title: One-way ANOVA for stratified samples in R
body: <p>I have a stratified sample with three groups ("a","b","c") that where drawn from a larger population N. All groups have 30 observations but their proportions in N are unequal, hence their sampling weights differ. </p>
  
  <p>I use the <code>survey</code> package in R to calculate summary statistics and linear regression models and would like to know how to calculate a one-way ANOVA correcting for the survey design (if necessary). </p>
  
  <p>My assumption is and please correct me if I'm wrong, that the standard error for the variance should be normally higher for a population where the weight is smaller, hence a simple ANOVA that does not account for the survey design should not be reliable. </p>
  
  <p>Here is an example. Any help would be appreciated. </p>
  
  <pre><code>## Oneway- ANOVA tests in R for surveys with stratified sampling-design
  library("survey")
  # create test data
  test.df&lt;-data.frame(
    id=1:90,
    variable=c(rnorm(n = 30,mean=150,sd=10),
               rnorm(n = 30,mean=150,sd=10),
               rnorm(n = 30,mean=140,sd=10)),
    groups=c(rep("a",30),
    rep("b",30),
    rep("c",30)),
    weights=c(rep(1,30), # undersampled
    rep(1,30),
    rep(100,30))) # oversampled
  
  
  # correct for survey design
  test.df.survey&lt;-svydesign(id=~id,
                             strata=~groups,
                             weights=~weights,
                             data=test.df)
  
  ## descriptive statistics
  # boxplot
  svyboxplot(~variable~groups,test.df.survey)
  # means
  svyby(~variable,~groups,test.df.survey,svymean)
  # variances
  svyby(~variable,~groups,test.df.survey,svyvar)
  
  
  ### ANOVA ###
  ## One-way ANOVA without correcting for survey design
  summary(aov(formula = variable~groups,data = test.df))
  </code></pre>