Homework 5
Solutions:
Exercise 26a(i)
Let's suppose you already downloaded the data and have
them stored in three variables. Mine are x1,x2 and x3 for percentage
removed, duration of the removal and code of the bee respectively.
I first created two variables to store the data when we deal with one
kind of bees and another for the other (du1 and du2)
In them I store the data to plot in the boxplot.
motif()
x1_x[,1]
x2_x[,2]
x3_x[,3]
du1_rep(NA,length(x3))
du2_rep(NA,length(x3))
li_0;lo_0
for (a in 1:length(x3)){if (x3[a]==1){li_li+1;du1[a]_x1[a]}
else{lo_lo+1;du2[a]_x1[a]}}
boxplot(du1,du2)
Exercise 26a(ii)
The second boxplot requires to transform previously the variables
x4_log(x1/(1-x1))
for (a in 1:length(x3)){if (x3[a]==1){du1[a]_x4[a]}
else{du2[a]_x4[a]}}
boxplot(du1,du2)
Exercise 26a(iii)
I will use the codes from the previous hw to solve this. You can see
that once you create them you just need to tell the program which the
new dataset is.
#Given that the data is in order, we just have to do this
m1_mean(du1[1:li])
m2_mean(du2[li+1:lo])
s1_sqrt(var(du1[1:li]))
s2_sqrt(var(du2[li+1:lo]))
n1_li
n2_lo
sp_sqrt((((n1-1)*var(du1[1:li]))+((n2-1)*var(du2[li+1:lo])))/(n1+n2-2))
sey2y1_sp*sqrt((1/n1)+(1/n2))
qt(0.975,n1+n2-2)
ica_m2-m1-qt(0.975,n1+n2-2)*sey2y1
icb_m2-m1+qt(0.975,n1+n2-2)*sey2y1
t_((m2-m1)-0)/sey2y1
pvalue_1-pt(abs(t),n1+n2-2)
These are the solutions:
Mean 1 |
Mean 2 |
S.d. 1 |
S.d. 2 |
pooled |
s.e. |
d.freedom |
t(97.5) |
Interval |
t stat. |
p-value |
-.38 |
0.76 |
0.90 |
0.84 |
0.89 |
0.29 |
45 |
2.014 |
[0.54,1.74] |
3.84 |
0.0001 |
Exercise 26b(i)
du1_rep(NA,length(x3))
du2_rep(NA,length(x3))
li_0;lo_0
for (a in 1:length(x3)){if (x3[a]==1){li_li+1;du1[a]_x2[a]}
else{lo_lo+1;du2[a]_x2[a]}}
boxplot(du1,du2)
Exercise 26b(ii)
x5_log(x2)
for (a in 1:length(x3)){if (x3[a]==1){du1[a]_x5[a]}else{du2[a]_x5[a]}}
boxplot(du1,du2)
Exercise 26b(iii)
x6_log(x2/1-x2)
for (a in 1:length(x3)){if (x3[a]==1){du1[a]_x6[a]}else{du2[a]_x6[a]}}
boxplot(du1,du2)
Exercise 26b(iv)
It seems to be the ++++++++++++ one
Exercise 26b(v)
These are the solutions:
Confidence interval |
p-value |
[0.18,1.11] |
0.0036 |
Exercise 26b(vi)
The answer is ===================
Exercise 26b(vii)
The answer is ===================