0483 - Trần Công Sơn - Bài Tập Số 2
0483 - Trần Công Sơn - Bài Tập Số 2
0483 - Trần Công Sơn - Bài Tập Số 2
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
$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
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
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
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
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)