Plot the results of a multivariate logistic regression model in R

前端 未结 1 1350
轻奢々
轻奢々 2021-01-31 23:42

I would like to plot the results of a multivariate logistic regression analysis (GLM) for a specific independent variables adjusted (i.e. independent of the confounders included

相关标签:
1条回答
  • 2021-02-01 00:15
    set.seed(12345)
    dataset <- expand.grid(Temp = rnorm(30), Age = runif(10))
    dataset$Truth <- with(dataset, plogis(2 * Temp - 3 * Age))
    dataset$Sample <- rbinom(nrow(dataset), size = 1, prob = dataset$Truth)
    model <- glm(Sample ~ Temp + Age, data = dataset, family = binomial)
    newdata <- expand.grid(
      Temp = pretty(dataset$Temp, 20), 
      Age = pretty(dataset$Age, 5))
    newdata$Sample <- predict(model, newdata = newdata, type = "response")
    library(ggplot2)
    ggplot(newdata, aes(x = Temp, y = Sample)) + geom_line() + facet_wrap(~Age)
    

    enter image description here

    ggplot(newdata, aes(x = Temp, y = Sample, colour = Age, group = Age)) + 
      geom_line()
    

    enter image description here

    0 讨论(0)
提交回复
热议问题