【问题标题】:R regression analysis: analyzing data for a certain ethnicityR回归分析:分析某个种族的数据
【发布时间】:2018-12-26 17:25:52
【问题描述】:

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

我想知道所有种族的基线抑郁症与岗位抑郁症的关系,我做了

lm(depression_base ~ depression_post, data=Data

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

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

有什么建议吗?

【问题讨论】:

    标签: r regression linear-regression lm


    【解决方案1】:

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

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

    单个模型允许您对组间的可变性进行适当的测试。

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

    【讨论】:

      猜你喜欢
      • 2018-01-06
      • 2023-03-15
      • 2018-07-26
      • 1970-01-01
      • 1970-01-01
      • 2019-08-17
      • 2012-05-23
      • 2012-09-16
      • 1970-01-01
      相关资源
      最近更新 更多