0% found this document useful (0 votes)
60 views10 pages

Stats 200 Problem Set 7

This document contains Pedro Martins' problem set 7 which includes 3 questions analyzing linear regression models. Question 1 estimates Pi using Monte Carlo simulations. Question 3 fits linear and quadratic regression models to load and deflection data from 3 experiments to determine if the relationships are linear or quadratic. Code is provided to estimate coefficients, residuals, and fit the linear and quadratic models for each deflection dataset.

Uploaded by

Pedro
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views10 pages

Stats 200 Problem Set 7

This document contains Pedro Martins' problem set 7 which includes 3 questions analyzing linear regression models. Question 1 estimates Pi using Monte Carlo simulations. Question 3 fits linear and quadratic regression models to load and deflection data from 3 experiments to determine if the relationships are linear or quadratic. Code is provided to estimate coefficients, residuals, and fit the linear and quadratic models for each deflection dataset.

Uploaded by

Pedro
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Stats 200 - Problem Set 7

Pedro G. Martins
3/15/2019

Problem Set 7

Question 1

Part c

#Disable scientific notation


options(scipen=999)

t_1 <- c(3.03,5.53,5.60,9.30,9.92,12.51,12.95,15.21,16.04,16.84)


t_2 <- c(3.19,4.26,4.47,4.53,4.67,4.69,12.78,6.79,9.37,12.75)

est_pi <- rep(0, 1000)

for(l in 1:1000) {
counter <- 0
t_1_sam <- sample(t_1, replace=T)
t_2_sam <- sample(t_2, replace=T)

for(j in 1:10){
for(k in 1:10){
if(t_1_sam[k] > t_2_sam[j]) {
counter <- counter + 1
}}}

est_pi[l] <- counter/100


}

mean(est_pi)

## [1] 0.74535
sd(est_pi)

## [1] 0.1172042

Part d

Now, the condidence interval is just mean_pi +/- 1.28*sd_pi/sqrt(100), with the values calculated above.

1
Question 3

Part a

load <- c(10000,20000,30000,40000,50000,60000,70000,80000,90000,100000)

deflection1 <- c(68.32,136.78,204.98,273.85,342.70,411.30,480.65,549.85,619.00,688.7)


deflection2 <- c(68.35,136.68,205.02,273.85,342.63,411.35,480.60,549.85,619.02,688.62)
deflection3 <- c(68.3,136.80,204.98,273.80,342.63,411.28,480.63,549.83,619.10,688.58)

plot(load,deflection1)
700
500
deflection1

300
100

20000 40000 60000 80000 100000

load
plot(load,deflection2,col = "red")

2
700
500
deflection2

300
100

20000 40000 60000 80000 100000

load
plot(load,deflection3,col = "blue")
700
500
deflection3

300
100

20000 40000 60000 80000 100000

load
The relationship does look linear.

Part b

#Calculation for the first deflection

model <- lm(deflection1 ~ load)

3
summary(model)

##
## Call:
## lm(formula = deflection1 ~ load)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.7745 -0.3707 -0.1980 0.3374 0.9331
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.464000000 0.416444802 -3.515 0.0079 **
## load 0.006892309 0.000006712 1026.922 <0.0000000000000002 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.6096 on 8 degrees of freedom
## Multiple R-squared: 1, Adjusted R-squared: 1
## F-statistic: 1.055e+06 on 1 and 8 DF, p-value: < 0.00000000000000022
beta1 <- summary(model)$coefficients[2]
beta0 <- summary(model)$coefficients[1]

y <- beta0+beta1*load

residuals <- (deflection1-y)


plot(load,residuals)
1.0
0.5
residuals

0.0
−0.5

20000 40000 60000 80000 100000

load
#Same calculation for the second deflection

4
model <- lm(deflection2 ~ load)
summary(model)

##
## Call:
## lm(formula = deflection2 ~ load)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.7074 -0.3751 -0.1620 0.2794 0.8965
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.46733333 0.40578434 -3.616 0.00682 **
## load 0.00689208 0.00000654 1053.866 < 0.0000000000000002 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.594 on 8 degrees of freedom
## Multiple R-squared: 1, Adjusted R-squared: 1
## F-statistic: 1.111e+06 on 1 and 8 DF, p-value: < 0.00000000000000022
beta1 <- summary(model)$coefficients[2]
beta0 <- summary(model)$coefficients[1]

y <- beta0+beta1*load

residuals <- (deflection2-y)


plot(load,residuals)
0.5
residuals

0.0
−0.5

20000 40000 60000 80000 100000

load
#Same calculation for the third deflection

model <- lm(deflection3 ~ load)

5
summary(model)

##
## Call:
## lm(formula = deflection3 ~ load)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.7736 -0.3946 -0.1880 0.3942 0.8527
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.474000000 0.414130963 -3.559 0.00741 **
## load 0.006892127 0.000006674 1032.633 < 0.0000000000000002 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.6062 on 8 degrees of freedom
## Multiple R-squared: 1, Adjusted R-squared: 1
## F-statistic: 1.066e+06 on 1 and 8 DF, p-value: < 0.00000000000000022
beta1 <- summary(model)$coefficients[2]
beta0 <- summary(model)$coefficients[1]

