day0204 - predict(lmskin,new) #5. Residual plot...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 #### Regression in R ######## # Change current directory (File -> Change dir. .) # Load the data file skin=read.table("skin.csv",header=T,sep = ",")# read.csv("skin.csv") will do the same job. #1. Correlation coefficient (r) cor(mortality,latitude) #2. Fitting least-square regression line attach(skin)# Attach variables in skin data to R workspace lmskin=lm(mortality~latitude)# Fit least-square regression line with 'latitude' as explanatory variable and 'mortality' as response # lm(mortality~latitude, data=skin) or lm(skin$mortality~skin$latitude) will do the same job if we have skipped attach(skin). summary(lmskin)# look for coefficient for the fitted line, and 'Multiple R-squared' for coefficient of determination (r^2) #3. Scatter plot with the fitted line plot(mortality~latitude)# scatter plot, same as "plot(latitude,mortality)" abline(lmskin)# Add the least-square regression line on the scatter plot #4. Prediction new=data.frame(latitude=37)# Make a new data. Note that 'latitude' is the explanatory variable.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: predict(lmskin,new) #5. Residual plot names(lmskin)# This will show you what kind of outputs R has stored for the 'lm' command lmskin$resid# Residuals for our least-squres regression line plot(lmskin$resid~latitude)# residual plot abline(0,0)# add a horizontal line with slope 0 and y intercept 0 ### We can adjust y axis range with the option 'ylim' plot(lmskin$resid~latitude,ylim=c(-100,100)) abline(h=0) Sheet1 Page 2 #### We can do the same job with R commander. #### (1) Load the R commader package : library(Rcmdr) #### (2) Import the data file : Data -> Import Data -> from text file, . ..... #### (3) Fit the least-sqaure regression line : Statistics -> Fit models -> Linear Regression #### (4) Draw the scatter plot with the fitted line : Graphs -> Scatterplot # Prediction is not available in R commander # correlation coefficient (r) : # In R commander, Statistics -> Summaries -> Correlation Matrix. ....
View Full Document

This note was uploaded on 09/11/2011 for the course STAT 200 taught by Professor Agniel during the Spring '09 term at University of Illinois at Urbana–Champaign.

Page1 / 2

day0204 - predict(lmskin,new) #5. Residual plot...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online