R regression analysis: analyzing data for a certain ethnicity

亡梦爱人 提交于 2019-12-02 01:25:58

问题


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

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])

Any suggestions?


回答1:


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.

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



来源:https://stackoverflow.com/questions/51407989/r-regression-analysis-analyzing-data-for-a-certain-ethnicity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!