truncSP (version 1.2.2)

lt.fit: Function for fitting LT

Description

Function to find LT estimates of the regression coefficients for regression models with truncated response variables. Uses optim. Intended to be called through lt, not on its own, since lt also transforms data into the correct form etc.

Usage

lt.fit(formula, mf, point, direction, bet, cl, cu, ...)

Arguments

formula
a symbolic description of the model to be estimated
mf
the model.frame containing the variables to be used when fitting the model. lt transforms the model frame to the correct form before calling lt.fit. If lt.fit is called on its own the model frame needs to be transformed manually.
point
point of truncation
direction
direction of truncation
bet
starting values to be used by optim. Column matrix with p rows.
cl
lower threshold value to be used, number or numeric vector of length 1. (See lt, argument clower, for more information).
cu
upper threshold value to be used, number or numeric vector of length 1. (See lt, argument cupper, for more information).
...
additional arguments to be passed to optim (see the documentation for lt for further details).

Value

a list with components:
startcoef
the starting values of the regression coefficients used by optim
coefficients
the named vector of coefficients
counts
number of iterations used by optim. See the documentation for optim for further details
convergence
from optim. An integer code. 0 indicates successful completion. Possible error codes are 1 indicating that the iteration limit maxit had been reached. 10 indicating degeneracy of the Nelder--Mead simplex.
message
from optim. A character string giving any additional information returned by the optimizer, or NULL.
residuals
the residuals of the model
df.residual
the residual degrees of freedom
fitted.values
the fitted values

See Also

lt

Examples

Run this code
require(utils)
##Model frame
n <- 10000
x <- rnorm(n,0,2)
y <- 2+x+4*rnorm(n)
d <- data.frame(y=y, x=x)
dl0 <- subset(d, y>0)
mf <- model.frame(y~x, data=dl0)

##Starting values and threshold values
lmmod <- lm(data=mf)
bet <- lmmod$coef
bet <- matrix(bet)
cl <- sqrt(deviance(lmmod)/df.residual(lmmod))
cu <- 2*cl

str(lt. <- lt.fit(y~x,mf,point=0,direction="left",bet,cl,cu))

Run the code above in your browser using DataLab