Last chance! 50% off unlimited learning
Sale ends in
set.seed(3) #for compatability issues
require(graphics)
# retrieve mean estimates of 8 parameters using getInitial
# and posneg_data object
data(posneg_data)
modpar(posneg_data$age, posneg_data$mass,verbose=TRUE)
getInitial(mass ~ SSposnegRichards(age, Asym, K, Infl, M,
RAsym, Rk, Ri, RM, modno = 1), data = posneg_data)
# retrieve mean estimates and produce plot to illustrate fit for
# curve with RM fixed
pars <- coef(nls(mass ~ SSposnegRichards(age,
Asym = Asym, K = K, Infl = Infl, RAsym = RAsym, Rk = Rk, M = M,
Ri = Ri, modno = 2), data = posneg_data))
plot(posneg_data$age, posneg_data$mass, pch=".")
curve(posnegRichards_eqn(x, Asym = pars[1], K = pars[2],
Infl = pars[3], M = pars[4], RAsym = pars[5], Rk = pars[6],
Ri = pars[7], modno = 2), xlim = c(0,
200), add = TRUE)
# retrieve mean estimates and produce plot to illustrate fit for custom model 17
\dontrun{ pars<-as.numeric( getInitial(mass ~ SSposnegRichards(age, Asym, K, Infl,
M, RAsym, Rk, Ri, RM, modno = 17), 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), lty = 3, xlim = c(0, 200) , add = TRUE)}
# fit nls object using 8 parameter model
# note: ensure data object is a groupedData object
richardsR1.nls <- nls(mass ~ SSposnegRichards(age, Asym = Asym,
K = K, Infl = Infl, M = M, RAsym = RAsym, Rk = Rk, Ri = Ri,
RM = RM, modno = 1), data = posneg_data)
# fit nlsList object using 8 parameter model
# note: ensure data object is a groupedData object
# also note: not many datasets require all 8 parameters
\dontrun{
richardsR1.lis <- nlsList(mass ~ SSposnegRichards(age, Asym = Asym,
K = K, Infl = Infl, M = M, RAsym = RAsym, Rk = Rk, Ri = Ri,
RM = RM, modno = 1), data = posneg_data)}
# 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
subdata <- subset(posneg_data,posneg_data$id == as.character(36)
| posneg_data$id == as.character(9)
| posneg_data$id == as.character(32)
| posneg_data$id == as.character(43))
richardsR22.lis <- nlsList(mass ~ SSposnegRichards(age, Asym = Asym,
K = K, Infl = Infl, RAsym = RAsym, Rk = Rk, Ri = Ri,
modno = 22), data = subdata)
richardsR22.nlme <- nlme(richardsR22.lis, random = pdDiag(Asym + Infl ~ 1) )
# fit nls object using simple logistic model, with
# M, RAsym, Rk, Ri, and RM fixed to values in pnmodelparams
data(logist_data)
modpar(logist_data$age, logist_data$mass ,force4par = TRUE) # create pnmodelparams
change.pnparameters(M = 1) #set to logistic (M =1) prior to fit
richardsR20.nls <- nls(mass ~ SSposnegRichards(age, Asym = Asym,
K = K, Infl = Infl, modno = 20), data = logist_data)
# fit a two component model - enter your own data in place of "mydata"
\dontrun{
modpar<-(mydata$x,mydata$y,twocomponent_age=TRUE) # if age of intersection unknown
modpar<-(mydata$x,mydata$y,twocomponent_age=75) # if age of intersection = 75
richardsR1.nls <- nls(y~ SSposnegRichards(x, Asym = Asym, K = K,
Infl = Infl, M = M, RAsym = RAsym, Rk = Rk, Ri = Ri, RM = RM, modno = 1)
, data = mydata)}
Run the code above in your browser using DataLab