nlsur | R Documentation |
nlsur()
is used to fit nonlinear regression models. It can handle the
feasible and iterative feasible variants.
nlsur(
eqns,
data,
startvalues,
type = NULL,
S = NULL,
trace = FALSE,
robust = FALSE,
stata = TRUE,
qrsolve = FALSE,
weights,
MASS = FALSE,
maxiter = 1000,
val = 0,
tol = 1e-07,
eps = 1e-05,
ifgnlseps = 1e-10,
tau = 0.001,
initial = FALSE
)
eqns |
is a list object containing the model as formula. This list can handle contain only a single equations (although in this case nls() might be a better choice) or a system of equations. |
data |
an (optional) data frame containing the variables that will be evaluated in the formula. |
startvalues |
initial values for the parameters to be estimated. |
type |
can be 1 Nonlinear Least Squares (NLS), 2 Feasible Generalized NLS (FGNLS) or 3 Iterative FGNLS (IFGNLS) or the respective abbreviations in character form. |
S |
is a weight matrix used for evaluation. If no weight matrix is provided the identity matrix I will be used. |
trace |
logical whether or not SSR information should be printed. Default is FALSE. |
robust |
logical if true robust standard errors are estimated. |
stata |
is a logical. If TRUE for nls a second evaluation will be run. Stata does this by default. For this second run Stata replaces the diagonal of the I matrix with the coefficients. |
qrsolve |
logical |
weights |
Additional weight vector. |
MASS |
is a logical whether an R function similar to the MASS::lm.gls() function should be used for weighted Regression. This can cause sever RAM usage as the weight matrix tend to be huge (n-equations * n-rows). |
maxiter |
Maximum number of iterations. |
val |
If no start values supplied, create them with this start value. Default is 0. |
tol |
qr.solves tolerance for detecting linear dependencies. |
eps |
the epsilon used for convergence in nlsur(). Default is 1e-5. |
ifgnlseps |
is epsilon for ifgnls(). Default is 1e-10. |
tau |
is another convergence variable. Default is 1e-3. |
initial |
logical value to define if rankMatrix is calculated every iteration of nlsur. |
nlsur() is a wrapper around .nlsur(). The function was initially inspired by the Stata Corp Function nlsur. Nlsur estimates a nonlinear least squares demand system. With nls, fgnls or ifgnls which is equivalent to Maximum Likelihood estimation. Nonlinear least squares requires start values and nlsur requires a weighting matrix for the demand system. If no weight matrix is provided, nlsur will use the identity matrix I. If type = 1 or type = "nls" is added, nlsur will use the matrix for an initial estimation, once the estimation is done, it will swap the diagonal with the estimated results.
Most robust regression estimates shall be returned with both qrsolve and MASS TRUE, but memory consumption is largest this way. If MASS is FALSE a memory efficient RcppArmadillo solution is used for fgnls and ifgnls. If qrsolve is FALSE as well, only the Armadillo function is used.
If robust
is selected Whites HC0 is used to calculate
Heteroscedasticity Robust Standard Errors.
If initial
is TRUE rankMatrix will be calculated every iteration of
nlsur. Meaning for nls at least once, for fgnls at least twice and for ifgnls
at least three times. This adds a lot of overhead, since rankMatrix is used
to calculate k. To assure that k does not change this can be set to TRUE.
Nlsur has methods for the generic functions coef, confint, deviance, df.residual, fitted, predict, print, residuals, summary and vcov.
The function returns a list object of class nlsur. The list includes:
estimated coefficients
residuals
residuals of each equation in a single list
list of equation names
the weight matrix
Residual sum of squares
Left hand side of the evaluated model
Right hand side of the evaluated model
model type. "NLS", "FGNLS" or "IFGNLS"
standard errors
t values
asymptotic covariance matrix
equation wise estimation results of SSR, MSE, RMSE, MAE, R2 and Adj-R2. As well as n, k and df.
equation or system of equations as list containing formulas
Gallant, A. Ronald (1987): Nonlinear Statistical Models. Wiley: New York
nls
## Not run:
# Greene Example 10.3
library(nlsur)
url <- "http://www.stern.nyu.edu/~wgreene/Text/Edition7/TableF10-2.txt"
dd <- read.table(url, header = T)
names(dd) <-
c("Year", "Cost", "Sk", "Sl", "Se", "Sm", "Pk", "Pl", "Pe", "Pm")
eqns <-
list( Sk ~ bk + dkk * log(Pk/Pm) + dkl * log(Pl/Pm) + dke * log(Pe/Pm),
Sl ~ bl + dkl * log(Pk/Pm) + dll * log(Pl/Pm) + dle * log(Pe/Pm),
Se ~ be + dke * log(Pk/Pm) + dle * log(Pl/Pm) + dee * log(Pe/Pm))
strtvls <- c(be = 0, bk = 0, bl = 0,
dkk = 0, dkl = 0, dke = 0,
dll = 0, dle = 0, dee = 0)
erg <- nlsur(eqns = eqns, data = dd, startvalues = strtvls, type = 2,
trace = TRUE, eps = 1e-10)
erg
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.