Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 205372

Plot regression lines in R

$
0
0

I need to add regression lines for each different combination of Sex and Race(white/nonwhite). These are the models and the plot I made, but I have no clue on where to put these lines and how to do it.

   colors <- interaction(Race, Sex)

  shapes = c(16) 
  shapes <- shapes[as.numeric(Sex)]

  plot(Years_Service, Average_Score, main="Score by Time", xlab="Years of service", ylab="AVG Score", col = colors, pch=16)


 legend("topleft", title="Legend", legend=c("White Male"," White Female", "Nonwhite Male", "Nonwhite Female"),
     col=c("blue", "red", "green", "black"), pch=16, cex=0.54)

  lines(lowess(Years_Service, Average_Score),col=2)


 model1<-lm(Average_Score~Years_Service+Sex+Race)
 summary(model1)
 plot(Average_Score)


 model2<-lm(Years_Service~Sex)
 summary(model2)
 plot(model2)


 model3<-lm(Years_Service~Race)
 summary(model3)
 plot(model3)

Thanks in advance.


Viewing all articles
Browse latest Browse all 205372

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>