1
votes

I have data with several outcome variables that are rating on the same 0-1 scale. I would like a way to compare the regression lines between the same IV and different DVs in the same plot.

df <- data.frame(IV = c(2,2,1,4,5,5), DV1 = c(0,0,.25,.25,1,.75), DV2 = c(1,.5,.5,1,.5,.75))

mod1 <- lm(DV1 ~ IV, data = df)
mod2 <- lm(DV2 ~ IV, data = df)
1

1 Answers

0
votes

If your dependent variables are comparable in scale, you place the models in a list, and name them after your dependent variables, and iterate through, apply points and abline:

library(ghibli)
models = list(DV1=mod1,DV2=mod2)
pal = rev(as.character(ghibli_palettes$MarnieMedium1))[1:length(models)]
names(pal) = names(models)

plot(NULL,xlim=range(df$IV),ylim=range(c(df$DV1,df$DV2)),ylab="DV",xlab="IV")

for(i in names(models)){

f = as.formula(paste(i,"~ IV"))
points(f,data=df,col=pal[i],ylim = range(c(DV1,DV2)),pch=20)
abline(models[[i]],col=pal[i],lty=4)
}

legend("topleft",fill=pal,c("DV1","DV2"))

enter image description here