cahulme-lowe at mmm.com
2011-Jun-09 21:09 UTC
[R] nls Error Message - Singular Gradient Matrix
I've been trying to run some analysis using the nls function in R but keep coming up with an error message which I don't understand how to fix. The message follows here: Error in nls(formula = f.p, data = n.data, start = list(S = 1, a = -0.1, : singular gradient In addition: Warning messages: 1: In min(x) : no non-missing arguments to min; returning Inf 2: In max(x) : no non-missing arguments to max; returning -Inf>I did take a look at the archives before positing this and noticed that there was a similar message from a few years ago. The solution there seemed to be to change the algorithm to plinear. I've tried this to no avail. Unfortunately I'm not in a position where I can share the data I'm using, but will copy my code below. What I can say is that there are relatively few observations - only 12 - compared to the number of parameters. Could this be causing the error I'm seeing? Is there anything else that might be causing it? Any insight would be greatly appreciated! Chris. Code: data <- read.csv(choose.files(),header=TRUE) adoption <- data[,3] year <- data[,2] time <- data[,1] cum.adoption <- data[,4] plot(data[,2],data[,3],xlab="Year",ylab="Adoption",main="Greek Cell Phone Adoption 1994 - 2005 Q3",type="b") plot(data[,2],data[,4],xlab="year",ylab="Cumulative Adoption",main="Greek Cell Phone Adoption 1994 - 2005 Q3",type="b") start.val <- c(n=1.17,p=0.001,q=0.626) bass <- nls(formula=data[,3] ~ p*n+(q-p)*data[,5]-(q/n)*data[,5]^2, data=n.data, start=start.val) start.val <- c(S=1,a=1,b=1) f.p <- cum.adoption~S/(1+exp(-a+b*time)) fisher.pry <- nls(formula = f.p, data = n.data, start= list(S=1,a=-0.1,b=0.1), alg = "plinear", trace=TRUE) [[alternative HTML version deleted]]