Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

phân tích phương sai

nhietdo<-c(1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4)
vitc<-c(1343,1393,1420,1641,1897,2160,2169,2279,2890,1809,1926,1264,1314,1399,1602
385,2511,2514,2767,2827,2895,3011,2850,2964,2283,2973,2384,3171,2447,3257,2479,327
1,2495, 3288,2525,3358,2541,3643,2769,3657)
> bang<-data.frame(nhietdo,vitc)
> bang
nhietdo vitc
1 1 1343
2 1 1393
3 1 1420
4 1 1641
5 1 1897
6 1 2160
7 1 2169
8 1 2279
9 1 2890
10 1 1809
11 1 1926
12 2 1264
13 2 1314
14 2 1399
15 2 1605
16 2 2385
17 2 2511
18 2 2514
19 2 2767
20 2 2827
21 2 2895
22 2 3011
23 3 2850
24 3 2964
25 3 2283
26 3 2973
27 3 2384
28 3 3171
29 3 2447
30 4 3257
31 4 2479
32 4 3271
33 4 2495
34 4 3288
35 4 2525
36 4 3358
37 4 2541
38 4 3643
39 4 2769
40 4 3657
nhietdo<-as.factor(nhietdo)
attach(bang)
The following objects are masked _by_ .GlobalEnv:

nhietdo, vitc
analysis <- lm(vitc ~ nhietdo)
anova(analysis)
Analysis of Variance Table

Response: vitc
Df Sum Sq Mean Sq F value Pr(>F)
nhietdo 3 8019648 2673216 9.8221 7.147e-05 ***
Residuals 36 9797895 272164
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

res <- aov(vitc ~ nhietdo)


TukeyHSD (res) (Cho biết từng cặp dữ liệu có khác nhau hay kh)
Tukey multiple comparisons of means
95% family-wise confidence level
Fit: aov(formula = vitc ~ nhietdo)

$nhietdo
diff lwr upr p adj
2-1 324.0909 -275.0194 923.2012 0.4733814
3-1 822.1169 142.7897 1501.4441 0.0124832
4-1 1123.2727 524.1624 1722.3830 0.0000738
3-2 498.0260 -181.3013 1177.3532 0.2164549
4-2 799.1818 200.0715 1398.2921 0.0051381
4-3 301.1558 -378.1714 980.4831 0.6345512

bài 1
a<-c(150, 140, 170, 160, 90, 240, 100, 140, 120, 100)
b<-c(100, 130, 80, 70, 40, 60, 120, 110, 30, 80)
a[order(a)]
[1] 90 100 100 120 140 140 150 160 170 240
b[order(b)]
[1] 30 40 60 70 80 80 100 110 120 130

> mean(a)
[1] 141
> mean(b)
[1] 82
> sd(a)
[1] 44.08325
> sd(b)
[1] 33.2666
> u1(a)=(141-90)/44.08
1.156987
un(a)=(240-141)/44.08
2.245917
u1(b)=(82-30)/33.3
1.561562
un(b)=(130-30)/33.3
3.003003
n=10
h=2,18
kết luậncó 2 gía trị bất thường 30 và 90 loại bỏ
nhietdo<-c(1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2)
> vitc<-c(150, 140, 170, 160, 90, 240, 100, 140, 120, 100,100,
130, 80, 70, 40, 60, 120, 110, 30, 80)
> bang<-data.frame(nhietdo,vitc)
> bang
nhietdo vitc
1 1 150
2 1 140
3 1 170
4 1 160
5 1 90
6 1 240
7 1 100
8 1 140
9 1 120
10 1 100
11 2 100
12 2 130
13 2 80
14 2 70
15 2 40
16 2 60
17 2 120
18 2 110
19 2 30
20 2 80
> nhietdo<-as.factor(nhietdo)
> attach(bang)
The following objects are masked _by_ .GlobalEnv:

nhietdo, vitc

> analysis <- lm(vitc ~ nhietdo)


> anova(analysis)
Analysis of Variance Table

