Loading [MathJax]/jax/output/HTML-CSS/jax.js
  • Simple linear regression
    • Linear regeression assumptions
    • Population regression function
    • Population regression model
    • Sample regression model
    • Solve ^β1,^β2 and variance
    • Calculate the variance ˆσ2 of error ei
    • Sum of squares decomposition
    • Coefficient of determination R2 and goodness of fit
    • Test of regression coefficients
    • Statistical test of model
    • Mean prediction
    • Individual prediction
  • Multiple linear regression
    • Matrix format
    • Variance covariance matrix of random errors
    • Minimize Q, (yˆy)2
    • Solve ˆβ by derivation
    • Solve ^σβ2
    • Solve S2(ˆβ)
    • Sum of squares decomposition (matrix format)
    • Determination coefficient R2 and goodness of fit
    • Test of regression coefficients
    • Test of model
    • Mean prediction
    • Individual prediction

Simple linear regression

Linear regeression assumptions

There are four principal assumptions:

  • linearity of the relationship between dependent and independent variables.

  • statistical independence of the errors with y variable.

  • homoscedasticity (constant variance) of the errors for all x.

  • normality of the error distribution.

if independent assumption violated, the estimated standard errors tend to underestimate the true standard error. P value associated thus is lower.

only the prediction errors need to be normally distributed. but with extremely asymmetric or long-tailed, it may be hard to fit them (x and y) into a linear model whose errors will be normally distributed.

Population regression function

Regression is to estimate and/or predict the population mean (expectation) of dependent variable (yi) by a known or a set value of explanatory variables (xi). Population regression line (PRL) is the trajectory of the conditional expectation value given Xi.

E(Y|Xi)=f(Xi)=β1+β2Xi This is an unknown but fixed value (can be estimated).

Population regression model

the errors ui=yiˆyi have equal variance Yi=β1+β2Xi+ui

Sample regression model

(using hat to indicate sample) Yi=ˆβ1+ˆβ2Xi+ei

since
uiN(0,σ2) or eiN(0,ˆσ2) and

i.i.d., independent identically distribution, the probability distributions are all the same and variables are independent of each other.

uii.i.d N(0,σ2)

then

Yiβ1+β2Xi(^Yi)i.i.d N(0,σ2)

thence, to minimize Q (YiˆYi)2 to solve b0 and b1.

Min(Q)=(YiˆYi)2=(Yi(ˆβ1+ˆβ2Xi))2=f(ˆβ1,ˆβ2)

Solve ^β1,^β2 and variance

ˆβ2=xiyix2i^β1=ˉYiˆβ2ˉXivar(ˆβ2)=σ2ˆβ2=1x2iσ2var(ˆβ1)=σ2ˆβ1=X2inx2iσ2

Calculate the variance ˆσ2 of error ei

(for sample)

ˆYi=ˆβ1+ˆβ2Xiei=YiˆYiˆσ2=e2in1=(YiˆYi)2n1

Sum of squares decomposition

(Yi¯Yi)=(^Yi¯Yi)+(Yi^Yi)y2i=^yi2+e2iTSS=ESS+RSS

Coefficient of determination R2 and goodness of fit

r2=ESSTSS=(^YiˉY)2(YiˉY)2=1RSSTSS=1(Yi^Yi)2(YiˉY)2

Test of regression coefficients

since
^β2N(β2,σ2^β2)^β1N(β1,σ2^β1)

and Sˆβ2=1x2iˆσSˆβ1=X2inx2iˆσ

therefore
t^β2=^β2β2S^β2=^β2S^β2=^β21x2iˆσt(n2)t^β1=^β1β1S^β1=^β1S^β1=^β1X2inx2iˆσt(n2)

Statistical test of model

since Yii.i.d N(β1+β2Xi,σ2) and
ESS=(^YiˉY)2χ2(dfESS)RSS=(Yi^Yi)2χ2(dfRSS)

therefore F=ESS/dfESSRSS/dfRSS=MSSESSMSSRSS=(^YiˉY)2/dfESS(Yi^Yi)2/dfRSS=^β22x2ie2i/(n2)=^β22x2iˆσ2

Mean prediction

since

μˆY0=E(ˆY0)=E(ˆβ1+ˆβ2X0)=β1+β2X0=E(Y|X0) and var(ˆY0)=σ2ˆY0=E(ˆβ1+ˆβ2X0)=σ2(1n+(X0ˉX)2x2i) therefore ˆY0N(μˆY0,σ2ˆY0)ˆY0N(E(Y|X0),σ2(1n+(X0ˉX)2x2i))

then construct t statistic to estimate CI tˆY0=ˆY0E(Y|X0)SˆY0t(n2)

ˆY0t1α/2(n2)SˆY0E(Y|X0)ˆY0+t1α/2(n2)SˆY0

Individual prediction

since

(Y0ˆY0)N(μ(Y0ˆY0),σ2(Y0ˆY0))(Y0ˆY0)N(0,σ2(1+1n+(X0ˉX)2x2i))

and Construct t statistic tˆY0=ˆY0E(Y|X0)SˆY0t(n2)

