

I have done some ANOVA tables for some data that I have, from this I can read the withingroup variance. can anyone tell me how i may find out the betweengroup variance?
Thanks Emma


can anyone advise me please?
emj83 wrote
I have done some ANOVA tables for some data that I have, from this I can read the withingroup variance. can anyone tell me how i may find out the betweengroup variance?
Thanks Emma


Hi Emma,
>>
R gives you the tools to work this out.
## Example
set.seed(7)
TDat < data.frame(response = c(rnorm(100, 5, 2), rnorm(100, 20, 2)))
TDat$group < gl(2, 100, labels=c("A","B"))
with(TDat, boxplot(split(response, group)))
summary(aov(response ~ group, data=TDat))
Regards, Mark.
emj83 wrote
can anyone advise me please?
emj83 wrote
I have done some ANOVA tables for some data that I have, from this I can read the withingroup variance. can anyone tell me how i may find out the betweengroup variance?
Thanks Emma
Mark Difford (Ph.D.)
Research Associate
Botany Department
Nelson Mandela Metropolitan University
Port Elizabeth, South Africa


I have done this in R and this is the following ANOVA table I get:
> summary(aov(response ~ group, data=TDat))
Df Sum Sq Mean Sq F value Pr(>F)
group 1 11203.5 11203.5 2505.0 < 2.2e16 ***
Residuals 198 885.5 4.5
The model is response(i,j)= group(i)+ error(i,j),
we assume that group~N(0,P^2) and error~N(0,sigma^2)
I know that sigma^2 is equal to 4.5, how do I find out P^2?
In the problem that I am trying to apply this to, I have more than 2 groups. I was hoping there would be a function that helps you do this that I don't know about.
Thanks for your help Emma
Mark Difford wrote
Hi Emma,
>>
R gives you the tools to work this out.
## Example
set.seed(7)
TDat < data.frame(response = c(rnorm(100, 5, 2), rnorm(100, 20, 2)))
TDat$group < gl(2, 100, labels=c("A","B"))
with(TDat, boxplot(split(response, group)))
summary(aov(response ~ group, data=TDat))
Regards, Mark.
emj83 wrote
can anyone advise me please?
emj83 wrote
I have done some ANOVA tables for some data that I have, from this I can read the withingroup variance. can anyone tell me how i may find out the betweengroup variance?
Thanks Emma


Hi Emma,
>> ...from this I can read the withingroup variance. can anyone tell me how i may find
>> out the betweengroup variance?
But it's in the table, above the "withingroup" variance. Remember that F is the ratio of these two quantities, i.e. the mean of the group variances divided by the mean of the withingroup variances . I will work with my example since you never set seed so your answers are different from mine (which really does not help matters).
set.seed(7)
TDat < data.frame(response = c(rnorm(100, 5, 2), rnorm(100, 20, 2)))
TDat$group < gl(2, 100, labels=c("A","B"))
summary(aov(response ~ group, data=TDat))
11225.25/3.64
[1] 3083.86
There is some rounding error on the mean squares (i.e. mean variances) but F is correct. Using estimates calculated by a different route we have:
11225.249057/3.639801
[1] 3084.028
Does this answer your question?
Regards, Mark.
emj83 wrote
I have done this in R and this is the following ANOVA table I get:
> summary(aov(response ~ group, data=TDat))
Df Sum Sq Mean Sq F value Pr(>F)
group 1 11203.5 11203.5 2505.0 < 2.2e16 ***
Residuals 198 885.5 4.5
The model is response(i,j)= group(i)+ error(i,j),
we assume that group~N(0,P^2) and error~N(0,sigma^2)
I know that sigma^2 is equal to 4.5, how do I find out P^2?
In the problem that I am trying to apply this to, I have more than 2 groups. I was hoping there would be a function that helps you do this that I don't know about.
Thanks for your help Emma
Mark Difford wrote
Hi Emma,
>>
R gives you the tools to work this out.
## Example
set.seed(7)
TDat < data.frame(response = c(rnorm(100, 5, 2), rnorm(100, 20, 2)))
TDat$group < gl(2, 100, labels=c("A","B"))
with(TDat, boxplot(split(response, group)))
summary(aov(response ~ group, data=TDat))
Regards, Mark.
emj83 wrote
can anyone advise me please?
emj83 wrote
I have done some ANOVA tables for some data that I have, from this I can read the withingroup variance. can anyone tell me how i may find out the betweengroup variance?
Thanks Emma
Mark Difford (Ph.D.)
Research Associate
Botany Department
Nelson Mandela Metropolitan University
Port Elizabeth, South Africa


