Hi, I want to compare a score across 5 groups where sample sizes (all of them N<30) are very unequal. Using KW would be wrong? Is there an option for unequal variances for ANOVA in stata?
Thank you
Thank you
// Date: 15-Jun-2021
// Use equations shown in Andy Field's document to compute
// Welch's F-test.
// https://www.discoveringstatistics.com/docs/welchf.pdf
// The data AF uses come from this document:
// https://www.discoveringstatistics.com/repository/contrasts.pdf
clear
input byte group y
1 3
1 2
1 1
1 1
1 4
2 5
2 2
2 4
2 2
2 3
3 7
3 4
3 5
3 3
3 6
end
preserve
drop if missing(group)
statsby Ybar=r(mean) Var=r(Var) n=r(N), by(group) clear: summarize y
list
quietly {
generate double Wt = n/Var
generate double WtMean = Wt*Ybar
egen double SumWt = total(Wt)
egen double SumWtMean = total(WtMean)
generate double WelchGM = SumWtMean/SumWt
generate double WtSqDev = Wt*(Ybar-WelchGM)^2
egen double SSmodel = total(WtSqDev)
generate byte k = _N // # of groups
generate double MSmodel = SSmodel/(k-1)
generate double Lterm = (1-Wt/SumWt)^2 / (n-1)
egen double lambda = total(Lterm)
replace lambda = lambda*3/(k^2-1)
generate double MSerror = 1+2*lambda*(k-2)/3
generate double WelchF = MSmodel/MSerror
generate byte df1 = k-1
generate double df2 = 1/lambda
generate double p = Ftail(df1,df2,WelchF)
}
list WelchF-p in 1
display _newline ///
"From SPSS ONEWAY:" _newline ///
"Welch F = "4.320451 _newline ///
" df1 = " 2 _newline ///
" df2 = " 7.943375 _newline ///
" p = " .053738
restore
// Date: 17-Aug-2021
// Compare Welch's F-test to multilevel modeling approach
// in post #3 here:
// https://www.statalist.org/forums/forum/general-stata-discussion/general/1427959-anova-rejection-of-bartlett-test
// Note that I have added the dfmethod(anova) option.
mixed y i.group, ml residuals(independent, by(group)) ///
nolrtest nolog dfmethod(anova)
margins group
margins group, pwcompare(effects) mcompare(noadjust)
// Compare to -regress- with vce(robust)
regress y i.group, vce(robust)
Comment