nlsLoop2: Loops through a non-linear model on many different curves to...

Description Usage Arguments Value Note Author(s) See Also Examples

Description

Finds the best estimated model to each of a set of curves using non-linear least squares regression using nlsLM(). Start parameters are found using nls2

Usage

1
2
3
nlsLoop2(model, data, id_col, tries, param_bds, r2 = c("Y", "N"),
  supp_errors = c("Y", "N"), AICc = c("Y", "N"), return_preds, control, alg,
  ...)

Arguments

model

a non-linear model formula, with the response on the left of a ~ operator and an expression involving parameters on the right.

data

a data frame containing an column to differentiate between curves and the response and predictor variables.

id_col

the column name that identifies each curve that is to be fitted in "".

tries

number of combinations of starting parameters that are tried on each curve.

param_bds

lower and upper boundaries for the start parameters. If missing these default to +/- 1e+09. Need to specified as a vector as : c(lower bound param 1, upper bound param 1, lower bound param 2, upper bound param 2 etc)

r2

whether or not the quasi rsquared value is calculated and returned. This defaults to no, to include the r2 values use r2 = 'Y'.

supp_errors

if supp_errors = 'Y', then no error messages will be shown from the nlsLM function, reducing the number of error messages printed while the model attempts to converge using poor starting parameters. Advised to only use supp_errors = 'Y' when you are confident in the bounds of your starting parameters.

AICc

whether or not the small sample AIC should be used. Defaults to 'Y'. Override this using AICc == 'N'. AICc should be used instead of AIC when sample size is small in comparison to the number of estimated parameters (Burnham & Anderson 2002 recommend its use when n / n_param < 40).

return_preds

whether predictions of each individual model fit are wanted alongside the parameters or. Defaults to yes ('Y'). Add 'N' to change to no.

control

specific control can be specified using nls.lm.control.

alg

the algorithm with which to scan for start parameters. See nls2 for details. Defaults to plinear-random.

...

Extra arguments to pass to nlsLM if necessary.

Value

returns a list of class nlsLoop. Notable elements within the list are $params and $predictions that give the best fit parameters and predictions based on these parameters for each individual fit.

Note

Useful additional arguments for nlsLM include: na.action = na.omit, lower/upper = c() where these represent upper and lower boundaries for parameter estimates

Author(s)

Daniel Padfield

See Also

quasi_rsq_nls for details on the calculation of r squared values for non linear models.

nlsLM for details on additional arguments to pass to the nlsLM function.

AICc for application of AICc.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# load in data

data("Chlorella_TRC")
Chlorella_TRC_test <- Chlorella_TRC[Chlorella_TRC$curve_id %in% c(1:10),]

# run nlsLoop()

# define the Sharpe-Schoolfield equation
schoolfield_high <- function(lnc, E, Eh, Th, temp, Tc) {
 Tc <- 273.15 + Tc
 k <- 8.62e-5
 boltzmann.term <- lnc + log(exp(E/k*(1/Tc - 1/temp)))
 inactivation.term <- log(1/(1 + exp(Eh/k*(1/Th - 1/temp))))
 return(boltzmann.term + inactivation.term)
}

fits <- nlsLoop2(ln.rate ~ schoolfield_high(lnc, E, Eh, Th, temp = K, Tc = 20),
                data = Chlorella_TRC_test,
                tries = 500,
                id_col = 'curve_id',
                param_bds = c(-10, 10, 0.1, 2, 0.5, 5, 285, 330),
                lower = c(lnc=-10, E=0, Eh=0, Th=0))

padpadpadpad/nlsLoop documentation built on May 24, 2019, 5:59 p.m.