Hi Emma,
...
I forgot to add the tabular ouput, which doesn't help either:
T.sum < summary(aov(response ~ group, data=TDat))
print(T.sum)
Df Sum Sq Mean Sq F value Pr(>F)
group 1 11225.2 11225.2 3084 < 2.2e16 ***
Residuals 198 720.7 3.6

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
unlist(T.sum)
unlist(T.sum)[5]/unlist(T.sum)[6]
Mean Sq1
3084.028
Regards, Mark.
Mark Difford wrote
Hi Emma,
>> ...from this I can read the withingroup variance. can anyone tell me how i may find
>> out the betweengroup variance?
But it's in the table, above the "withingroup" variance. Remember that F is the ratio of these two quantities, i.e. the mean of the group variances divided by the mean of the withingroup variances . I will work with my example since you never set seed so your answers are different from mine (which really does not help matters).
set.seed(7)
TDat < data.frame(response = c(rnorm(100, 5, 2), rnorm(100, 20, 2)))
TDat$group < gl(2, 100, labels=c("A","B"))
summary(aov(response ~ group, data=TDat))
11225.25/3.64
[1] 3083.86
There is some rounding error on the mean squares (i.e. mean variances) but F is correct. Using estimates calculated by a different route we have:
11225.249057/3.639801
[1] 3084.028
Does this answer your question?
Regards, Mark.
emj83 wrote
I have done this in R and this is the following ANOVA table I get:
> summary(aov(response ~ group, data=TDat))
Df Sum Sq Mean Sq F value Pr(>F)
group 1 11203.5 11203.5 2505.0 < 2.2e16 ***
Residuals 198 885.5 4.5
The model is response(i,j)= group(i)+ error(i,j),
we assume that group~N(0,P^2) and error~N(0,sigma^2)
I know that sigma^2 is equal to 4.5, how do I find out P^2?
In the problem that I am trying to apply this to, I have more than 2 groups. I was hoping there would be a function that helps you do this that I don't know about.
Thanks for your help Emma
Mark Difford wrote
Hi Emma,
>>
R gives you the tools to work this out.
## Example
set.seed(7)
TDat < data.frame(response = c(rnorm(100, 5, 2), rnorm(100, 20, 2)))
TDat$group < gl(2, 100, labels=c("A","B"))
with(TDat, boxplot(split(response, group)))
summary(aov(response ~ group, data=TDat))
Regards, Mark.
emj83 wrote
can anyone advise me please?
emj83 wrote
I have done some ANOVA tables for some data that I have, from this I can read the withingroup variance. can anyone tell me how i may find out the betweengroup variance?
Thanks Emma
Mark Difford (Ph.D.)
Research Associate
Botany Department
Nelson Mandela Metropolitan University
Port Elizabeth, South Africa


I'm trying also to understand how to get the betweengroup variance out of a oneway ANOVA, but I'm beginning to think that in a sense, the variance does not exist. Emma said:
The model is response(i,j)= group(i)+ error(i,j)
Yes, if by group(i) you mean intercept + coefficient[i].
we assume that group~N(0,P^2) and error~N(0,sigma^2)
Only the error is assumed to be a random variable. Group is a fixed effect, not a random variable, and therefore it has no variance associated with it. The model does not predict a variance for it. One could compute the variance of the coefficients and call this a group variance, but it seems to me that isn't the right way to think about it.
I'm trying to calculate a heritability value for a trait in an organism, defined as Vg/Vp, where Vg = variance due to genotype and Vp = total variance. The model is p~g, or p[i,j] = intercept + g_coefficient[i] + error[i,j]. But to get Vg, I think it is actually necessary to use a different model, where g is modelled as a random variable (a random effect), so the model can estimate a variance associated with it.
If anyone can add something to this, please do.
ted


