留学生R代码代编程讲解、R程序设计辅导
辅导留学生 Statistics统计、回归、迭代|讲解R语言
The model equation is
Xij = μ + αi + βj + ?ij
Let’s consider the following example:
Factor A = amount of a medication
Factor B = the age of a patient
The object of this experiment is to compare one factor ANOVA with two factor (blocked) ANOVA.
If we use one factor ANOVA here, it might be difficult to catch the treatment effect. (i.e. it might be hard to distinguish what is actually an effect from the medication from effects of a person’s age).
In this case, βj gets shoved into ?ij, increasing the error and increasing the variance of ?ij.
If we use blocked ANOVA instead, however, there will be a large cost to degrees fo freedom for the SSE.
For our experiment, we need to choose αi and βj (i= 1,…, i, and j = 1,..., j) for two different cases:
1) A case where blocking works and increases power (as compared to one-factor ANOVA)
2) A case where blocking doesn’t work and power is decreased.
In each case, μij = μ + αi + βj should be the same.
We can set μ = 0, but we must remember that ∑_(i=0)^I?αi = ∑_(j=0)^j?βj = 0.
Power is the P(rejecting H0 correctly| Ha is correct); i.e., correctly rejecting H0.
To calculate it, we’ll need to calculate (# of rejections of H0 / # of times we repeat the experiment).
So, to calculate power properly, we’ll need to repeat the experiment many times.
For the experiment, we’ll need to create an IxJ data frame of iid N(0, σ2) errors, then create a matrix where the entries are μ + αi + βj. Adding the original data frame to this matrix will give us our simulated observations Xij.
We will then apply ANOVA both for the one factor and two factor blocking case. We will need to determine whether H0 is rejected for all cases, and then count the rejections. We’ll need to simulate the experiment a bunch of times and find the power (using the # of rejections) of each experiment.
We will be fiddling with σ, αi, and βj until we get a configuration so that the highlighted conditions hold (so two separate experiments).
We will also need to do this for multiple values of i, so it will be useful to develop an intuition about the parameters so that we can determine whether to use one factor or blocked ANOVA.