nls and na/Nan/Inf error
Use a grid search to get the starting values in which case you will likely be close enough that you won't run into problems even without derivatives: attach(fldgd) grid <- expand.grid(Vr = seq(0,.3,.1), Vm = seq(.45, 1, .05), alpha = seq(1,2,.25), lamda = seq(1,2,.25)) ss <- function(p) sum((Moisture - vanGen(Suction, p[1], p[2], p[3], p[4]))^2) idx <- which.min(apply(grid, 1, ss)) startval <- grid[idx,] nls(Moisture ~ vanGen(Suction, Vr, Vm, alpha, lamda), start = startval)
On 9/26/05, Tony Meissner <tony.meissner at bigpond.com> wrote:
I am trying to it a particular nonlinear model common in Soil Science to
moisture release data from soil. I have written the function as shown
below according to the logist example in Ch8 of Pinheiro & Bates. I am
getting the following error (R version 2.1.1)
*Error in qr(attr(rhs, "gradient")) : NA/NaN/Inf in foreign function
call (arg 1)*
Below is the function and data.
/# the van genuchten moisture release function
vanGen <- function(x, Vr, Vm, alpha, lamda) {
if (Vr < 0) Vr <- 0
Vr + (Vm - Vr)/((1+(alpha*x)^lamda)^(1-1/lamda))
}
vanGen <- deriv(~Vr + (Vm - Vr)/((1+(alpha*x)^lamda)^(1-1/lamda)),
c("Vr", "Vm", "alpha", "lamda"), function(x, Vr, Vm, alpha, lamda) {} )/
the call in R
/> fm1fld.nls <- nls(Moisture ~ vanGen(Suction, Vr,Vm,alpha,lamda),
+ data=fldgd, start=c(Vr=0.229, Vm=0.433, alpha=0.2, lamda=1.5))
/and the data:/
/* Suction Moisture
1 0 0.433
2 1 0.421
3 4 0.400
4 10 0.379
5 20 0.366
6 30 0.362
7 40 0.358
8 50 0.353
9 60 0.351
10 70 0.349
*/
/can anyone offer any suggestions. The parameters Vr, Vm >= 0, alpha >
0, and
lamda > 1
______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html