r - prop.test function in a loop -


i wanting 2 sample proportions test in r using loop , split health center , measure. below link show example of how data set (the website not allow me upload image of dataset)

basically, want compare health center a's measure a's using prop.test function , repeat health centers (29 of them) , measures (14 of them). not sure on code loop proportion tests want , split how want.

any appreciated!

i went ahead deleted 0's. however, code worked did not split data how wanted to. hoping split health center , measure instead splits health center have 28 measures prop.test analyzing instead of health center measure a. see output example below: click here see output

you can perform split , prop.test using this

lapply(split(df, df$health_center), function(x) prop.test(as.matrix(cbind(x[,3], x[,4]-x[,3])))) 

output

$a1          2-sample test equality of proportions continuity correction  data:  as.matrix(cbind(x[, 3], x[, 4] - x[, 3])) x-squared = 1.713, df = 1, p-value = 0.1906 alternative hypothesis: two.sided 95 percent confidence interval:  -0.28136975  0.04846377 sample estimates:    prop 1    prop 2  0.2307692 0.3472222    $a2          2-sample test equality of proportions continuity correction  data:  as.matrix(cbind(x[, 3], x[, 4] - x[, 3])) x-squared = 0.12192, df = 1, p-value = 0.727 alternative hypothesis: two.sided 95 percent confidence interval:  -0.1789668  0.1114439 sample estimates:    prop 1    prop 2  0.4800000 0.5137615  

input data

df <- data.frame(health_center=c("a1","a2","a1","a2"),                  measure=c("a","b","a","b"),                  numerator=c(15,48,25,56),                  denominator=c(65,100,72,109), stringsasfactors=f) 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -