From wdunlap at tibco.com  Wed Aug  4 20:36:26 2010
From: wdunlap at tibco.com (William Dunlap)
Date: Wed, 4 Aug 2010 11:36:26 -0700
Subject: [Rd] problem in predict.lm(type="terms", terms=someNames,
	interval="confidence", ...)
Message-ID: <77EB52C6DD32BA4D87471DCD70C8D700034847A1@NA-PA-VBE03.na.tibco.com>

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 



[Rd] problem in predict.lm(type="terms", terms=someNames, interval="confidence", ...)
William Dunlap