set.seed(3) #for compatability issues
require(graphics)
# retrieve mean estimates of 8 parameters using getInitial
# and posneg.data object
modpar(posneg.data$age, posneg.data$mass,verbose=TRUE, pn.options = "myoptions", width.bounds=2)
getInitial(mass ~ SSposnegRichards(age, Asym, K, Infl, M,
RAsym, Rk, Ri, RM, modno = 1, pn.options = "myoptions"), data = posneg.data)
# retrieve mean estimates and produce plot to illustrate fit for
# curve with M, Ri and Rk fixed
pars <- coef(nls(mass ~ SSposnegRichards(age,
Asym = Asym, K = K, Infl = Infl, RAsym = RAsym,
RM = RM, modno = 24, pn.options = "myoptions"), data = posneg.data,
control=list(tolerance = 10)))
plot(posneg.data$age, posneg.data$mass, pch=".")
curve(posnegRichards.eqn(x, Asym = pars[1], K = pars[2],
Infl = pars[3], RAsym = pars[4],
RM = pars[5], modno = 24, pn.options = "myoptions"), xlim = c(0,
200), add = TRUE)
# following example not run as appropriate data are not available in the package
# retrieve mean estimates and produce plot to illustrate fit for custom model 17
if (FALSE) {
pars<-as.numeric( getInitial(mass ~ SSposnegRichards(age, Asym, K, Infl,
M, RAsym, Rk, Ri, RM, modno = 17, pn.options = "myoptions"), data = datansd) )
plot(datansd$jday21March, datansd$moosensd)
curve( posnegRichards.eqn(x, Asym = pars[1], K = 1, Infl = pars[2],
M = pars[3], RAsym = pars[4], Rk = 1, Ri = pars[5], RM = pars[6],
modno = 17, pn.options = "myoptions"), lty = 3, xlim = c(0, 200) , add = TRUE)}
# fit nls object using 8 parameter model
# note: ensure data object is a groupedData object
# \donttest{
richardsR1.nls <- nls(mass ~ SSposnegRichards(age, Asym = Asym,
K = K, Infl = Infl, M = M, RAsym = RAsym, Rk = Rk, Ri = Ri,
RM = RM, modno = 1, pn.options = "myoptions"), data = posneg.data)# }
# following example not run as it fits very few levels in these data - as noted
# such a comprehensive equation is rarely required
# fit nlsList object using 8 parameter model
# note: ensure data object is a groupedData object
# also note: not many datasets require all 8 parameters
if (FALSE) {
richardsR1.lis <- nlsList(mass ~ SSposnegRichards(age, Asym = Asym,
K = K, Infl = Infl, M = M, RAsym = RAsym, Rk = Rk, Ri = Ri,
RM = RM, modno = 1, pn.options = "myoptions"), data = posneg.data)
summary(richardsR1.lis)}
# fit nlsList object using 6 parameter model with value M and RM
# fixed to value in pnmodelparams and then fit nlme model
# note data is subset to provide estimates for a few individuals
# as an example
# \donttest{
subdata <- subset(posneg.data,posneg.data$id == as.character(26)
| posneg.data$id == as.character(1)
| posneg.data$id == as.character(32))
richardsR22.lis <- nlsList(mass ~ SSposnegRichards(age, Asym = Asym,
K = K, Infl = Infl, RAsym = RAsym, Rk = Rk, Ri = Ri,
modno = 22, pn.options = "myoptions"), data = subdata)
summary(richardsR22.lis )
richardsR22.nlme <- nlme(richardsR22.lis, random = pdDiag(Asym + Infl ~ 1) )
summary(richardsR22.nlme)# }
# fit nls object using simple logistic model, with
# M, RAsym, Rk, Ri, and RM fixed to values in pnmodelparams
# \donttest{
modpar(logist.data$age, logist.data$mass ,force4par = TRUE, pn.options = "myoptions")
change.pnparameters(M = 1, pn.options = "myoptions") #set to logistic (M =1) prior to fit
richardsR32.nls <- nls(mass ~ SSposnegRichards(age, Asym = Asym,
K = K, Infl = Infl, modno = 32, pn.options = "myoptions"), data = logist.data)
coef(richardsR32.nls)# }
# fit a two component model - enter your own data in place of "mydata"
# this is not run for want of an appropriate dataset
# if x of intersection unknown
if (FALSE) {
modpar(mydata$x,mydata$y,twocomponent.x=TRUE, pn.options = "myoptions")
# if x of intersection = 75
modpar(mydata$x,mydata$y,twocomponent.x=75, pn.options = "myoptions")
richardsR1.nls <- nls(y~ SSposnegRichards(x, Asym = Asym, K = K,
Infl = Infl, M = M, RAsym = RAsym, Rk = Rk, Ri = Ri, RM = RM,
modno = 1, pn.options = "myoptions")
, data = mydata)
coef(richardsR1.nls)}
Run the code above in your browser using DataLab