I cannot fit an intercept only model with an offset term using the lrm function from rms. The equivalent model can be fit with glm. I cannot find anything about this on the internet. Reproducible example below. Any help appreciated!
### Generate data
###
## Load rms
#install.packages("rms")
library(rms)
## Set seed
set.seed(1)
## Generate event probabilities
p.true <- runif(1000, 0.2 , 0.8)
## Generate binary outcome
state1.bin <- rbinom(1000, 1, p.true)
## Crete dataset with outcome, and the logit of the event probabilities
data.raw.temp <- data.frame("state1.bin" = state1.bin, "p.true.logit1" = log(p.true/(1-p.true)))
### Fit an intercept only model, using the logit of the event probabilities as an offset
###
## GLM attempt 1
glm(state1.bin ~ offset(p.true.logit1), data = data.raw.temp, family = binomial(link = "logit"))
## lrm attempt 1
lrm(state1.bin ~ offset(p.true.logit1), data = data.raw.temp)
## lrm attempt 2
lrm(state1.bin ~ 1, offset = p.true.logit1, data = data.raw.temp)
GLM attempt 1 sucessfully fits the desired model
Call: glm(formula = state1.bin ~ offset(p.true.logit1), family = binomial(link = "logit"),
data = data.raw.temp)
Coefficients:
(Intercept)
-0.02642
Degrees of Freedom: 999 Total (i.e. Null); 999 Residual
Null Deviance: 1270
Residual Deviance: 1270 AIC: 1272
lrm attempt 1 gives the following error
Error in lrm(state1.bin ~ offset(p.true.logit1), data = data.raw.temp) :
object 'nact' not found
lrm attempt 2 gives the following error
Error in fitter(X, Y, offset = offs, penalty.matrix = penalty.matrix, :
formal argument "offset" matched by multiple actual arguments
I don't know how to do it using lrm
, but you can use lrm.fit
.
with(data.raw.temp, lrm.fit(y = state1.bin, offset = p.true.logit1))