Dawn Ashcourt
2007-Jan-16 09:30 UTC
[R] Gaussian glm for grouped data with unequal variances
Hello - I am fairly new to R, (i.e., ability to create functions/write programs insignificant) and was wondering if there might be a convenient way to model the following: I want to fit a gaussian glm to grouped data, while allowing for unequal variances in each of the groups. More specifically, my data set looks something like this: ---------------- data group 1 76 1 2 82 1 3 83 1 4 54 1 5 35 1 6 46 1 7 87 1 8 68 1 9 87 2 10 95 2 11 98 2 12 100 2 13 109 2 14 109 2 15 100 2 16 81 2 17 75 2 18 68 2 19 67 2 20 105 3 .... et cetera. --------------- There are seven groups in all, each with a different number of observations. The idea is to compare a model in which all the data points can be modeled with a single mean (i.e., if all the group means are equal), or if the data suggests that each of the groups has a different mean. In other words, I want to do a Likelihood ratio test on whether or not the group means are significantly different from each other: the full model would be glm(data ~ as.factor(group)-1, family = gaussian), to be compared against a restricted model that only includes an intercept. However, I also need to allow for the fact that each group has a different variance. And this I have no idea how to do. I would really appreciate some help in this matter. Thank you in advance, Dawn. [[alternative HTML version deleted]]
Chuck Cleland
2007-Jan-16 11:51 UTC
[R] Gaussian glm for grouped data with unequal variances
Dawn Ashcourt wrote:> Hello - I am fairly new to R, (i.e., ability to create functions/write > programs insignificant) and was wondering if there might be a convenient way > to model the following: I want to fit a gaussian glm to grouped data, while > allowing for unequal variances in each of the groups. > More specifically, my data set looks something like this: > ---------------- > data group > 1 76 1 > 2 82 1 > 3 83 1 > 4 54 1 > 5 35 1 > 6 46 1 > 7 87 1 > 8 68 1 > 9 87 2 > 10 95 2 > 11 98 2 > 12 100 2 > 13 109 2 > 14 109 2 > 15 100 2 > 16 81 2 > 17 75 2 > 18 68 2 > 19 67 2 > 20 105 3 > .... et cetera. > --------------- > There are seven groups in all, each with a different number of observations. > The idea is to compare a model in which all the data points can be modeled > with a single mean (i.e., if all the group means are equal), or if the data > suggests that each of the groups has a different mean. In other words, I > want to do a Likelihood ratio test on whether or not the group means are > significantly different from each other: the full model would be glm(data ~ > as.factor(group)-1, family = gaussian), to be compared against a restricted > model that only includes an intercept. However, I also need to allow for the > fact that each group has a different variance. And this I have no idea how > to do. I would really appreciate some help in this matter.Have you considered oneway.test()? For example: ## Not assuming equal variances oneway.test(breaks ~ tension, data = warpbreaks) One-way analysis of means (not assuming equal variances) data: breaks and tension F = 5.8018, num df = 2.00, denom df = 32.32, p-value = 0.007032> Thank you in advance, > Dawn. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894
Thilo Kellermann
2007-Jan-16 12:16 UTC
[R] Gaussian glm for grouped data with unequal variances
Hi, I would suggest to use lme for doing that: library(nlme) vf1Ident <- varIdent( c(m = 0.5), form = ~ 1 | group ) fm.lme <- lme(data ~ group, weights = vf1Ident. data = DATA) anova(fm.lme) Hope this helps, Thilo On Tuesday 16 January 2007 10:30, Dawn Ashcourt wrote:> Hello - I am fairly new to R, (i.e., ability to create functions/write > programs insignificant) and was wondering if there might be a convenient > way to model the following: I want to fit a gaussian glm to grouped data, > while allowing for unequal variances in each of the groups. > More specifically, my data set looks something like this: > ---------------- > data group > 1 76 1 > 2 82 1 > 3 83 1 > 4 54 1 > 5 35 1 > 6 46 1 > 7 87 1 > 8 68 1 > 9 87 2 > 10 95 2 > 11 98 2 > 12 100 2 > 13 109 2 > 14 109 2 > 15 100 2 > 16 81 2 > 17 75 2 > 18 68 2 > 19 67 2 > 20 105 3 > .... et cetera. > --------------- > There are seven groups in all, each with a different number of > observations. The idea is to compare a model in which all the data points > can be modeled with a single mean (i.e., if all the group means are equal), > or if the data suggests that each of the groups has a different mean. In > other words, I want to do a Likelihood ratio test on whether or not the > group means are significantly different from each other: the full model > would be glm(data ~ as.factor(group)-1, family = gaussian), to be compared > against a restricted model that only includes an intercept. However, I also > need to allow for the fact that each group has a different variance. And > this I have no idea how to do. I would really appreciate some help in this > matter. > Thank you in advance, > Dawn. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html and provide commented, minimal, > self-contained, reproducible code.-- ________________________ Thilo Kellermann Department of Psychiatry und Psychotherapy RWTH Aachen University Pauwelstr. 30 52074 Aachen Tel.: +49 (0)241 / 8089977 Fax.: +49 (0)241 / 8082401 E-Mail: tkellermann at ukaachen.de
Apparently Analagous Threads
- one-way ANOVA model, with one factor, an unbalanced design and unequal variances
- help with unequal variances
- Variance functions in package nlme
- Looking for an unequal variances equivalent of the Kruskal Wallis nonparametric one way ANOVA
- lme unequal random-effects variances varIdent pdMat Pinheiro Bates nlme