Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

wfct

Weighting function that can be supplied to the weights argument of nlsLM or nls


Description

wfct can be supplied to the weights argument of nlsLM or nls, and facilitates specification of weighting schemes.

Usage

wfct(expr)

Arguments

expr

An expression specifying the weighting scheme as described in the Details section below.

Details

The weighting function can take 5 different variable definitions and combinations thereof:

  • the name of the predictor (independent) variable

  • the name of the response (dependent) variable

  • error: if replicates y_{ij} exist, the error sigma_{ij}

  • fitted: the fitted values hat{y}_i of the model

  • resid: the residuals y_i - hat{y}_i of the model

For the last two, the model is fit unweighted, fitted values and residuals are extracted and the model is refit by the defined weights.

Value

The results of evaluation of expr in a new environment, yielding the vector of weights to be applied.

Author(s)

Andrej-Nikolai Spiess

See Also

Examples

### Examples from 'nls' doc ###
## note that 'nlsLM' below may be replaced with calls to 'nls'
Treated <- Puromycin[Puromycin$state == "treated", ]

## Weighting by inverse of response 1/y_i:
nlsLM(rate ~ Vm * conc/(K + conc), data = Treated,
start = c(Vm = 200, K = 0.05), weights = wfct(1/rate))

## Weighting by square root of predictor \sqrt{x_i}:
nlsLM(rate ~ Vm * conc/(K + conc), data = Treated,
start = c(Vm = 200, K = 0.05), weights = wfct(sqrt(conc)))

## Weighting by inverse square of fitted values 1/\hat{y_i}^2:
nlsLM(rate ~ Vm * conc/(K + conc), data = Treated,
start = c(Vm = 200, K = 0.05), weights = wfct(1/fitted^2))

## Weighting by inverse variance 1/\sigma{y_i}^2:
nlsLM(rate ~ Vm * conc/(K + conc), data = Treated,
start = c(Vm = 200, K = 0.05), weights = wfct(1/error^2))

minpack.lm

R Interface to the Levenberg-Marquardt Nonlinear Least-Squares Algorithm Found in MINPACK, Plus Support for Bounds

v1.2-1
GPL-3
Authors
Timur V. Elzhov, Katharine M. Mullen, Andrej-Nikolai Spiess, Ben Bolker
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.