Home > Enterprise >  Curve Plot logistic regression
Curve Plot logistic regression

Time:05-29

here is my model. Exam_taken is a binary variable (0,1), and social class (1-10 scale) and GDP are continuous variables.

fit<-glm(Exam_taken~Gender Social_class*GDP, data=final, family=binomial(link="probit")
summary(fit)

I need to draw graphs. Goal 1) the relationship between Social_class and Exam_taken; Goal 2) the interaction of Social_class*GDP on Exam_taken.

I encountered two problems.

  1. I used the following code for Goal 1:
#exclude missing values
final=subset(final, final$Social_class!="NA")
final=subset(final, final$Exam_taken!="NA")
#graph
library(popbio)
logi.hist.plot(final$Social_class, final$Exam_taken, boxp=FALSE, type = "hist")

I got an error "Error in seq.default(min(independ),max(independ),len=100):'from' must be a finite number" How to fix it? Thank you so much

  1. I have no idea how to draw the interaction with two continuous variables on a binary outcome. Can anyone provide some directions? Thanks!

CodePudding user response:

You can use the sjPlot package to plot the predicted values from the model. If you save the output of the plot_model() function, you can modify its appearance using ggplot2.

Here is one of many pages that can show you other options with this package: enter image description here


Data used

Obviously, we don't have your data, but we can make a reasonable replica given clues from your description and code.

set.seed(1)

final <- data.frame(Gender = rep(c("Male", "Female"), 100),
                    Social_class = sample(10, 200, TRUE),
                    GDP = 1000 * sample(20:60, 200, TRUE))

final$Exam_taken <- rbinom(200, 1, 
                           c(0, 0.1)   0.05 * final$Social_class  
                             final$GDP/1e5 - 0.2)
  • Related