Georg Ehret
2010-Apr-04 22:01 UTC
[R] calculating an interaction statistic from stratified data
Dear R community, I have data on beta&standard error (for the main effect of variable x), stratified by sex for my dataset. I wish to calculate the sex-interaction effect (as beta&se) from these two stratified datasets. Is there a package to do this? If not, any advice how to do it manually? Thank you very much and best regards, Georg. ************************ Georg Ehret, JHU, Baltimore [[alternative HTML version deleted]]
Alvarez, Joann Marie
2010-Apr-04 22:12 UTC
[R] calculating an interaction statistic from stratified data
Hi Georg, Instead of stratifying by sex, use all your data together to fit one model that controls for sex. This gives you more power because of the increased sample size. Also, this way you can add an interaction term, which is what you are looking for. The gender variable should be defined as a factor. Here's an example: dataframe$sex <- factor(dataframe$sex) awesomemodel <- lm(outcomevariable ~ sex + x + sex*x, data = dataframe) Hope this helps, JoAnn ________________________________________ From: r-help-bounces at r-project.org [r-help-bounces at r-project.org] On Behalf Of Georg Ehret [georgehret at gmail.com] Sent: Sunday, April 04, 2010 5:01 PM To: r-help Subject: [R] calculating an interaction statistic from stratified data Dear R community, I have data on beta&standard error (for the main effect of variable x), stratified by sex for my dataset. I wish to calculate the sex-interaction effect (as beta&se) from these two stratified datasets. Is there a package to do this? If not, any advice how to do it manually? Thank you very much and best regards, Georg. ************************ Georg Ehret, JHU, Baltimore [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org 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.
(Ted Harding)
2010-Apr-04 22:26 UTC
[R] calculating an interaction statistic from stratified dat
On 04-Apr-10 22:01:08, Georg Ehret wrote:> Dear R community, > I have data on beta&standard error (for the main effect of > variable x), stratified by sex for my dataset. I wish to > calculate the sex-interaction effect (as beta&se) from these > two stratified datasets. Is there a package to do this? > If not, any advice how to do it manually? > Thank you very much and best regards, Georg. > ************************ > Georg Ehret, JHU, BaltimoreIf you have the full original data, then you should simply be able to write a [generalised] linear model with sex-interaction. For example (e.g. binary outcome and logistic regression, with two independent variables X1 and X2, therefore a beta for each of X1 and X2, and also Sex as a factor) summary(glm(Y ~ X1*Sex + X2*Sex, family=binomial)$coef should give you what However, if (as your wording suggests) all you have is the beta & SE results by Sex, i.e. you have betaM, SE.betaM ; betaF, SE.betaF then it should be straightforward. The interaction is the difference between the two betas: beta:Sex = betaM - betaF and (reasoning that Sex differentiates individuals, so the results for the Sex=M individuals should be independent of the results for the Sex=F individuals -- unless the two sexes have some influence on each other ... ), the variance of beta:Sex = betaM - betaF will be the sum of the variances of betaM and betaF: SE(beta:Sex) = sqrt(SE.betaM^2 + SE.betaF^2) However, if the two sexes do have an influence on each other (e.g. your original data are on incidence of a sexually transmitted disease, and you cannot exclude that some of the Ms were in contact with some of the Fs), then the above will not be valid, since the Ys for the Ms could be correlated with the Ys for the Fs. But in that case you should perhaps be thinking of a more elaborate model (and you would certianly need the full original data -- just the beta's and SE's from the two sexes will not be sufficient). Hoping this helps, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 04-Apr-10 Time: 23:26:37 ------------------------------ XFMail ------------------------------