Re: [R] Linear regression

From: Greg Snow <Greg.Snow_at_imail.org>
Date: Wed, 12 Nov 2008 14:03:04 -0700

Alireza,

The "lm" function fits the linear regression (linear model), the "predict" function predicts new response values based on values of the predictor variables.

Try something like:

> mydata <- data.frame( x=1:30, y=31:60+rnorm(30) )
> fit1 <- lm( y ~ x, data=mydata )
> summary(fit1) # optional
> plot(fit1) # optional
> newdata <- data.frame(x=3.5)
> predict(fit1, newdata)

Also you should reread section 11 of "An Introduction to R" to get more detail.

Hope this helps,

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow_at_imail.org
801.408.8111



> -----Original Message-----
> From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-
> project.org] On Behalf Of Dr. Alireza Zolfaghari
> Sent: Wednesday, November 12, 2008 1:57 PM
> To: R-help
> Subject: [R] Linear regression
>
> Hi List,
> Does anybody know what function I need to use for a simple regression?
>
> Here is the data: I want to find the value for x1=3.5
> data<-data.frame(x=c(1:30),Value=c(31:60))
> x1<-3.5
>
> Regards,
> Alireza
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.
______________________________________________ R-help_at_r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Received on Wed 12 Nov 2008 - 21:04:44 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 12 Nov 2008 - 21:30:24 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive