predict.lmWinsor {fda}R Documentation

Predict method for Winsorized linear model fits

Description

Model predictions for object of class 'lmWinsor'.

Usage

## S3 method for class 'lmWinsor':
predict(object, newdata, se.fit = FALSE,
     scale = NULL, df = Inf, 
     interval = c("none", "confidence", "prediction"),
     level = 0.95, type = c("response", "terms"), 
     terms = NULL, na.action = na.pass,
     pred.var = res.var/weights, weights = 1, ...)

Arguments

object Object of class inheriting from 'lmWinsor'
newdata An optional data frame in which to look for variables with which to predict. If omitted, the fitted values are used.
se.fit a switch indicating if standard errors of predictions are required
scale Scale parameter for std.err. calculation
df degrees of freedom for scale
interval type of prediction (response or model term)
level Tolerance/confidence level
type Type of prediction (response or model term); see predict.lm
terms If 'type="terms"', which terms (default is all terms)
na.action function determining what should be done with missing values in 'newdata'. The default is to predict 'NA'.
pred.var the variance(s) for future observations to be assumed for prediction intervals. See predict.lm 'Details'.
weights variance weights for prediction. This can be a numeric vector or a one-sided model formula. In the latter case, it is interpreted as an expression evaluated in 'newdata'
... additional arguments for other methods

Details

1. Identify inputs and outputs via mdly <- mdlx <- formula(object); mdly[[3]] <- NULL; mdlx[[2]] <- NULL; xNames <- all.vars(mdlx); yNames <- all.vars(mdly). Give an error if as.character(mdly[[2]]) != yNames.

2. If 'newdata' are provided, clip all numeric xNames to (object[["lower"]], object[["upper"]]).

3. Call predict.lm

4. Clip the responses to the relevant components of (object[["lower"]], object[["upper"]]).

5. Done.

Value

If class(object) == c('lmWinsor', 'lm'), 'predict.lmWinsor' produces a vector of predictions or a matrix of predictions with limits or a list, as produced by predict.lm. Otherwise, 'object' is a list of such objects and will therefore return a list of such predictions.

Author(s)

Spencer Graves

See Also

lmWinsor predict.lm

Examples

# example from 'anscombe'
# trim = 0 
lm.1 <- lmWinsor(y1~x1, data=anscombe)

newD <- data.frame(x1=seq(1, 22, .1))
predW <- predict(lm.1, newdata=newD) 
plot(y1~x1, anscombe, xlim=c(1, 22),
     main="Anscombe, example 1") 
lines(newD[["x1"]], predW, col='blue')
abline(h=lm.1[['lower']]['y1'], col='red', lty='dashed') 
abline(h=lm.1[['upper']]['y1'], col='red', lty='dashed')
abline(v=lm.1[['lower']]['x1'], col='green', lty='dashed') 
abline(v=lm.1[['upper']]['x1'], col='green', lty='dashed')
# clipped at range(anscombe[, 'x1']) = c(4, 14)


# trim = 0.25 
lm.1.25 <- lmWinsor(y1~x1, data=anscombe, trim=0.25)

newD <- data.frame(x1=seq(1, 22, .1))
predW.25 <- predict(lm.1.25, newdata=newD) 
plot(y1~x1, anscombe, xlim=c(1, 22)) 
lines(newD[["x1"]], predW.25, col='blue', lwd=2)
abline(h=lm.1.25[['lower']]['y1'], col='red', lty='dotted') 
abline(h=lm.1.25[['upper']]['y1'], col='red', lty='dotted')
abline(v=lm.1.25[['lower']]['x1'], col='green', lty='dotted') 
abline(v=lm.1.25[['upper']]['x1'], col='green', lty='dotted')
# clipped at range(anscombe[, 'y1']) = c(4.26 10.84)


# list example
lm.1. <- lmWinsor(y1~x1, data=anscombe, trim=c(0, 0.25, .4, .5)) 
pred.1. <- predict(lm.1.)


[Package fda version 2.1.1 Index]