Message-ID: <971536df050531140029ff1b41@mail.gmail.com>
Date: 2005-05-31T21:00:15Z
From: Gabor Grothendieck
Subject: simple predict question
In-Reply-To: <2954407796.1117558073@Lab26.DOMAIN.IE.PITT.EDU>
On 5/31/05, sms13+ at pitt.edu <sms13+ at pitt.edu> wrote:
> Excuse the simple question...
> I'm not sure what I'm doing wrong with predict, but let me use this example:
> Suppose I do:
> dat<-matrix(c(0,0,10,20),2,byrow=T)
> lm1<-lm(dat[,2]~dat[,1])
>
> Suppose I want to generate the linearly-interpolated y-values between the
> point (0,0) and (0,20) at every unit interval.
> I thought I just do:
> predict(lm1, data.frame(seq(0,10,1))) to get 0,2,4,6...,18,20, but instead
> I just get:
> 1 2
> 0 20
>
I think the names are confusing it. Try:
x <- dat[,1]; y <- dat[,2]
lm1 <- lm(y ~ x)
predict(lm1, data.frame(x = 1:10))