R回归分析:分析特定种族的数据 [英] R regression analysis: analyzing data for a certain ethnicity

查看:67
本文介绍了R回归分析:分析特定种族的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据集,用于调查不同种族(黑人,白人和拉丁裔)个体中的抑郁症.

I have a data set that investigate depression among individuals with different ethnicities (Black, White, and Latina).

我想知道所有种族的基线抑郁症与岗后抑郁症有何关系

I want to know how depression at baseline relates to depression at post with all ethnic groups, I did

lm(depression_base ~ depression_post, data=Data

现在,我想按族裔来看这种关系.我的数据集中的种族编码为0 = White1 = Black2 = Latina.我以为我需要使用ifelse函数,但似乎无法正常使用它.这是我尝试的White:

Now, I want to look at the relationship by ethnicity. Ethnicity in my dataset is coded as 0 = White, 1 = Black, and 2 = Latina. I am thinking that I need to use the ifelse function, but I cannot seem to get it to work. Here is what I tried for White:

lm(depression_base[ifelse, ethnicity == 0],
   depression_post[ifelse, ethnicity == 0])

有什么建议吗?

推荐答案

将您的ethnicity编码为具有正确水平的因子,然后进行一次回归:

Code your ethnicity as factors with correct levels, then do a single regression:

## recode your 0, 1, 2 from numeric to factor
Data$ethnicity <- factor(Data$ethnicity)
fit <- lm(depression_base ~ depression_post * ethnicity, data = Data)

单个模型可让您对组之间的变异性进行适当的测试.

A single model allows you decent test for variability between groups.

您可能对系数的含义感到困惑.如果是这样,请查看或CrossValidated上的其他帖子.

You might be confused about the meaning of the coefficients. If so, have a look at this or other posts on CrossValidated.

这篇关于R回归分析:分析特定种族的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