I have this model nls()that works pretty smoothly and I want to be able to cross-check with the package cvTools, but I get this error when the function starts cvFit():
Error: an object of type 'symbol' is not a subset
RStudio automatically opens the debugger, and I get this in the source code viewer:
function (x, env = parent.frame(), ...)
{
notAtomic <- !is.atomic(x)
notnull <- function(z) notAtomic && !is.null(z)
if (notnull(x$formula))
eval(x$formula)
else if (notnull(x$terms)) {
z <- x$terms
oldClass(z) <- "formula"
z
}
else if (notnull(x$call$formula))
eval(x$call$formula)
else if (!is.null(attr(x, "formula")))
attr(x, "formula")
else {
form <- switch(mode(x), `NULL` = structure(NULL, class = "formula"),
character = formula(eval(parse(text = x)[[1L]])),
call = eval(x), stop("invalid formula"))
environment(form) <- env
form
}
}
I have included an excerpt of my frame in the following link in .csv format: https://www.sendspace.com/file/ec1aoa
And here is the code I used:
fctmod<-function(x,y,z){
resultat<-(1+x*((z-mean(z))/mean(z))+y*((z-mean(z))/mean(z))^2)
return(resultat)
}
fctmodlin<-function(x,z){
resultat<-(1+x*((z-mean(z))/mean(z)))
return(resultat)
}
nlscut<- nls(BAI ~ (a*(B_A)^(b))*
fctmodlin(c,PPT.an)*
fctmod(e,f,maxTmax.an)*
fctmod(g,h,GPautre),
start = list(a = 1.14338, b = 0.504549,c=0, e=0, f=0, g=0, h=0),
data = datacut,
weights= wfct(DHPc))
library(cvTools)
testcut<-cvFit(nlscut, data=datacut,y=datacut$BAI,cost=mspe,K=10,R=1,seed=1234)