Skip to content

Instantly share code, notes, and snippets.

@jebyrnes
Created January 3, 2017 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jebyrnes/37f01b1c231c17e7dfff888ca5392825 to your computer and use it in GitHub Desktop.
Save jebyrnes/37f01b1c231c17e7dfff888ca5392825 to your computer and use it in GitHub Desktop.
gets a profile of a GLM using offset
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