Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
gets a profile of a GLM using offset
adf <- data.frame(x=1:100) %>%
mutate(y=rnorm(100, 5*x, 90))
#What do we have
#examine the output
summary(glm(y ~ x, data=adf))
#try out two different fixed slope coefficients
glm(y ~ 1, offset=2*x, data=adf)
glm(y ~ 1, offset=1*x, data=adf)
### Fit a bunch of slope coefficients to make a profile
### for the intercept
coefFrame <- data.frame(b1 = seq(-30,30,length.out=500)) %>%
rowwise() %>%
mutate(int = coef(glm(y ~ 1, offset=b1*x, data=adf)),
LL = logLik(glm(y ~ 1, offset=b1*x, data=adf))[1])
plot(LL ~ b1, data=coefFrame)
critVal <- logLik(glm(y ~ x, data=adf))[1]-qchisq(.95,1)/2
coefFrame %>%
filter(LL>critVal) %>%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment