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

MATH 6170-500 -Experimental design I

Mechanical Engineering Department


Seymur Hasanov, #T00285391

HOMEWORK 2 - ANSWERS

PROBLEM 16.19
a. > Y # <<-- Y matrix setup
[,1]
[1,] 28
[2,] 26
[3,] 31
[4,] 27
[5,] 35
[6,] 34
[7,] 29
[8,] 25
[9,] 31
[10,] 29
[11,] 31
[12,] 25
[13,] 27
[14,] 29
[15,] 28
> X # <<-- X matrix setup
[,1] [,2] [,3]
[1,] 1 1 0
[2,] 1 1 0
[3,] 1 1 0
[4,] 1 1 0
[5,] 1 1 0
[6,] 1 0 1
[7,] 1 0 1
[8,] 1 0 1
[9,] 1 0 1
[10,] 1 0 1
[11,] 1 -1 -1
[12,] 1 -1 -1
[13,] 1 -1 -1
[14,] 1 -1 -1
[15,] 1 -1 -1

> B # <<-- B matrix setup


[,1]
[1,] 29.0
[2,] 0.4
[3,] 0.6
MATH 6170-500 -Experimental design I
Mechanical Engineering Department
Seymur Hasanov, #T00285391

b. Obtain XB and develop equivalent expressions of the elements of this vector in


terms of the cell means 𝜇𝑖.

> t(XB)
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,1
4] [,15]
[1,] 29.4 29.4 29.4 29.4 29.4 29.6 29.6 29.6 29.6 29.6 28 28 28
28 28

XB > cell means (29.4, 29.6, 28)

Develop an expression -->>

c. Obtain the fitted regression function


> coef(lm(y~x1+x2))
(Intercept) x1 x2
29.0 0.4 0.6
We can confirm from the B matrix that
> t(B)
[,1] [,2] [,3]
[1,] 29 0.4 0.6

𝑌̅ = 29 + 0.4 ∗ 𝑋1 + 0.6 ∗ 𝑋2

d. Obtain the regression analysis of variance table

> SSTO
[,1]
[1,] 124
> SSTR
[,1]
[1,] 7.6
> SSE
[,1]
[1,] 116.4
> MSTR
MATH 6170-500 -Experimental design I
Mechanical Engineering Department
Seymur Hasanov, #T00285391

[,1]
[1,] 3.8
> MSE
[,1]
[1,] 9.7
> F_value
[,1]
[1,] 0.3917526

Source of
SS MS df F-value
variables
Between
7.6 3.8 2 0.3917526
treatments
Error (within
116.4 9.7 12
treatments)
Total 124 14

e.
> alpha <- 0.1
> F_stat <- qf(1-alpha,r-1,n-r)
> F_value <- MSTR/MSE
> F_stat
[1] 2.806796
> F_value
[,1]
[1,] 0.3917526

> if (F_stat>=F_value){
+ print("Do not reject the null hypothesis")
+ }
[1] "Do not reject the null hypothesis"
> # Conclusion is that equality of factor level means or the effect
s due to treatment levels are equal to 0, so we accept the hypothesis
.
MATH 6170-500 -Experimental design I
Mechanical Engineering Department
Seymur Hasanov, #T00285391

PROBLEM 16.27. Noncentrality parameter Fi is calculated in R


> mu <- c(22,28,22)
> s <- 1.6
>
> mu_mean <- mean(mu)
> SQ <-0
> Fi <-0
> n <- c(12,12,12)
> nt <- sum(n)
> r <- 3
> for (i in 1:3) {
+
+ SQ <- SQ + (1/r)*(n[i]*(mu[i]-mu_mean)^2)
+ Fi <- (1/s)*sqrt(SQ)
+ }
> print(Fi)
[1] 6.123724
>
> v1 <- r - 1
> v2 <- nt - r
>
# The power of the F test from Table B11 is Power = 1 (with alpha=0.01, v1=2
,v2=33, Fi=6.12)
> power.t.test(n=12,delta=6,sd=1.6) #calculated using power function to verify

Two-sample t test power calculation

n = 12
delta = 6
sd = 1.6
sig.level = 0.05
power = 1
alternative = two.sided

NOTE: n is number in *each* group

PROBLEM 16.41
MATH 6170-500 -Experimental design I
Mechanical Engineering Department
Seymur Hasanov, #T00285391

PROBLEM 16.46
a.
> y <- c(rnorm(5,mean=100,sd=12),rnorm(5,mean=100,sd=12),rnorm(5,mean=1
00,sd=12))
> a <-anova(lm(y~factor(x)))
> y
[1] 94.84066 103.12687 110.44553 93.02069 110.37969 97.62888 110.33
53 106.14340 94.33223 111.36437 115.41887 93.99783
[13] 103.62549 90.94148 95.98118
> a
Analysis of Variance Table

Response: y
Df Sum Sq Mean Sq F value Pr(>F)
factor(x) 2 39.89 19.943 0.2682 0.7692
Residuals 12 892.28 74.357

b. Repeat it 100 times and get the mean of 100F*


n=100
> x <- c(rep(1,5),rep(2,5),rep(3,5))
>
> F_value <- c(rep(0,n))
> P_value <- c(rep(0,n))
> for (i in 1:n) {
+ y <- c(rnorm(5,mean=100,sd=12),rnorm(5,mean=100,sd=12),rnorm(5,
mean=100,sd=12))
+ a <-anova(lm(y~factor(x)))
+ F_value[i] <- a[[4]][1]
+ P_value[i] <- a[[5]][1]
+ }
> data <- data.frame(F_value,P_value)
> print(data)
F_value P_value
1 0.25044272 0.78242519
2 1.04527054 0.38152364
3 1.52596891 0.25676332
4 1.69716846 0.22434766
5 0.24356640 0.78760977
6 0.68880146 0.52097595
7 1.09222705 0.36661626
8 0.17018343 0.84551059
9 1.04282389 0.38231957
10 1.01600402 0.39117269
11 2.25557093 0.14737534
12 0.47735271 0.63171651
13 0.21790871 0.80731208
14 1.85726216 0.19828052
15 2.63465252 0.11257405
16 0.09135292 0.91332412
17 1.78887982 0.20895727
18 0.18350633 0.83463894
MATH 6170-500 -Experimental design I
Mechanical Engineering Department
Seymur Hasanov, #T00285391

19 0.14249165 0.86864046
20 1.17440816 0.34212989
21 2.49641285 0.12402061
22 1.56540050 0.24883757
23 2.07215006 0.16864448
24 2.09012257 0.16640903
25 0.40154425 0.67795207
26 1.75873902 0.21387530
27 1.27498456 0.31471326
28 0.50395825 0.61636935
29 0.89989037 0.43236881
30 2.42139300 0.13079884
31 0.62763296 0.55049935
32 0.28667859 0.75575314
33 3.04787941 0.08504067
34 0.24145027 0.78921333
35 1.36089171 0.29330869
36 0.68141347 0.52444194
37 0.59298148 0.56808898
38 0.09175024 0.91296676
39 0.85574197 0.44934584
40 1.04623114 0.38121167
41 0.35334418 0.70940330
42 0.31562869 0.73520418
43 0.13262407 0.87706028
44 1.03040209 0.38639057
45 1.56542465 0.24883281
46 1.43857135 0.27540404
47 2.99853795 0.08787711
48 1.44420592 0.27415567
49 1.79816352 0.20746913
50 0.59905872 0.56495720
51 0.66134364 0.53399412
52 0.38619047 0.68779070
53 1.50609974 0.26086842
54 3.96579103 0.04762520
55 0.56714476 0.58163156
56 3.29497210 0.07234674
57 2.12979386 0.16159589
58 0.31678320 0.73439832
59 2.85791611 0.09658688
60 0.07801445 0.92541627
61 1.70824953 0.22241953
62 0.16282868 0.85158290
63 0.75700045 0.49021186
64 0.71554187 0.50865244
65 3.05502612 0.08463875
66 0.84920023 0.45192704
67 0.04418565 0.95693123
68 1.21656769 0.33031125
69 0.21589138 0.80888541
70 1.20812778 0.33263860
71 0.56623791 0.58211369
72 0.16352156 0.85100867
73 1.61635694 0.23901424
74 0.71520255 0.50880668
75 1.43647427 0.27587035
MATH 6170-500 -Experimental design I
Mechanical Engineering Department
Seymur Hasanov, #T00285391

