[Rd] problem in predict.lm(type="terms", terms=someNames, interval="confidence", ...)
William Dunlap
wdunlap at tibco.com
Wed Aug 4 20:36:26 CEST 2010
R's predict.lm() fails when trying to compute
term-wise confidence (or prediction) intervals
for a subset of the terms in a model:
> dat <- data.frame(y=log(1:10), x=1:10,
fac=rep(LETTERS[11:13],c(3,3,4)))
> fit <- lm(y~fac*x, data=dat)
> # can compute intervals for all terms
> pfit <- predict(fit, type="terms", interval="confidence",
newdata=dat[7:5,])
> # error computing intervals for a subset of the terms
> pfit2 <- predict(fit, type="terms", terms=c("x","fac"),
interval="confidence", newdata=dat[7:5,])Error in predictor + hwid :
non-conformable arrays
> # pfit2 should be the same as pfit2Expected
> pfit2Expected <- lapply(pfit2,
function(x)if(is.matrix(x)) structure(x[, c("x","fac")],
constant=attr(x, "constant")) else x)
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
More information about the R-devel
mailing list