Prestige <- read.table('http://math.uttyler.edu/nathan/classes/statistics/data/prestige.data',header=TRUE) attach(Prestige) plot(education,prestige) # want m and b so that we can take a number of years of eductaion, # evaluate m*education + b, and obtain a guess at the prestige level # prestige = m*education + b (+ err) ### The easy way: mod.1 <- lm(prestige ~ education) #### lm(y~x) summary(mod.1) #Call: #lm(formula = prestige ~ education) # #Residuals: # Min 1Q Median 3Q Max #-26.0397 -6.5228 0.6611 6.7430 18.1636 # #Coefficients: # Estimate Std. Error t value Pr(>|t|) #(Intercept) -10.732 3.677 -2.919 0.00434 ** #education 5.361 0.332 16.148 < 2e-16 *** #--- #Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 # #Residual standard error: 9.103 on 100 degrees of freedom #Multiple R-squared: 0.7228, Adjusted R-squared: 0.72 #F-statistic: 260.8 on 1 and 100 DF, p-value: < 2.2e-16 ### prestige = 5.361*education - 10.732 ( + err) ### making a predication: 5.361*16-10.732 abline(mod.1,col='red') #### slope = 5.361 -- every extra year of education amounts to 5.361 #### extra prestige points #### intercept = -10.732 -- zero education = -10 prestige (kind of meaningless) #### #### std error = 9.103 -- average residual is 9.103 #### #### r^2 = .7228 -- 72.28% of the variability in prestige is explained #### by prestige's linear relationship with education x <- rnorm(30) y <- x*x plot(x,y) ### question1 == what percent of the vaiablility in y is explained by x? summary(lm(y~x))