Response: vitc
Df Sum Sq Mean Sq F value Pr(>F)
nhietdo 1 17405 17405 11.413 0.003348 **
Residuals 18 27450 1525
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> res <- aov(vitc ~ nhietdo)
> TukeyHSD (res)
Tukey multiple comparisons of means
95% family-wise confidence level

Fit: aov(formula = vitc ~ nhietdo)


$nhietdo
diff lwr upr p adj
2-1 -59 -95.69102 -22.30898 0.0033484
kết luận: ở nhiệt độ khác nhau có ảnh hưởng đến chất
lượng xoài xấy

nhiet.do=a[order(a)]
plot(nhiet.do, dnorm(nhiet.do, 141, 44.08325), type="l",
ylab="f(nhiet.do) ", xlab="nhiet.do", main="sự ảnh hưởng
nhiệt độ đến hàm lượng vitamin C")

nhietdo= b[order(b)]
plot(nhietdo, dnorm(nhietdo,82,33.2666), type="l",
ylab="f(nhietdo) ", xlab="nhietdo", main="sự ảnh hưởng
nhiệt độ đến hàm lượng vitamin C")
bài 2
a<-c(17.55, 17.60, 14.85, 14.90, 14.95, 15.00, 15.05, 15.10,
15.15, 15.20, 17.65, 17.70,
+ 17.75, 17.80, 17.85, 17.90, 17.95, 16.00, 16.05, 16.10)
> a[order(a)]
[1] 14.85 14.90 14.95 15.00 15.05 15.10 15.15 15.20 16.00
16.05 16.10 17.55 17.60 17.65 17.70 17.75 17.80 17.85 17.90
17.95
> mean(a)
[1] 16.405
> sd(a)
[1] 1.3009
>u1= (16.4-14.85)/1.3
[1] 1.192308
>un= (17.95-16.04)/1.3
[1] 1.469231
Giá trị TSS trung bình 20 mẫu kiểm tra=16.405 khác với giá
trị TCCS được quy định trong TSS=14.3
nhietdo=a[order(a)]
plot(nhietdo, dnorm(nhietdo,16.405,1.3009), type="l",
ylab="f(nhietdo) ", xlab="nhietdo", main="sự ảnh hưởng
nhiệt độ đến hàm lượng vitamin C")

bài 3

Hàm lượng đường (%)


20 22 24 26
Nồng độ 9.4, 8.9, 11.6, 10.1, 11.8, 12.9, 13.2, 12.4,
cồn 9.5, 9.8, 10.6, 12.2, 10.3, 13.2, 12.5,
(%) 10.1, 8.3, 11.3, 9.9, 12.4, 13.1, 13.8, 12.5,
8.1, 10.5, 9.7, 12.4 13.3, 12.5,
9.2, 9.0, 9.8, 13.6, 11.9,
7.8, 10.8, 9.1 10.7
8.3, 7.9

mean 8.772727 10.29091 12.15714 12.69091

sd 0.7444339 0.7462634 0.9253056 0.8791525


var
HLD<-c(1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,
4,4,4,4,4,4,4,4,4,4,4)
ndc<-c(9.4, 8.9, 9.5,10.1, 8.3, 8.1,9.2, 9.0, 7.8,8.3, 7.9,9.4, 8.9,
9.5,10.1, 8.3, 8.1,9.2, 9.0, 7.8,8.3, 7.9,11.8, 12.9,12.2,
10.3,12.4, 13.1,12.4,13.2, 12.4,13.2, 12.5,13.8, 12.5,13.3,
12.5,13.6, 11.9,10.7)
bang<-data.frame(HLD,ndc)
bang
HLD ndc
1 1 9.4
2 1 8.9
3 1 9.5
4 1 10.1
5 1 8.3
6 1 8.1
7 1 9.2
8 1 9.0
9 1 7.8
10 1 8.3
11 1 7.9
12 2 9.4
13 2 8.9
14 2 9.5
15 2 10.1
16 2 8.3
17 2 8.1
18 2 9.2
19 2 9.0
20 2 7.8
21 2 8.3
22 2 7.9
23 3 11.8
24 3 12.9
25 3 12.2
26 3 10.3
27 3 12.4
28 3 13.1
29 3 12.4
30 4 13.2
31 4 12.4
32 4 13.2
33 4 12.5
34 4 13.8
35 4 12.5
36 4 13.3
37 4 12.5
38 4 13.6
39 4 11.9
40 4 10.7
HLD<-as.factor(HLD)
attach(bang)
The following objects are masked _by_ .GlobalEnv:

HLD, ndc
analysis <- lm(ndc~HLD)
anova(analysis)
Analysis of Variance Table

Response: ndc
Df Sum Sq Mean Sq F value Pr(>F)
HLD 3 137.53 45.843 68.908 5.464e-15 ***
Residuals 36 23.95 0.665
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
bài 4

Condition<-c(1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2)
> Material<-c(1,1,1,2,2,2,3,3,3,1,1,1,2,2,2,3,3,3)
> Mau<-c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18)
> score<-c(4.1, 3.9, 4.3, 3.1, 2.8, 3.3, 3.5, 3.2, 3.6, 2.7, 3.1, 2.6, 1.9, 2.2, 2.3,
2.7, 2.3, 2.5)
> bang<-data.frame( Condition,Material,Mau,score)
> bang
Condition Material Mau score
1 1 1 1 4.1
2 1 1 2 3.9
3 1 1 3 4.3
4 1 2 4 3.1
5 1 2 5 2.8
6 1 2 6 3.3
7 1 3 7 3.5
8 1 3 8 3.2
9 1 3 9 3.6
10 2 1 10 2.7
11 2 1 11 3.1
12 2 1 12 2.6
13 2 2 13 1.9
14 2 2 14 2.2
15 2 2 15 2.3
16 2 3 16 2.7
17 2 3 17 2.3
18 2 3 18 2.5
> twoway <- lm(score ~ Condition + Material)
> anova(twoway)
Analysis of Variance Table

Response: score
Df Sum Sq Mean Sq F value Pr(>F)
Condition 1 5.0139 5.0139 33.9584 3.33e-05 ***
Material 1 0.7008 0.7008 4.7466 0.04572 *
Residuals 15 2.2147 0.1476
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> summary(twoway)

Call:
lm(formula = score ~ Condition + Material)

Residuals:
Min 1Q Median 3Q Max
-0.73333 -0.21944 0.02222 0.29722 0.52500

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 5.0722 0.3623 14.001 5.12e-10 ***
Condition -1.0556 0.1811 -5.827 3.33e-05 ***
Material -0.2417 0.1109 -2.179 0.0457 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.3843 on 15 degrees of freedom


Multiple R-squared: 0.7207, Adjusted R-squared: 0.6835
F-statistic: 19.35 on 2 and 15 DF, p-value: 7.008e-05

> anova(twoway <- lm(score ~ Condition+ Material+Condition*Material))


Analysis of Variance Table

Response: score
Df Sum Sq Mean Sq F value Pr(>F)
Condition 1 5.0139 5.0139 33.2063 4.915e-05 ***
Material 1 0.7008 0.7008 4.6415 0.04911 *
Condition:Material 1 0.1008 0.1008 0.6678 0.42751
Residuals 14 2.1139 0.1510
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> Material <- as.factor(Material)
> res <- aov(score ~ Condition+ Material+Condition)
> TukeyHSD(res)
Tukey multiple comparisons of means
95% family-wise confidence level
Fit: aov(formula = score ~ Condition + Material + Condition)

$Material
diff lwr upr p adj
2-1 -0.8500000 -1.19610279 -0.5038972 0.0000442
3-1 -0.4833333 -0.82943612 -0.1372305 0.0068648
3-2 0.3666667 0.02056388 0.7127695 0.0374069

Warning messages:
1: In replications(paste("~", xx), data = mf) :
non-factors ignored: Condition
2: In TukeyHSD.aov(res) :
'which' specified some non-factors which will be dropped
> plot(TukeyHSD(res), ordered=TRUE)

You might also like