The decimal point is 2 digit(s) to the right of the |
0 | 1111122233334
0 | 55578
1 |
1 | 579
Min. 1st Qu. Median Mean 3rd Qu.
Max.
5.0 19.3 27.0
50.4 50.1 185.9
> hist(yields); boxplot(yields); qqnorm(yields);
> plot(density(yields));
>
> stem(yields) ; summary(yields);
The decimal point is 1 digit(s) to the right of the |
0 | 400222
2 | 123928
4 | 011
6 | 119
8 | 92
10 | 0
Min. 1st Qu. Median Mean 3rd Qu.
Max.
4.40 12.30 32.10 40.47
60.80 99.60
>
> plot(yields~spend)
>
> fm0 <- lm(yields~1)
# Summarization by mean only.
> summary(fm0) # Yields = b_0 + epsilon
Call:
lm(formula = yields ~ 1)
Residuals:
Min
1Q Median 3Q
Max
-36.067 -28.167 -8.367 20.333
59.133
Coefficients:
Estimate Std. Error t value
Pr(>|t|)
(Intercept) 40.467
6.586 6.144
5.28e-06 ***
---
Signif. codes: 0 `***' 0.001 `**' 0.01
`*' 0.05 `.' 0.1 ` ' 1
Residual standard error: 30.18 on 20 degrees of freedom
> # Plot the fitted line overlayed over the y
vs. x scatter plot
> plot(spend,yields,xlab="spend", ylab="yields",
main="Summary by mean");
> abline(coef(fm0),0)
> # Plots for diagnosis
> par(mfrow=c(2,2));
> plot(fm0)
> fm1 <- lm(yields~spend) # Regress yields
on spend.
> summary(fm1) # Yields = b_0 + b_1 (spend)
+ epsilon
Call:
lm(formula = yields ~ spend)
Residuals:
Min 1Q Median
3Q Max
-42.422 -12.623 -8.171 8.832 50.526
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 22.16269 7.08948 3.126
0.00556 **
spend 0.36317
0.09712 3.739 0.00139 **
---
Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1
Residual standard error: 23.5 on 19 degrees of freedom
Multiple R-Squared: 0.424, Adjusted R-squared:
0.3936
F-statistic: 13.98 on 1 and 19 DF, p-value: 0.001389
> names(fm1) # List variables from the regression
output
[1] "coefficients" "residuals"
"effects" "rank"
[5] "fitted.values" "assign"
"qr"
"df.residual"
[9] "xlevels" "call"
"terms" "model"
> # Plot the fitted line overlayed over the y
vs. x scatter plot
> plot(spend,yields,xlab="spend", ylab="yields",
main="Simple Linear Regression");
> abline(coef(fm1))
> # Plots for diagnosis
> plot(fm1)
>
> fm2 <- lm(yields~spend+I(spend^2))
> summary(fm2)
Call:
lm(formula = yields ~ spend + I(spend^2))
Residuals:
Min 1Q Median
3Q Max
-37.825 -9.128 -2.773 9.560 34.460
Coefficients:
Estimate Std. Error t value
Pr(>|t|)
(Intercept) 7.059322 9.986180 0.707
0.4887
spend 1.084708
0.369944 2.932 0.0089 **
I(spend^2) -0.003990 0.001984 -2.011
0.0595 .
---
Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1
Residual standard error: 21.82 on 18 degrees of freedom
Multiple R-Squared: 0.5296, Adjusted R-squared:
0.4774
F-statistic: 10.13 on 2 and 18 DF, p-value: 0.001127
> plot(spend,yields,xlab="spend", ylab="yields",
main="Polynomial Regression");
> hat<-predict(fm2)
> points(approx(spend, hat), col = 2, pch = "*")
Warning message:
Collapsing to unique x values in: approx(spend, hat)
>
> par(mfrow=c(2,2));
> plot(fm2)
> detach(tvad)
> q()
> # Exit (You don't need to save workspace image)
>
>