0

I want to fit a glm in R. The predictors I am using are let's say 4 variables: Age, Sex, HIV But I want to fit the glm in a way that it only uses those rows of HIV which are equal to 0 and those rows of DM which are equal to 1!

Age<-c(21,20,12,34,19)
Sex<-c(1,1,1,0,1,0)
HIV<c(0,1,1,0,0,0)
DM<-c(1,1,1,1,0,0)
Y<-c(1,1,0,0,1,1)
data<-data.frame(Age,Sex,HIV,DM,Y)

model<-glm(Y~Age+Sex+???????+?????) Should I be writing Y~Age+Sex+(data$HIV==0)+(data$DM==1), or it means that I am setting everyone to 0 and then 1?

P.S: I edited the question after Akrun answered, the initial version just had HIV, Age and Sex

Aura
  • 49
  • 7
  • Try `glm(Y ~ Age + Sex + HIV, data = subset(data, HIV == 0))` – akrun May 10 '21 at 20:21
  • @akrun this was a small example but in reality, I have several variables each with different amount of 0 and 1, for some I need 1s, for some I need 0s, and the number of these 0s and 1s are not the same, so practically I do not think I can subsetting the data, Or I can? – Aura May 10 '21 at 20:25
  • You can combine conditions with `&`, e,g., `subset(data, HIV == 0 & DM == 1)` – Gregor Thomas May 10 '21 at 20:38
  • @GregorThomas Thanks!! – Aura May 10 '21 at 20:50

0 Answers0