Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

How to calculate direct and indirect standardized rates by subgroups in R?

$
0
0

Using below example data, I am trying to calculate direct and indirect standardized rates by subgroups such as year, region and sex using "ageadjust.indirect" and "ageadjust.direct" functions in R, but not much luck. I appreciate any help.

#study Data
data <- data.frame (

  year = rep(c(rep("2010",20), rep("2011",20)),1),
  subregion = rep(c(rep("A",10), rep("B",10)),2),
  gender=rep(c(rep("M",5), rep("F",5)),4),
  agegr = rep(c('00-14','15-34','35-54','55-74','75+'),8),
  pop = round((runif(40, min = 10000, max = 99999)), digits = 0),
  count = round((runif(40, min = 100, max = 999)), digits = 0)
) 

data$rate = data$count / data$pop
# standard data
stdata <- data.frame(age=rep(c('00-14','15-34','35-54','55-74','75+'),2),
                       sex=rep(c('M','F'),c(5,5)),
                       pop=c(308543,401996,409450,199486,610631,
                             293991,388762,418814,227170,104944)
  )
#implement direct age standardization using 'ageadjust.direct'
library(epitools)
dsr<- ageadjust.direct(count = data$count, pop = data$pop, 
                                    , stdpop = stdata$pop)
round(100000*dsr, 2) ##rate per 100,000 per year using standard pop

# how to get dsr by year subregion, and gender?

#implement indirect age standardization using 'ageadjust.indirect'

dataB<-subset(data,subregion == 'B')

isr <- ageadjust.indirect(count = data$count, pop = data$pop,
                          stdcount = dataB$count, stdpop = dataB$pop)
round(isr$sir, 2)         ##standarized incidence ratio
round(100000*isr$rate, 2) ##rate per 100,000 per year

# how to get isr by year, subregion, and sex? 

Viewing all articles
Browse latest Browse all 201867

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>