source("http://192.38.117.59/~linearpredictors/datafiles/readFever.R") ## sorting the data according to alcohol consumption fever <- fever[order(fever$alco),] ## Fitting linear model with alcohol as explanatory variable model <- glm(death ~ alco, family = binomial, data = fever) ## Observed death probabilities smoothed on evenly distributed values ## of alcohol consumption smoothed.deaths <- predict( loess(unclass(death)-1 ~ alco, data = fever, degree = 1, span = 0.8), data.frame(alco = seq(0, 15, .1)) ) ## Smoothed observed deaths (probabilities) on log-odds scale plot(seq(0,15,.1), log(smoothed.deaths/(1-smoothed.deaths)), type = "l", xlab = "Drinks per week", ylab = "Fetal death, log(odds) scale", ylim = c(-5,-3) ) lines((model$model)$alco, predict(model, type="link"), lty="22") ## Marginal histogram hist <- hist(fever$alco, breaks = seq(-0.25,15.25,0.5), plot = FALSE) p <- hist$mids[hist$counts != 0] counts <- hist$counts[hist$counts != 0] segments(p, -5, p, -5 + counts/max(counts)*.2)