76 0.68958729 0.52060886
77 1.96590531 0.18259827
78 0.37589970 0.69447824
79 1.73672200 0.21755324
80 0.96379594 0.40910170
81 0.33029991 0.72503970
82 0.10323107 0.90271078
83 0.69691208 0.51720167
84 0.70042226 0.51557811
85 1.90598609 0.19106064
86 2.58184086 0.11679514
87 3.57007502 0.06073170
88 5.29950077 0.02241568
89 0.73872750 0.49824177
90 4.51661166 0.03448677
91 1.35159345 0.29554159
92 0.36667272 0.70053905
93 1.39598424 0.28505695
94 0.56751356 0.58143562
95 1.02375085 0.38859116
96 3.31474713 0.07143007
97 0.35872465 0.70580931
98 0.55608667 0.58754264
99 0.59267967 0.56824504
100 1.62979845 0.23649889
> plot(data)

c. Calculate the mean of 100F* statistics


> Mean_F_value <-mean(F_value)
> Mean_F_value
[1] 1.231166

d. What proportion of 100F* statistics lead to the conclusion of Ho?

Fstat <- qf(0.95,2,12)


a <- F_value>Fstat
print(a)
Fstat <- rep(qf(.95,2,12),100)
Extract <- F_value[F_value>Fstat]
Extract
Prop <- (length(Extract)/length(a))*100 # percent
Prop

> Fstat <- qf(0.95,2,12)


