data(msa)
dat <- aggregate(cbind(Count, Population) ~ Year, data = msa, FUN = sum)
fit <- stan_rw(dat, time = Year)
## print summary of results
print(fit)
print(fit$summary)
## plot time trends (rates per 10,000)
plot(fit, scale = 10e3)
plot(fit, style = 'lines', scale = 10e3)
## Summary with MCMC diagnostics (n_eff, Rhat; from Rstan)
print(fit$samples)
## cumulative percent change
fit_pc <- apc(fit)
print(fit_pc$cpc)
plot(fit_pc, cumulative = TRUE)
# \donttest{
## age-specific rates
data(cancer)
cancer2 <- subset(cancer, grepl("55-59|60-64|65-69", Age))
fit <- stan_rw(cancer2, time = Year, group = Age,
chains = 3, iter = 1e3) # for speed only
## plot trends
plot(fit, scale = 10e3)
## age-standardized rates
data(standard)
fit_stands <- standardize(fit,
label = standard$age,
standard_pop = standard$standard_pop)
print(fit_stands)
plot(fit_stands)
## percent change for age-standardized rates
fit_stands_apc <- apc(fit_stands)
plot(fit_stands_apc)
print(fit_stands_apc)
# }
Run the code above in your browser using DataLab