LinearRegression: Linear Regression

Description Usage Arguments Details Value Note Author(s) References Examples

Description

Inferences for linear regression: confidence intervals and hypthesis testing on regression coefficients, confidence interval on the mean response at a given x and prediction interval on a future observation at a given x, Partial F-test, model adequacy checking.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# fit must be an lm object; e.g., fit=lm(y~x).
lm.est(fit)

# based on the fit, compute CIs and tests on betas
lm.coef.CI(fit,level=0.95)
# The default value of hypo.beta is zero
lm.coef.test(fit,alpha=0.05,H1="two",hypo.beta=?)

#Partial F-test,
#fit.H0 is the lm object using the null model
#fit.ALL is the lm object using the full model
lm.partialFtest(fit.H0=lmH0,fit.ALL=lmALL,alpha=0.05)

# Model Adequacy checking
lm.modelcheck(fit)
# fit must be an lm object. VIFs are also printed.

Arguments

fit

an lm object

level

the confidence level

alpha

the significance level

hypo.beta

the hypothesized beta value that about to be tested

fit.H0, fit.ALL

the null model and full model in the partial F-test

Details

Inferences for linear regression: confidence intervals and hypthesis testing on regression coefficients, confidence interval on the mean response at a given x and prediction interval on a future observation at a given x, Partial F-test, model adequacy checking.

Value

lm.est

the least squares estimates

interval

As long as the function has "interval", the outcome are confidence intervals.

test

As long as the function has "test", it conduct the hypothesis testing.

lm.modelcheck

residual analysis and VIFs

Note

deweiwang@stat.sc.edu

Author(s)

Dewei Wang

References

Chapters 11-12 of the textbook "Applied Statistics and Probability for Engineers" 7th edition

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
Example1=read.csv("https://raw.githubusercontent.com/Harrindy/StatEngine/master/Data/HydrocarbonPurity.csv")
x=Example1$HydrocarbonLevels
y=Example1$Purity
fit=lm(y~x)
lm.est(fit)
summary(fit)
lm.coef.interval(fit,level=0.95)
predict.lm(fit,new=data.frame(x=1),interval="confidence")
predict.lm(fit,new=data.frame(x=1),interval="prediction")


Example2=read.csv("https://raw.githubusercontent.com/Harrindy/StatEngine/master/Data/WireBond.csv")
head(Example2,2)
y=Example2$PullStrength
x1=Example2$WireLength
x2=Example2$DieHeight
fit=lm(y~x1+x2)
summary(fit)
lm.coef.interval(fit,level=0.95)
lm.coef.test(fit,alpha=0.05,H1="two")
predict.lm(fit,new=data.frame(x1=8,x2=275),interval="confidence")
predict.lm(fit,new=data.frame(x1=8,x2=275),interval="prediction")
data.summary(fit$residuals)
vif(fit)
lm.modelcheck(fit)

x3=x1^2
x4=x2^2
lmH0=lm(y~x1+x2)
lmALL=lm(y~x1+x2+x3+x4)
lm.partialFtest(fit.H0=lmH0,fit.ALL=lmALL,alpha=0.05)
summary(lm(y~x1+x2+x3))
summary(lm(y~x1+x2+x4))
summary(lm(y~x1+x2+x3+x4))

Example3=read.csv("https://raw.githubusercontent.com/Harrindy/StatEngine/master/Data/AirplaneSidewallPanels.csv")
head(Example3,2)
y=Example3$cost
x=Example3$lotsize
plot(x,y)
fit=lm(y~x)
lines(x,fit$fitted.values)
x2=x^2
fit.quad=lm(y~x+x2)
lines(x,fit.quad$fitted.values,col="blue")
summary(fit)
summary(fit.quad)


Example4=read.csv("https://raw.githubusercontent.com/Harrindy/StatEngine/master/Data/SurfaceFinishData.csv")
head(Example4,2)
plot(Example4)
y=Example4$SurfaceFinish
x1=Example4$RPM
x2=Example4$TypeofCuttingTool
fit=lm(y~x1+x2)
summary(fit)
par(mar=c(4,4,.1,.1))
par(mfrow=c(1,2))
plot(x1[x2==0],y[x2==0])
lines(x1[x2==0],fit$fitted.values[x2==0])
plot(x1[x2==1],y[x2==1])
lines(x1[x2==1],fit$fitted.values[x2==1])

x3=x1*x2
fit2=lm(y~x1+x2+x3)
summary(fit2)
par(mfrow=c(1,1))
plot(x1,y)
lines(x1[x2==0],fit$fitted.values[x2==0])
lines(x1[x2==1],fit$fitted.values[x2==1])
lines(x1[x2==0],fit2$fitted.values[x2==0],col="blue")
lines(x1[x2==1],fit2$fitted.values[x2==1],col="blue")

Harrindy/StatEngine documentation built on Nov. 19, 2021, 1:10 p.m.