> a <- F_value>Fstat
> print(a)
[1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[21] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
MATH 6170-500 -Experimental design I
Mechanical Engineering Department
Seymur Hasanov, #T00285391

[41] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE
[61] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[81] FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE TRUE FALSE
FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
> Fstat <- rep(qf(.95,2,12),100)
> Extract <- F_value[F_value>Fstat]
> Extract
[1] 3.965791 5.299501 4.516612
> Prop <- (length(Extract)/length(a))*100 # percent
> Prop
[1] 3

For this particular case it is 97 % accept the hypothesis (3 data out of 100 indicates
that they do not consistent with theoretical expectations. )

e.
n=100
> x1 <- c(rep(1,5),rep(2,5),rep(3,5))
>
> F_value_e <- c(rep(0,n))
> P_value_e <- c(rep(0,n))
> for (i in 1:n) {
+ y1 <- c(rnorm(5,mean=80,sd=12),rnorm(5,mean=60,sd=12),rnorm(5,m
ean=160,sd=12))
+ a1<-anova(lm(y1~factor(x1)))
+ F_value_e[i] <- a1[[4]][1]
+ P_value_e[i] <- a1[[5]][1]
+ }
> data1 <- data.frame(F_value_e,P_value_e)
> print(data1)
F_value_e P_value_e
1 135.43180 5.829416e-09
2 145.12961 3.915706e-09
3 177.28573 1.230653e-09
4 75.02040 1.649457e-07
5 214.38929 4.071595e-10
6 148.82886 3.386851e-09
7 136.80926 5.500083e-09
8 47.03143 2.097527e-06
9 70.34801 2.355706e-07
10 96.50437 4.022102e-08
11 190.25719 8.164961e-10
12 40.41674 4.665087e-06
13 89.28095 6.235498e-08
14 112.90598 1.650765e-08
15 72.43201 2.004229e-07
16 217.62569 3.730588e-10
17 192.36630 7.657732e-10
18 80.30179 1.129246e-07
19 114.69926 1.508967e-08
20 266.24950 1.145790e-10
21 343.37176 2.565552e-11
22 114.49014 1.524749e-08
MATH 6170-500 -Experimental design I
Mechanical Engineering Department
Seymur Hasanov, #T00285391

23 88.14240 6.701868e-08
24 63.70302 4.068161e-07
25 151.75398 3.027091e-09
26 108.23029 2.100002e-08
27 79.95308 1.157015e-07
28 48.62812 1.755536e-06
29 63.75239 4.050913e-07
30 109.49680 1.965567e-08
31 57.17795 7.336931e-07
32 78.77151 1.257210e-07
33 48.28844 1.822483e-06
34 67.62396 2.929492e-07
35 73.59833 1.834356e-07
36 89.49130 6.153535e-08
37 84.21578 8.653912e-08
38 80.64847 1.102407e-07
39 241.88480 2.010982e-10
40 90.58133 5.748418e-08
41 135.55578 5.798850e-09
42 76.35996 1.494895e-07
43 72.38781 2.011019e-07
44 84.11829 8.710235e-08
45 50.55501 1.425873e-06
46 96.74309 3.966356e-08
47 182.92896 1.025926e-09
48 94.65836 4.485475e-08
49 76.79022 1.448883e-07
50 91.09177 5.569458e-08
51 145.16363 3.910422e-09
52 162.49713 2.038696e-09
53 115.54638 1.446956e-08
54 80.33384 1.126733e-07
55 63.82373 4.026144e-07
56 116.58433 1.374984e-08
57 142.75063 4.306799e-09
58 55.70426 8.453111e-07
59 350.04247 2.290323e-11
60 84.63781 8.414941e-08
61 158.24911 2.376235e-09
62 204.92921 5.297697e-10
63 121.19287 1.101871e-08
64 84.24598 8.636549e-08
65 66.96168 3.092704e-07
66 90.72989 5.695649e-08
67 101.71904 2.986433e-08
68 135.09138 5.914316e-09
69 117.56250 1.310954e-08
70 92.99441 4.957279e-08
71 204.78873 5.318916e-10
72 336.53634 2.888468e-11
73 337.06533 2.861848e-11
74 123.19812 1.003160e-08
75 108.09370 2.115132e-08
76 105.81139 2.387763e-08
77 56.18778 8.066356e-07
78 100.36510 3.221905e-08
79 81.37461 1.048567e-07
MATH 6170-500 -Experimental design I
Mechanical Engineering Department
Seymur Hasanov, #T00285391

80 99.07570 3.466521e-08
81 201.77110 5.799581e-10
82 79.39126 1.203447e-07
83 86.44142 7.476662e-08
84 155.79511 2.600849e-09
85 117.85519 1.292475e-08
86 75.78465 1.559109e-07
87 365.85465 1.764689e-11
88 356.05100 2.071519e-11
89 264.84653 1.181865e-10
90 80.09548 1.145580e-07
91 48.42048 1.796111e-06
92 206.54680 5.060344e-10
93 213.11847 4.215350e-10
94 52.79221 1.129767e-06
95 64.85834 3.686053e-07
96 128.89948 7.741869e-09
97 94.40240 4.554523e-08
98 145.67691 3.831693e-09
99 55.36696 8.735742e-07
100 132.32211 6.661282e-09
> plot(data1)
>
> par(mfrow=c(1,2))
> plot(data,col="blue")
> plot(data1,col="red")
>
> Mean_F_value_e<-mean(F_value_e)
> Mean_F_value_e

[1] 126.3785

Comparison of two test options d and e.


MATH 6170-500 -Experimental design I
Mechanical Engineering Department
Seymur Hasanov, #T00285391

As we can see from the results that there is a huge difference between 1st and 2nd
performed test.

f.
> Fstat1 <- rep(qf(.95,2,12),100)
> Extract1 <- F_value_e[F_value_e>Fstat1]
> Extract1
[1] 135.43180 145.12961 177.28573 75.02040 214.38929 148.82886
[7] 136.80926 47.03143 70.34801 96.50437 190.25719 40.41674
[13] 89.28095 112.90598 72.43201 217.62569 192.36630 80.30179
[19] 114.69926 266.24950 343.37176 114.49014 88.14240 63.70302
[25] 151.75398 108.23029 79.95308 48.62812 63.75239 109.49680
[31] 57.17795 78.77151 48.28844 67.62396 73.59833 89.49130
[37] 84.21578 80.64847 241.88480 90.58133 135.55578 76.35996
[43] 72.38781 84.11829 50.55501 96.74309 182.92896 94.65836
[49] 76.79022 91.09177 145.16363 162.49713 115.54638 80.33384
[55] 63.82373 116.58433 142.75063 55.70426 350.04247 84.63781
[61] 158.24911 204.92921 121.19287 84.24598 66.96168 90.72989
[67] 101.71904 135.09138 117.56250 92.99441 204.78873 336.53634
[73] 337.06533 123.19812 108.09370 105.81139 56.18778 100.36510
[79] 81.37461 99.07570 201.77110 79.39126 86.44142 155.79511
[85] 117.85519 75.78465 365.85465 356.05100 264.84653 80.09548
[91] 48.42048 206.54680 213.11847 52.79221 64.85834 128.89948
[97] 94.40240 145.67691 55.36696 132.32211
> Propf <- (length(Extract1)/length(af))*100 # percent
> Propf
[1] 100

As we can see that 100 % of the repeated 100F* tests lead to conclusion of Ha
means we reject the hypothesis. It means test does not have a staisfactory power
with the given mean levels.

You might also like