Learn R Programming

FlexParamCurve (version 1.3)

FlexParamCurve-package: Tools to Fit Flexible Parametric Curves

Description

selfStart functions and model selection tools to fit parametric curves in nls, nlsList and nlme frameworks.

Arguments

Details

General approach for using package (also see examples below) 1) Run $modpar$ to produce initial parameter estimates for your dataset. These are saved in object $pnmodelparams$ and parameterbounds for subsequent fits are in $pnmodelparamsbounds$. All can be edited manually or using $change.pnparameters$. 2) Determine most appropriate model (number of necessary parameters) for your data using $pn_mod_compare$ or $pn_modselect_step$ (these compare nested models using $extraF$). This may take some time as many $nlsList$ objects are fitted. Note that if you perform this step, then you do not need to perform step 1. If you are sure of your model (e.g. it is a simple logistic) Step 2 may be unnecessary. 3) Fit $nls$ or $nlsList$ or $nlme$ models using $SSposnegRichards$ specifying the appropriate model number. Parameter bounds can be refined to improve fits by altering $pnmodelparamsbounds$. 4) Plot your curves using eqn{posnegRichards_eqn} specifying the appropriate model number. User level functions include: $pn_mod_compare$ all-model selection for positive-negative Richards nlsList models $pn_modselect_step$ backward stepwise model selection for positive-negative Richards nlsList models $SSposnegRichards$ selfStart function for estimating parameters of 36 possible reductions of the 8-parameter positive-negative Richards model $posnegRichards_eqn$ function for evaluating 36 possible reductions of the 8-parameter positive-negative Richards model $modpar$ estimates mean parameters (and parameter bounds) for 8-parameter positive-negative Richards models or 4-parameter Richards models and saves in objects pnmodelparams and pnmodelparamsbounds. (required prior to use of the above functions) $change.pnparameters$ simple function to update pnmodelparams and pnmodelparamsbounds with user specified values $extraF$ performs extra sum-of-squares F test for two nested nlsList models $extaF.nls$ performs extra sum-of-squares F test for two nested nls models ll{Package: FlexParamCurve Type: Package Title: Tools to Fit Flexible Parametric Curves Version: 1.0 Date: 2011-09-15 Author: Stephen Oswald Maintainer: Stephen Oswald License: GPL-2 Depends: nlme Enhances: nlme LazyLoad: yes }

See Also

nlme SSlogis richards

Examples

Run this code
# run all-model selection for posneg_data object (Step 2) without need to run any previous functions

data(posneg_data)

modseltable <- pn_mod_compare(posneg_data$age, posneg_data$mass,

    posneg_data$id, existing = FALSE)



# run backwards stepwise model selection (Step 2) for logist_data object without need to run any previous functions

data(logist_data)

modseltable <- pn_modselect_step(logist_data$age, logist_data$mass,

    logist_data$id, existing = FALSE)



# estimate fixed parameters use data object posneg_data (Step 1)

modpar(posneg_data$age,posneg_data$mass)



# change fixed values of M and constrain hatching mass to 45.5 in a growth curve (Step 1)

change.pnparameters(M=1,RM=0.5,first_y=45.5)

    

# fit nlsList object using 6 parameter model with values M and RM (Step 3)

# fixed to value in pnmodelparams and then fit nlme model

richardsR22.lis <- nlsList(mass ~ SSposnegRichards(age, Asym = Asym, K = K,

      Infl = Infl, RAsym = RAsym, Rk = Rk, Ri = Ri,

      modno = 22), 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)

richardsR20.lis <- nlsList(mass ~ SSposnegRichards(age, Asym = Asym, K = K,

      Infl = Infl, modno = 20), data = posneg_data)

 extraF(richardsR20.lis,richardsR22.lis)

 

 # fit and plot a logistic curve (M=1) to data, note that all parameters set to equal 1 here are ignored

 # note code here forces \eqn{modpar} to only estimate 4 curve parameters (simple Richards curve)

data(logist_data)

modpar(logist_data$age,logist_data$mass,force4par=TRUE)

change.pnparameters(M=1) # set M to 1 for subsequent fit

richardsR20.nls <- nls(mass ~ SSposnegRichards(age, Asym = Asym, K = K,

      Infl = Infl, modno = 20), data = logist_data)

plot(logist_data$age , logist_data$mass, xlab = "age", ylab = "mass", pch = ".", cex = 0.7) 

par <- coef( richardsR20.nls )

#(Step 4)

curve(posnegRichards_eqn(x, Asym = par[1], K = par[2], Infl = par[3], modno = 20), add= TRUE)

Run the code above in your browser using DataLab