There is nothing about R in your question, hence it is not appropriate
for this list. Please consult with a local statistician, or post on a
stats help list such as http://stats.stackexchange.com/On Tue, Jul 24, 2012 at 8:55 PM, tedtoal < [hidden email]> wrote:
> I'm trying also to understand how to get the betweengroup variance out of a
> oneway ANOVA, but I'm beginning to think that in a sense, the variance does
> not exist. Emma said:
>
> *The model is response(i,j)= group(i)+ error(i,j)*
>
> Yes, if by group(i) you mean intercept + coefficient[i].
>
> *we assume that group~N(0,P^2) and error~N(0,sigma^2) *
>
> Only the error is assumed to be a random variable. Group is a fixed effect,
> not a random variable, and therefore it has no variance associated with it.
> The model does not predict a variance for it. One could compute the
> variance of the coefficients and call this a group variance, but it seems to
> me that isn't the right way to think about it.
>
> I'm trying to calculate a heritability value for a trait in an organism,
> defined as Vg/Vp, where Vg = variance due to genotype and Vp = total
> variance. The model is p~g, or p[i,j] = intercept + g_coefficient[i] +
> error[i,j]. But to get Vg, I think it is actually necessary to use a
> different model, where g is modelled as a random variable (a random effect),
> so the model can estimate a variance associated with it.
>
> If anyone can add something to this, please do.
> ted
>
>
>
>
> 
> View this message in context: http://r.789695.n4.nabble.com/BetweengroupvariancefromANOVAtp901535p4637686.html> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/rhelp> PLEASE do read the posting guide http://www.Rproject.org/postingguide.html> and provide commented, minimal, selfcontained, reproducible code.
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


Hi,
From the ANOVA results, you could get MSE and MS of group. MSE is basically sigma^2 error. MS group of MS between group contains sigma^2 error+replication*sigma^2group (please check the formula. It can be slightly different when the model complexity increases).
Once, you get sigma^2 group, I guess you know how to calculate Vg and Vp.
Once, you have all the values, except sigma^2 group, you can subtract and divide it by replication to get sigma^2 group. In SAS, proc glm also shows the output with formula.
A.K.
 Original Message 
From: Ista Zahn < [hidden email]>
To: tedtoal < [hidden email]>
Cc: [hidden email]
Sent: Wednesday, July 25, 2012 6:21 AM
Subject: Re: [R] Betweengroup variance from ANOVA
There is nothing about R in your question, hence it is not appropriate
for this list. Please consult with a local statistician, or post on a
stats help list such as http://stats.stackexchange.com/On Tue, Jul 24, 2012 at 8:55 PM, tedtoal < [hidden email]> wrote:
> I'm trying also to understand how to get the betweengroup variance out of a
> oneway ANOVA, but I'm beginning to think that in a sense, the variance does
> not exist. Emma said:
>
> *The model is response(i,j)= group(i)+ error(i,j)*
>
> Yes, if by group(i) you mean intercept + coefficient[i].
>
> *we assume that group~N(0,P^2) and error~N(0,sigma^2) *
>
> Only the error is assumed to be a random variable. Group is a fixed effect,
> not a random variable, and therefore it has no variance associated with it.
> The model does not predict a variance for it. One could compute the
> variance of the coefficients and call this a group variance, but it seems to
> me that isn't the right way to think about it.
>
> I'm trying to calculate a heritability value for a trait in an organism,
> defined as Vg/Vp, where Vg = variance due to genotype and Vp = total
> variance. The model is p~g, or p[i,j] = intercept + g_coefficient[i] +
> error[i,j]. But to get Vg, I think it is actually necessary to use a
> different model, where g is modelled as a random variable (a random effect),
> so the model can estimate a variance associated with it.
>
> If anyone can add something to this, please do.
> ted
>
>
>
>
> 
> View this message in context: http://r.789695.n4.nabble.com/BetweengroupvariancefromANOVAtp901535p4637686.html> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/rhelp> PLEASE do read the posting guide http://www.Rproject.org/postingguide.html> and provide commented, minimal, selfcontained, reproducible code.
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


