R regression analysis: analyzing data for a certain ethnicity
Asked Answered
N

1

3

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?

Nasser answered 18/7, 2018 at 17:37 Comment(0)
P
2

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.

Pronty answered 18/7, 2018 at 17:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.