y <- beta0+beta1*load

residuals <- (deflection3-y)


plot(load,residuals)
0.5
residuals

0.0
−0.5

20000 40000 60000 80000 100000

load
In all the three cases we have a very clear pattern: the errors are systematically greater form small loads and
for large loads, so we know the deflection load relationship is mostly linear for intermediate loads, and a little
more deviant (but still quite linear under visual inspection in part a) for extremely large or small loads.

6
Part c

#Quadratic fit for first deflection run

model <- lm(deflection1 ~ I(load) + I(load^2))


summary(model)

##
## Call:
## lm(formula = deflection1 ~ I(load) + I(load^2))
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.18818 -0.10741 0.05748 0.08807 0.13491
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.14850000000013 0.16423329344358 0.904 0.396
## I(load) 0.00681168409091 0.00000685907472 993.091 < 0.0000000000000002
## I(load^2) 0.00000000073295 0.00000000006077 12.061 0.00000614
##
## (Intercept)
## I(load) ***
## I(load^2) ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.1396 on 7 degrees of freedom
## Multiple R-squared: 1, Adjusted R-squared: 1
## F-statistic: 1.005e+07 on 2 and 7 DF, p-value: < 0.00000000000000022
beta2 <- summary(model)$coefficients[3]
beta1 <- summary(model)$coefficients[2]
beta0 <- summary(model)$coefficients[1]

se_beta2 <- summary(model)$coefficients[3,2]


se_beta1 <- summary(model)$coefficients[2,2]
se_beta0 <- summary(model)$coefficients[1,2]

y <- beta0+beta1*deflection1+beta2*(deflection1^2)

residuals <- deflection1-y


plot(load,residuals)

7
700
500
residuals

300
100

20000 40000 60000 80000 100000

load
#Quadratic fit for second deflection run

model <- lm(deflection2 ~ I(load) + I(load^2))


summary(model)

##
## Call:
## lm(formula = deflection2 ~ I(load) + I(load^2))
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.13048 -0.06359 0.02297 0.06473 0.09558
##
## Coefficients:
## Estimate Std. Error t value
## (Intercept) 0.12266666666695 0.11318985060483 1.084
## I(load) 0.00681257878788 0.00000472728535 1441.119
## I(load^2) 0.00000000072273 0.00000000004188 17.256
## Pr(>|t|)
## (Intercept) 0.314
## I(load) < 0.0000000000000002 ***
## I(load^2) 0.000000539 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.09624 on 7 degrees of freedom
## Multiple R-squared: 1, Adjusted R-squared: 1
## F-statistic: 2.116e+07 on 2 and 7 DF, p-value: < 0.00000000000000022
beta2 <- summary(model)$coefficients[3]
beta1 <- summary(model)$coefficients[2]
beta0 <- summary(model)$coefficients[1]

8
se_beta2 <- summary(model)$coefficients[3,2]
se_beta1 <- summary(model)$coefficients[2,2]
se_beta0 <- summary(model)$coefficients[1,2]

y <- beta0+beta1*deflection2+beta2*(deflection2^2)

residuals <- deflection2-y


plot(load,residuals)
700
500
residuals

300
100

20000 40000 60000 80000 100000

load
#Quadratic fit for third deflection run

model <- lm(deflection3 ~ I(load) + I(load^2))


summary(model)

##
## Call:
## lm(formula = deflection3 ~ I(load) + I(load^2))
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.187576 -0.034955 0.008985 0.082856 0.138424
##
## Coefficients:
## Estimate Std. Error t value
## (Intercept) 0.13766666666683 0.14505570905745 0.949
## I(load) 0.00681154393939 0.00000605813794 1124.363
## I(load^2) 0.00000000073258 0.00000000005367 13.649
## Pr(>|t|)
## (Intercept) 0.374
## I(load) < 0.0000000000000002 ***
## I(load^2) 0.00000267 ***
## ---

9
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.1233 on 7 degrees of freedom
## Multiple R-squared: 1, Adjusted R-squared: 1
## F-statistic: 1.288e+07 on 2 and 7 DF, p-value: < 0.00000000000000022
beta2 <- summary(model)$coefficients[3]
beta1 <- summary(model)$coefficients[2]
beta0 <- summary(model)$coefficients[1]

se_beta2 <- summary(model)$coefficients[3,2]


se_beta1 <- summary(model)$coefficients[2,2]
se_beta0 <- summary(model)$coefficients[1,2]

y <- beta0+beta1*deflection3+beta2*(deflection3^2)

residuals <- deflection3-y


plot(load,residuals)
700
500
residuals

300
100

20000 40000 60000 80000 100000

load
The fit does not seem reasonable, as this time we have residuals in a scale two order of magnitude higher
than in the linear fitting case.

10

You might also like