and SˆY0=ˆσ2(1n+(X0ˉX)2x2i) therefore

ˆY0t1α/2(n2)SˆY0E(Y|X0)ˆY0+t1α/2(n2)SˆY0

it is harder to predict your weight based on your age than to predict the mean weight of people who are your age. so, the interval of individual prediction is wider than those of mean prediction.

Multiple linear regression

Matrix format

Yi=β1+β2X2i+β3X3i++βkXki+ui 

[Y1Y2Yn]=[1X21X31Xk11X22X32Xk21X2nX3nXkn][β1β2βk]+[u1u2un]

y=Xβ+u(n×1)(n×k)(k×1)+(n×1)

Variance covariance matrix of random errors

because uN(0,σ2I) populationeN(0,σ2I) sample 

therefore varcov(u)=E(uu)=[σ21σ212σ21nσ221σ22σ22nσ2n1σ2n2σ2n](E(ui)=0)=[σ2σ212σ21nσ221σ2σ22nσ2n1σ2n2σ2](var(ui)=σ2)=[σ2000σ2000σ2](cov(ui,uj)=0,ij)=σ2[100010001]=σ2I

Minimize Q, (yˆy)2

Q=e2i=ee=(yXˆβ)(yXˆβ)=yy2ˆβXy+ˆβXXˆβ

Solve ˆβ by derivation

(population=sample)

Qˆβ=0(yy2ˆβXy+ˆβXXˆβ)ˆβ=02Xy+2XXˆβ=0Xy+XXˆβ=0XXˆβ=Xy ˆβ=(XX)1Xy

Solve ^σβ2

varcov(ˆβ)=E((ˆβE(ˆβ))(ˆβE(ˆβ)))=E((ˆββ)(ˆββ))=E(((XX)1Xu)((XX)1Xu))=E((XX)1XuuX(XX)1)=(XX)1XE(uu)X(XX)1=(XX)1Xσ2IX(XX)1=σ2(XX)1XX(XX)1=σ2(XX)1

Solve S2(ˆβ)

(for sample)

where ˆσ2=e2ink=eenkE(ˆσ2)=σ2

therefore S2ij(ˆβ)=ˆσ2(XX)1=eenk(XX)1 which is variance-covariance of coefficients

Sum of squares decomposition (matrix format)

TSS=yynˉY2RSS=ee=yyˆβXyESS=ˆβXynˉY2

Determination coefficient R2 and goodness of fit

R2=ESSTSS=ˆβXynˉY2yynˉY2

Test of regression coefficients

because uN(0,σ2I)ˆβN(β,σ2XX1) therefore

(for all coefficients test, vector, see above S2ˆβ ) tˆβ=ˆββSˆβt(nk)

(for individual coefficient test) tˆβ=ˆβS2ij(ˆβkk) where S2ij(ˆβkk)=[s2ˆβ1,s2ˆβ2,,s2ˆβk]

they are on diagonal line of the matrix of S2(ˆβ)

Test of model

unrestricted model uii.i.d N(0,σ2)Yii.i.d N(β1+β2Xi++βkXi,σ2)RSSU=(Yi^Yi)2χ2(nk) restricted model uii.i.d N(0,σ2)Yii.i.d N(β1,σ2)RSSR=(Yi^Yi)2χ2(n1) F test F=(RSSRRSSU)/(k1)RSSU/(nk)=ESSU/dfESSURSSU/dfRSSUF(dfESSU,dfRSSU)

F=ESSU/dfESSURSSU/dfRSSU=(ˆβXynˉY2)/(k1)(yyˆβXy)/(nk)

Mean prediction

since E(ˆY0)=E(X0ˆβ)=X0β=E(Y0)var(ˆY0)=E(X0ˆβX0β)2=E(X0(ˆββ)(ˆββ)X0)=EX0((ˆββ)(ˆββ))X0=σ2X0(XX)1X0 and ˆY0N(μˆY0,σ2ˆY0)ˆY0N(E(Y0|X0),σ2X0(XX)1X0) construct t statistic tˆY0=ˆY0E(Y|X0)SˆY0t(nk)

therefore ˆY0t1α/2(n2)SˆY0E(Y|X0)ˆY0+t1α/2(n2)SˆY0

where SˆY0=ˆσ2X0(XX)1X0ˆσ2=ee(nk)

Individual prediction

since e0=Y0ˆY0

and E(e0)=E(Y0ˆY0)=E(X0β+u0X0ˆβ)=E(u0X0(ˆββ))=E(u0X0(XX)1Xu)=0

var(e0)=E(Y0ˆY0)2=E(e20)=E(u0X0(XX)1Xu)2=σ2(1+X0(XX)1X0)

and
e0N(μe0,σ2e0)e0N(0,σ2(1+X0(XX)1X0))

construct a t statistic te0=ˆY0Y0Se0t(nk)

therefore ˆY0t1α/2(n2)SY0ˆY0(Y0|X0)ˆY0+t1α/2(n2)SY0ˆY0

where SY0ˆY0=Se0=ˆσ2(1+X0(XX)1X0)ˆσ2=ee(nk)