> > I'm trying also to understand how to get the betweengroup variance
> > out of a oneway ANOVA, but I'm beginning to think that in a sense,
> > the variance does not exist. Emma said:
> >
> > *The model is response(i,j)= group(i)+ error(i,j)*
> >
> > Yes, if by group(i) you mean intercept + coefficient[i].
> >
> > *we assume that group~N(0,P^2) and error~N(0,sigma^2) *
> >
> > Only the error is assumed to be a random variable. Group
> is a fixed
> > effect, not a random variable, and therefore it has no
> variance associated with it.
> > The model does not predict a variance for it. One could
> compute the
> > variance of the coefficients and call this a group variance, but it
> > seems to me that isn't the right way to think about it.
The classical calculations in a one way anova table make no assumptions about the origin or distribution of the betweengroup differences. Nor does the F test commonly applied (because the F test assumes the null hypothesis, which is that there is no group effect  so we don't need to make assumptions about it to calculate a pvalue).
For one way anova you are therefore free to think of the between group effects, if hypothesised to be present, as fixed or random. If the experiment tests controlled changes it usually makes more sense to think of them as fixed, and one tends to worry about the size of individual effects; If you're thinking of them as drawn randomly from a larger population of possible effects (ie random) it is usually sensible to calculate a variance.
The classical calcuilations of the betweengroup variance are given in practically every textbook on the topic. For a slightly more modern take on it you'd probably go for REML solutions which you can get from lme in the nlme package, among others. To do that, assuming data y with a grouping factor g, you would do something like
library(nlme)
l < lme(y~1, random=~1g)
summary(l) #for the whole picture
VarCorr(l) #for just variances
... and that will give you estimates of within and betweengroup variance components
S Ellison
*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


On Jul 25, 2012, at 14:56 , arun wrote:
> Hi,
>
> From the ANOVA results, you could get MSE and MS of group. MSE is basically sigma^2 error. MS group of MS between group contains sigma^2 error+replication*sigma^2group (please check the formula. It can be slightly different when the model complexity increases).
>
>
> Once, you get sigma^2 group, I guess you know how to calculate Vg and Vp.
>
>
> Once, you have all the values, except sigma^2 group, you can subtract and divide it by replication to get sigma^2 group. In SAS, proc glm also shows the output with formula.
>
> A.K.
>
Beware, though, that this works for balanced designs only (identical group sizes). For unequal replication, you need to go the lme/lmer route.
pd
>
>
>
>  Original Message 
> From: Ista Zahn < [hidden email]>
> To: tedtoal < [hidden email]>
> Cc: [hidden email]
> Sent: Wednesday, July 25, 2012 6:21 AM
> Subject: Re: [R] Betweengroup variance from ANOVA
>
> There is nothing about R in your question, hence it is not appropriate
> for this list. Please consult with a local statistician, or post on a
> stats help list such as http://stats.stackexchange.com/>
> On Tue, Jul 24, 2012 at 8:55 PM, tedtoal < [hidden email]> wrote:
>> I'm trying also to understand how to get the betweengroup variance out of a
>> oneway ANOVA, but I'm beginning to think that in a sense, the variance does
>> not exist. Emma said:
>>
>> *The model is response(i,j)= group(i)+ error(i,j)*
>>
>> Yes, if by group(i) you mean intercept + coefficient[i].
>>
>> *we assume that group~N(0,P^2) and error~N(0,sigma^2) *
>>
>> Only the error is assumed to be a random variable. Group is a fixed effect,
>> not a random variable, and therefore it has no variance associated with it.
>> The model does not predict a variance for it. One could compute the
>> variance of the coefficients and call this a group variance, but it seems to
>> me that isn't the right way to think about it.
>>
>> I'm trying to calculate a heritability value for a trait in an organism,
>> defined as Vg/Vp, where Vg = variance due to genotype and Vp = total
>> variance. The model is p~g, or p[i,j] = intercept + g_coefficient[i] +
>> error[i,j]. But to get Vg, I think it is actually necessary to use a
>> different model, where g is modelled as a random variable (a random effect),
>> so the model can estimate a variance associated with it.
>>
>> If anyone can add something to this, please do.
>> ted
>>
>>
>>
>>
>> 
>> View this message in context: http://r.789695.n4.nabble.com/BetweengroupvariancefromANOVAtp901535p4637686.html>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/rhelp>> PLEASE do read the posting guide http://www.Rproject.org/postingguide.html>> and provide commented, minimal, selfcontained, reproducible code.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/rhelp> PLEASE do read the posting guide http://www.Rproject.org/postingguide.html> and provide commented, minimal, selfcontained, reproducible code.
>
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/rhelp> PLEASE do read the posting guide http://www.Rproject.org/postingguide.html> and provide commented, minimal, selfcontained, reproducible code.

Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: [hidden email] Priv: [hidden email]
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.

