8.1 The multi-faceted nature of regression
8.2 OLS Regression
OLS regression fit model form:
In order to properly interpret the coefficients of the OLS model, the data must meet the following statistical assumptions.
Port normality for fixed independent values, the value of the variable is normally distributed.
Independent of the mouth Independence Yi value.
Linear correlation between the linear dependent variable and the independent variable.
The variance of the variance dependent variable does not vary with the level of the independent variable. It can also be called invariant variance, but it is more sharp in the sense of variance.
8.2.1 using LM () to fit regression model
MYFIT<-LM (Formula,data)
Formula refers to the form of a model to fit, data is a dataset that contains the data used to fit the model.
Expression (Formula): Y~X1+X2+...+XK
8.2.2 Simple linear regression
> Fit<-lm (weight~height,data=women)
> Summary (FIT)
Call:
LM (Formula = weight ~height, data = women)
Residuals:
Min 1Q Median 3Q Max
-1.7333-1.1333-0.3833 0.7417 3.1167
Coefficients:
Estimate Std. Error T Valuepr (>|t|)
(Intercept) -87.51667 5.93694-14.74 1.71e-09 * * *
Height 3.45000 0.09114 37.85 1.09e-14 * * *
---
Signif. codes:0 ' * * * ' 0.001 ' * * ' 0.01 ' * ' 0.05 '. ' 0.1 "1
Residual standarderror:1.525 on degrees of freedom
multipler-squared:0.991, Adjusted r-squared:0.9903
f-statistic:1433 on 1 and DF, p-value:1.091e-14
> Plot (women$height,women$weight,xlab= "H", ylab= "W")
> Abline (FIT)
8.2.3 Polynomial regression
> Plot (women$height,women$weight,xlab= "H", ylab= "W")
> Abline (FIT)
> Fit2<-lm (Weight~height+i (height^2), data=women)
> Plot (women$height,women$weight,xlab= "Height (ininches)", ylab= "weight (in lbs)")
> Lines (women$height,fitted (fit2))
8.2.4 multi-element linear regression
> Library (CAR)
> States<-as.data.frame (State.x77[,c ("Murder", "Population", "illiteracy", "Income", "Frost")])
> Cor (states)
Murder Populationilliteracy Income
Murder 1.0000000 0.3436428 0.7029752-0.2300776
Population 0.3436428 1.0000000 0.1076224 0.2082276
Illiteracy 0.7029752 0.1076224 1.0000000-0.4370752
Income-0.2300776 0.2082276-0.4370752 1.0000000
frost-0.5388834-0.3321525-0.6719470 0.2262822
Frost
Murder-0.5388834
Population-0.3321525
Illiteracy-0.6719470
Income 0.2262822
Frost 1.0000000
> Scatterplotmatrix (states,spread=false,lty.smooth=2,main= "SPM")
Multivariate linear regression of 8.2.5 with interacting items
> Fit<-lm (mpg~hp+wt+hp:wt,data=mtcars)
> Summary (FIT)
Call:
LM (formula = MPG ~ HP +WT + HP:WT, data = Mtcars)
Residuals:
Min 1Q Median 3Q Max
-3.0632-1.6491-0.7362 1.4211 4.5513
Coefficients:
Estimate Std. Error T Valuepr (>|t|)
(Intercept) 49.80842 3.60516 13.816 5.01e-14 * * *
hp-0.12010 0.02470-4.863 4.04e-05 * * *
wt-8.21662 1.26971-6.471 5.20e-07 * * *
HP:WT 0.02785 0.00742 3.753 0.000811 * * *
---
Signif. codes:0 ' * * * ' 0.001 ' * * ' 0.01 ' * ' 0.05 '. ' 0.1 "1
Residual standarderror:2.153 on degrees of freedom
multipler-squared:0.8848, Adjusted r-squared:0.8724
f-statistic:71.66 on 3and DF, p-value:2.981e-13
The effect () function in the effects package, which can be used to graphically show the results of an interaction item
Plot (Effect (term,mod,xlevels), multiline=true)
Term is the model to be drawn, MoD for the model through LM (), Xlevels is a list, specify the variable to set the constant value, the Multiline=true option means to add the corresponding line.
Welcome attention:
R in Action reading notes (8)-eighth chapter: Regression (Part I)