[R] Novice question

Mike Mascari mascarm at mascari.com
Mon Aug 4 18:44:17 CEST 2003


Hello.

I am new R user, so this question is probably quite stupid, but for
the life of me I cannot figure out how to get predications using
multivariate linear regression analysis. Single variable predictions
work fine. I am trying the following:

-- Known y's for known x's1 and x's2

ys <- c(133890, 135000, 135790, 137300, 138130, 139100, 139900,
141120, 141890, 143230, 144000, 145290)

xs1 <- c(1:12)
xs2 <- c(22, 24.5, 27, 33, 36.8, 40, 44, 57, 59, 62, 74, 77)
xm <- cbind(xs1, xs2)

-- New x's1 and x's2

nx1 <- c(13:17)
nx2 <- c(82, 85, 88.3, 90, 95)

-- Generate some predictions

samples <- data.frame(xs1=nx1, xs2=nx2)
f <- predict(lm(ys ~ xm), samples)

data.frame(f) yields:

         f
1  133949.8
2  134970.2
3  135990.6
4  137008.1
5  138027.5
6  139047.3
7  140066.5
8  141078.3
9  142099.1
10 143119.1
11 144131.7
12 145151.7

Not the predicted y's for the new x1's and x2's. I tried:

f <- predict.mlm(lm(ys ~ xm), samples) and got:

Error in object$coefficients[piv, ] : incorrect number of dimensions

I would have though that maybe it would be something like:

f <- predict(mlm(ys ~ xm), samples)

but there doesn't appear to be an mlm().

If the y's and x1's look familiar, they are out of the Excel
documentation for the TREND() function, which I am attempted to
reproduce in R.

Confused,

Mike Mascari




More information about the R-help mailing list