#Code is provided here for an illustrative overview of using FlexParamCurve to select,
# fit, analyze and plot the most appropriate non-linear curves for a dataset.
# NOTE: autorun is disabled for these examples since more detailed examples are provided for the
# individual functions in their associated help files and runtime for this overview approximates
# 5 mins. To run, simply copy and paste code from this help file into the R GUI.
# run all-model selection for posneg.data object (Step 2) without need to run any previous functions
if (FALSE) {
modseltable <- pn.mod.compare(posneg.data$age, posneg.data$mass,
posneg.data$id, existing = FALSE, pn.options = "myoptions")}
# run backwards stepwise model selection (Step 2) for logist.data object
#without need to run any previous functions
if (FALSE) {
modseltable <- pn.modselect.step(logist.data$age, logist.data$mass,
logist.data$id, existing = FALSE, pn.options = "myoptions")}
# estimate fixed parameters use data object posneg.data (Step 1)
if (FALSE) {
modpar(posneg.data$age,posneg.data$mass, pn.options = "myoptions")}
# change fixed values of M and constrain hatching mass to 45.5 in a growth curve (Step 1)
if (FALSE) {
change.pnparameters(M=1,RM=0.5,first.y=45.5, pn.options = "myoptions")}
# fit nlsList object using 6 parameter model with values M and RM (Step 3)
# fixed to value in pnmodelparams and then fit nlme model
if (FALSE) {
richardsR22.lis <- nlsList(mass ~ SSposnegRichards(age, Asym = Asym, K = K,
Infl = Infl, RAsym = RAsym, Rk = Rk, Ri = Ri,
modno = 22, pn.options = "myoptions"), data = posneg.data)
richardsR22.nlme <- nlme(richardsR22.lis, random = pdDiag(Asym + Infl ~ 1))}
# fit reduced nlsList model and then compare performance with extraF (manual version of Step 2)
if (FALSE) {
richardsR20.lis <- nlsList(mass ~ SSposnegRichards(age, Asym = Asym, K = K,
Infl = Infl, modno = 20, pn.options = "myoptions"), data = posneg.data)
extraF(richardsR20.lis,richardsR22.lis)}
# fit and plot a logistic curve (M=1) to data, note - all parameters set to 1 are ignored
# note code here forces \eqn{modpar} to only estimate 4 curve parameters (simple Richards curve)
#create list for fixed parameters
if (FALSE) {
modpar(logist.data$age,logist.data$mass,force4par=TRUE, pn.options = "myoptions")
change.pnparameters(M=1, pn.options = "myoptions") # set M to 1 for subsequent fit
richardsR20.nls <- nls(mass ~ SSposnegRichards(age, Asym = Asym, K = K,
Infl = Infl, modno = 20, pn.options = "myoptions"), data = logist.data)
plot(logist.data$age , logist.data$mass, xlab = "age", ylab = "mass", pch = ".", cex = 0.7)
par <- coef( richardsR20.nls )}
#(Step 4)
if (FALSE) {
curve(posnegRichards.eqn(x, Asym = par[1], K = par[2], Infl = par[3], modno = 20
, pn.options = "myoptions"), add= TRUE)}
Run the code above in your browser using DataLab