50% off | Unlimited Data & AI Learning

Last chance! 50% off unlimited learning

Sale ends in


FlexParamCurve (version 1.4-3)

pn.mod.compare: Compare All Possible Positive-Negative Richards $nlslist$ Models

Description

This function performs model selection for nlsList models fitted using SSposnegRichards.

Usage

pn.mod.compare(x,

y,

grp,

pn.options,

forcemod = 0,

existing = FALSE,

penaliz = "1/sqrt(n)",

taper.ends = 0.45,

mod.subset = c(NA),

...)

Arguments

x
a numeric vector of the primary predictor
y
a numeric vector of the response variable
grp
a factor of same length as x and y that distinguishes groups within the dataset
pn.options
required character string specifying name of list object populated with starting parameter estimates, fitting options and bounds
forcemod
optional numeric value to constrain model selection (see Details)
existing
optional logical value specifying whether some of the relevant models have already been fitted
penaliz
optional character value to determine how models are ranked (see Details)
taper.ends
numeric representing the proportion of the range of the x variable for which data are extended at the two ends of the data set. This is used in initial estimation (prior to optim and nls optimizations) and can speed up subsequent optimizations by im
mod.subset
optional vector containing modno of models that the user desires to be estimated. If not NA, only nlsList models in mod.subset will be fitted and ranked
...
additional optional arguments to be passed to nlsList

Value

  • A list object with two components: $'Model rank table' contains the statistics from extraF ranked by the modified residual standard error, and $'P values from pairwise extraF comparison' is a matrix of P values from extraF for legitimate comparisons (nested and successfully fitted models). The naming convention for models is a concatenation of 'richardsR', the modno and '.lis' which is shortened in the matrix output, where the number of parameters has been pasted in parentheses to allow users to easily distinguish the more general model from the more reduced model (see extraF and SSposnegRichards). For extra flexibility, mod.subset can specify a vector of modno values (a number of different models) that can be fitted in nlsList and then evaluated by model selection. This prevents fitting of unwanted models or attempts to fit models that are known to fail. If the nlsList model already exists it will not be refitted and thus existing models can be included in the ranking table without adding noticeably to processing time.

Details

First, whether parameter M should be fixed (see SSposnegRichards) is determined by fitting models 12 and 20 and comparing their perfomance using extraF. Note that model 20 is identical to model 32. If model 12 provides superior performance (variable values of M) then 16 models that estimate M are run (models 1 through 16), otherwise the models with fixed M are fitted (models 21 through 36). Fitting these nlsList models can be time-consuming (2-4 hours using the dataset posneg.data that encompasses 100 individuals) and if several of the relevant models are already fitted the option existing=TRUE can be used to avoid refitting models that already exist globally (note that a model object in which no grouping levels were successfully parameterized will be refitted, as will objects that are not of class nlsList). Specifying forcemod=3 will force model selection to only consider fixed M models and setting forcemod=4 will force model selection to consider models with varying values of M only. If fitting both models 12 and 20 fails, fixed M models will be used by default. taper.ends can be used to speed up optimization as it extends the dataset at maximum and minimum extremes of x by repeatedly pasting the y values at these extremes for a specified proportion of the range of x. taper.ends is a numeric value representing the proportion of the range of x values are extended for and defaults to 0.45 (45tend towards a zero slope this is a suitable values. If tapered ends are not desirable then choose taper.ends = 0. Models are ranked by modified pooled residual square error. By default residual standard error is divided by the square root of sample size. This exponentially penalizes models for which very few grouping levels (individuals) are successfully parameterized (the few individuals that are parameterized in these models are fit unsuprisingly well) using a function based on the relationship between standard error and sample size. However, different users may have different preferences and these can be specified in the argument penaliz (which residual standard error is multiplied by). This argument must be a character value that contains the character n (sample size) and must be a valid right hand side (RHS) of a formula: e.g. 1*(n), (n)^2. It cannot contain more than one n but could be a custom function, e.g. FUN(n).

See Also

extraF SSposnegRichards nlsList

Examples

Run this code
#these examples will take a long while to run as they have to complete the 32 model comparison

#run model selection for posneg.data object (only first 3 group levels for example's sake)

data(posneg.data)

   subdata <- subset(posneg.data, as.numeric(row.names (posneg.data) ) < 40)

   modseltable <- pn.mod.compare(subdata$age, subdata$mass,

      subdata$id, existing = FALSE, pn.options = "myoptions")

    

#fit nlsList model initially and then run model selection

#for posneg.data object when at least one model is already fit

# note forcemod is set to 3 so that models 21-36 are evaluated

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

      Infl = Infl, RAsym = RAsym, Rk = Rk, Ri = Ri , modno = 22)

                        ,data = posneg.data, pn.options = "myoptions")

   modseltable <- pn.mod.compare(subdata$age, subdata$mass,

      subdata$id, forcemod = 3, existing = TRUE, pn.options = "myoptions")

 

#run model selection ranked by residual standard error*sample size

modseltable <- pn.mod.compare(subdata$age, subdata$mass,

      subdata$id, penaliz='1*(n)', existing = TRUE, pn.options = "myoptions")

Run the code above in your browser using DataLab