Last active
February 25, 2022 10:31
-
-
Save samclifford/e3bf65c3c389aae21b4cfadda629748a to your computer and use it in GitHub Desktop.
A method for extracting confidence intervals for parametric terms from an mgcv gamObject and returning a tidy data frame
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
confint.gam <- function(mod, level = 0.95) { | |
# a method for extracting confidence intervals and returning a tidy data frame | |
require(mgcv) | |
require(dplyr) | |
mod.s <- summary(mod) | |
E <- data.frame(Estimate = mod.s$p.coeff) %>% | |
mutate(Term = row.names(.)) %>% | |
select(Term, Estimate) | |
SE <- data.frame(SE = mod.s$se) %>% | |
mutate(Term = row.names(.)) %>% | |
select(Term, SE) | |
nu <- mod.s$residual.df | |
inner_join(E, SE) %>% | |
mutate(L = Estimate + | |
SE * qt(df = nu, | |
p = (1 - level) / 2), | |
U = Estimate + | |
SE * qt(df = nu, | |
p = 1 - (1 - level) / 2)) %>% | |
return | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment