Created
January 3, 2017 22:09
-
-
Save jebyrnes/37f01b1c231c17e7dfff888ca5392825 to your computer and use it in GitHub Desktop.
gets a profile of a GLM using offset
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
adf <- data.frame(x=1:100) %>% | |
mutate(y=rnorm(100, 5*x, 90)) | |
#What do we have | |
plot(adf) | |
#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) %>% | |
slice(c(1,n())) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment