I created this plot using tensor smooths.
.
I would like to add a visualization of the data density along the x-axis and z-axis. Ideally, this could be done with either:
A rug plot on the respective axes, or A density function plot for the data on the axes. I have searched extensively but couldn't find a solution.
This is my current code:
gam.model <- gam(death_or_neurodeficit1y ~
te(OtherBiomarker, laktat_0, bs = 'cr') + age + isMALE + Diabetes + trop_t_s + shock + byst_cpr + gfr_0,
data = df,
family = "binomial")
par(cex = 1)
vis.gam(gam.model,
view = c("OtherBiomarker", "laktat_0"),
plot.type = "persp",
type = "response",
theta = 320,
phi = 25,
color = "heat",
xlab = "\n\nOtherBiomarker at admission",
ylab = "\n\nLactate at admission",
zlab = "\n\nPredicted Probability",
border = "black",
r = 100,
ticktype = "detailed"
)
I got the density function but could not manage to add it to the plot.
lactate_density <- density(gam.model$model$laktat_0)
OtherBiomarker_density <- density(gam.model$model$OtherBiomarker)
Here is a data sample:
structure(list(death_or_neurodeficit1y = c(0, 1, 1, 1, 0, 1),
age = c(53, 67, 76, 69, 81, 51), isMALE = c(1, 1, 1, 0, 1,
1), diabetes = c(0, 0, 0, 0, 0, 0), trop_t_s = c(296, 120,
24, 41, 71, 258), shock = c(1, 1, 1, 1, 1, 1), byst_cpr = c(1,
0, 1, 1, 1, 1), gfr_0 = c(107.1, 64.1, 64.9, 38, 54.2, 65.6
), OtherBiomarker = c(14562.291216349, 26308.5822361957,
15525.1522892513, 26273.8258989978, 23385.2426802908, 18708.4888976223
), laktat_0 = c(16.8, 55.5, 63.9, 40.1, 139.7, 27.6)), terms = death_or_neurodeficit1y ~
age + isMALE + diabetes + trop_t_s + shock + byst_cpr + gfr_0 +
OtherBiomarker + laktat_0, na.action = structure(c(`26` = 26L,
`33` = 33L, `43` = 43L, `46` = 46L, `57` = 57L, `70` = 70L, `91` = 91L,
`93` = 93L, `105` = 105L, `115` = 115L, `116` = 116L, `118` = 118L,
`121` = 121L, `127` = 127L, `135` = 135L, `160` = 160L), class = "omit"), row.names = c(NA,
6L), class = "data.frame")
Thank you in advance.
