Language:EN
Pages: 27
Rating : ⭐⭐⭐⭐⭐
Price: $10.99
Page 1 Preview
codes anova test analysis deviance table model gam

Codes anova test analysis deviance table model gamma

INFT13/71-326
Statistical Learning and Regression Models Indicative Solutions
Week 10

Load some of the usual suspects:

8 10 14
65 70 75 80
trees$Height

# Start with linear regression, but maybe some heteroskedasticity, so might need to switch to # Gamma model.

1

10 20 30 40 50 60 70

fitted(trees.lm)

0.1
0.0
−0.1
−0.2
10 20 30 40 50 60

fitted(trees.glm)

trees$Volume
60
50
40
30
20
10
10 20 30 40 50 60 70

fitted(trees.lm)

trees$Volume
60
50
40
30
20
10
10 20 30 40 50 60

u1 <- trees$Volume - cbind(1,trees$Height)%*%coef(trees.lm)[c(1,3)] u2 <- trees$Volume - cbind(1,trees$Girth)%*%coef(trees.lm)[c(1,2)] plot(trees$Girth,u1,pch=16)

plot(trees$Height,u2,pch=16)

6

trees$Height

trees$Girth

plot(trees$Girth,v1,pch=16)
abline(coef(lm(v1~trees$Girth)),lty=3,col=2)

#So, let's see if a quadratic term in Girth is significant
trees.lmq <- lm(Volume~Height+Girth+I(Girth^2),data=trees)
trees.glmq <- glm(Volume~Height+Girth+I(Girth^2),family=Gamma(link="identity"),data=trees) anova(trees.lmq)

## Analysis of Variance Table
##
## Response: Volume

1 2901.2

2901.2 421.113 < 2.2e-16 ***

## Girth
## I(Girth^2)

27

186.0

6.9

## Signif. codes:

## Df Deviance Resid. Df Resid. Dev F Pr(>F)

## NULL 30 8.3172

## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

#Clearly, quadratic term is significant. Try height^2? Maybe girth^3? trees.lmq2 <- lm(Volume~Height+Girth+I(Girth^2)+I(Height^2),data=trees)

Df Sum Sq Mean Sq F value

## Height ## Girth

1 2901.2 1 4783.0

235.9 0.1

33.0009 4.769e-06 ***
0.0208 0.8865

26 185.9
## Signif. codes:

trees.glmq2 <- glm(Volume~Height+Girth+I(Girth^2)+I(Height^2),family=Gamma(link="identity"),data=trees)

trees.lmq3 <- lm(Volume~Height+Girth+I(Girth^2)+I(Girth^3),data=trees) anova(trees.lmq3)

## Analysis of Variance Table
##
## Response: Volume

Df Sum Sq Mean Sq
1 2901.2

2901.2 408.2570 < 2.2e-16 ***

## Girth

1 4783.0
## I(Girth^2) 1 235.9 235.9
residuals(trees.lm1)

−0.05
−0.15
2.5 3.0 3.5 4.0

fitted(trees.lm1)

−0.05
−0.15
2.5 3.0 3.5 4.0

trees.glm1$linear.predictors

abs(residuals(trees.lm1)) 0.15
0.10
0.05
0.00
2.5 3.0 3.5 4.0

16

0.10
0.05
0.00
2.5 3.0 3.5 4.0
log(trees$Volume)
3.5
3.0
2.5
2.5 3.0 3.5 4.0

18

log(trees$Volume)
3.5
3.0
2.5
2.5 3.0 3.5

## [1] 155.5867

trees.glm1$linear.predictors

barplot(CooksD)
abline(h=4/31,lty=3)

You are viewing 1/3rd of the document.Purchase the document to get full access instantly

Immediately available after payment
Both online and downloadable
No strings attached
How It Works
Login account
Login Your Account
Place in cart
Add to Cart
send in the money
Make payment
Document download
Download File
img

Uploaded by : Eileen Hobbs

PageId: DOCB84EF2D