R codes for various
Statistical tests
A) T-test
ex9-37
> Indoor=scan("clipboard")
Read 33 items
> Outdoor=scan("clipboard")
Read 33 items
> Indoor
[1] 0.07 0.08 0.09 0.12 0.12 0.12 0.13 0.14 0.15 0.15 0.17 0.17 0.18 0.18 0.18
[16] 0.18 0.19 0.20 0.22 0.22 0.23 0.23 0.25 0.26 0.28 0.28 0.29 0.34 0.39 0.40
[31] 0.45 0.54 0.62
> Outdoor
[1] 0.29 0.09 0.47 0.54 0.97 0.35 0.49 0.84 0.86 0.28 0.32 0.32 1.55 0.66 0.29
[16] 0.21 1.02 1.59 0.90 0.52 0.12 0.54 0.88 0.49 1.24 0.48 0.27 0.37 1.26 0.70
[31] 0.76 0.99 0.36
> t.test(Indoor,Outdoor,paired=T)
Paired t-test
data: Indoor and Outdoor
t = -5.9509, df = 32, p-value = 1.251e-06
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-0.5450513 -0.2670700
sample estimates:
mean of the differences
-0.4060606
B) Analysis of Variance: ANOVA, F-test
exp10-1
> y=scan("clipboard")
Read 24 items
> x=scan("clipboard")
Read 24 items
> y
[1] 656 788 734 721 679 699 789 773 787 686 732 775 737 639 696 672 717 727 535
[20] 629 542 559 587 520
> x
[1] 1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3 4 4 4 4 4 4
> x=as.factor(x)
> x
[1] 1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3 4 4 4 4 4 4
Levels: 1 2 3 4
> summary(aov(y~x))
Df Sum Sq Mean Sq F value Pr(>F)
x 3 127385 42462 25.125 5.474e-07 ***
Residuals 20 33801 1690
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
C) Simple Linear Regression Analysis
ex12-37
> x=scan("clipboard")
Read 10 items
> y=scan("clipboard")
Read 10 items
> plot(x,y)
> summary(lm(y~x))
Call:
lm(formula = y ~ x)
Residuals:
Min 1Q Median 3Q Max
-0.209799 -0.045309 -0.001910 0.082312 0.142137
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 2.1416477 0.0767926 27.89 2.95e-09 ***
x 0.0068006 0.0002618 25.98 5.17e-09 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.1101 on 8 degrees of freedom
Multiple R-Squared: 0.9883, Adjusted R-squared: 0.9868
F-statistic: 675 on 1 and 8 DF, p-value: 5.172e-09
> abline(2.1416,.0068)