- library(epiR) # Used for Risk ratio
- library(MASS) # Used for data
- dat1 <- birthwt; head(dat1)
- ## Generate a table of cell frequencies. First set the levels of the outcome
- ## and the exposure so the frequencies in the 2 by 2 table come out in the
- ## conventional format:
- dat1$low <- factor(dat1$low, levels = c(1,0))
- dat1$smoke <- factor(dat1$smoke, levels = c(1,0))
- dat1$race <- factor(dat1$race, levels = c(1,2,3))
- ## Generate the 2 by 2 table. Exposure (rows) = smoke. Outcome (columns) = low.
- tab1 <- table(dat1$smoke, dat1$low, dnn = c("Smoke", "Low BW"))
- print(tab1)
- ## Compute the incidence risk ratio and other measures of association:
- epi.2by2(dat = tab1, method = "cohort.count",
- conf.level = 0.95, units = 100, outcome = "as.columns")
复制代码
源答案见这里:
https://stats.stackexchange.com/questions/180135/calculating-a-risk-ratio-for-specific-x-values-from-a-gam-model-using-the-mgcv-p