I have difficulties with two tasks:
# dataframe # 0=female # 1=male set.seed(1234) df <- data.frame( sex=factor(rep(c("0", "1"), each=200)), weight=round(c(rnorm(200, mean=55, sd=5), rnorm(200, mean=65, sd=5))), height=round(c(rnorm(200, mean=160, sd=10), rnorm(200, mean=170, sd=10))) )
Create an ggplot-Object showing the predicted "effect" of two variables included in two separate logistic regression analyses.
library(ggplot2) library(sjPlot) lm1 <- glm(sex ~ weight, data=df, family="binomial") lm2 <- glm(sex ~ height, data=df, family="binomial") # Current version: Plot them next to each other. p1 <- plot_model(lm1, type="pred", term="weight") p2 <- plot_model(lm2, type="pred", term="height") ggarrange(p1,p2) # Wanted version: Plot them overlapping over each other (potentially without confidence intervals)
Create a nomogram/3-d surface showing the probability of being male by weight and height.
Problem 1: I do not manage to make the "outcome" axis "logarithmic".
Problem 2: I need to set certain limits for the continuous variables. Is there any default? The nomogram-Code does not work currently.
library(rms) lm3 <- rms::Glm(sex ~ weight + height, data=df, family="binomial") plot(nomogram(lm3, weight=seq(40,100,by=2), height=seq(150,200,by=5), fun=plogis, lp="Prob of being male")) bplot(Predict(lm3, weight=seq(40,100,by=2), height=seq(150,200,by=5)))
Thank you so much!