lognlm {logNormReg} | R Documentation |
Multiple linear regression with log Normal errors
Description
The function fits simple multiple linear regression models with log Normals erros. Two objectives as well as two optimizing functions can be used.
Usage
lognlm(formula, data, subset, weights, na.action, y = TRUE, start, model = TRUE,
lik = FALSE, opt = c("nlminb", "optim"), contrasts=NULL, ...)
Arguments
formula |
a standard R formula with response and explanatory variables (and possible offset) specifying the regression model being fitted. |
data |
an optional data frame, list or environment containing some or all the variables in the model. |
subset |
an optional vector specifying a subset of observations to be used in the fitting process. |
weights |
an optional vector of (positive) weights to be used in the fitting process. Currently implemented only if |
na.action |
a function indicating what should happen when the data contain NAs. The default is set by the |
y |
logical. If |
start |
(optional) starting values of the parameter to be estimated. If |
model |
logical. If |
lik |
If |
opt |
the optimization function to be used. |
contrasts |
an optional list. See the contrasts.arg of model.matrix.default. |
... |
optional arguments passed on to the optimizing functions ( |
Details
lognlm
fits simple linear regression models with log Normal errors and identity link. Actually two objectives could be used.
If lik=TRUE
the usual log Normal likelihood is optimized, otherwise estimation is based on minimization of the following loss function
\sum_i(\log y_i-\log \mu_i )^2
where \mu_i=x_i^T\beta
is the mean function equal to the linear predictor (as an identity link is exploited).
Value
A list with components
coefficients |
the regression parameters estimate. |
loglik |
The objective function value, namely the log Normal log likelihood or the sum of the squared ‘log residuals’ (depending on |
s2 |
the error variance estimate. |
fitted.values |
the fitted values. |
residuals |
the raw residuals on the original scale, i.e. 'observed - fitted'. |
grad |
the gradient at solution. |
hessian |
the hessian matrix at solution. |
Ehessian |
the expected hessian matrix at solution (only if |
convergence |
the convergence code coming from the fitter function. |
call |
the matched call. |
y |
the response vector (provided that |
opt |
the employed optimizer. |
lik |
logical, indicating if the fit comes from a log Normal likelihood approach. |
xlevels |
(only where relevant) a record of the levels of the factors used in fitting. |
terms |
the terms object used. |
contrasts |
(only where relevant) the contrasts used. |
model |
if requested, i.e. |
offset |
the (possible) offset used. |
Author(s)
Vito M.R. Muggeo
See Also
See also print.lognlm
and summary.lognlm
to display results.
Examples
n=300
s=.4
set.seed(123) #just to get reproducible results..
x<-seq(.1,10,l=n) #covariate
mu<- 10+2*x #linear regression function
y<-rlnorm(n, log(mu)-s^2/2, s) #data..
o0<-lm(log(y)~x) #the usual but WRONG model
o<- lognlm(y~x, lik=TRUE) #fit the 'right' model by ML
plot(x,y)
lines(x, mu, lwd=2)
points(x, exp(fitted(o0)), col=2, type="l", lwd=2)
points(x, fitted(o), col=3, type="l", lwd=2)
legend("topleft", legend=c("true", "lm(log(y)~x)", "lognlm(y~x)"),
col=c(1,2,3), lwd=2)
#Sometimes people would estimate parameters by minimizing a least square objective
# (i.e. by setting 'lik=FALSE', see Details), wherein data would come from
# Y = mu * exp(eps) where eps~N(0,s)..
y1<-mu*exp(rnorm(n,0,1)) #data..
o1<-lognlm(y1~x, lik=FALSE) #set 'lik=FALSE', see Details