Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

Jupyter notebook yrbs_r/2016-07-01-130934.ipynb

64 views
Kernel: R
# YRBS survey analysis # Lots of help, inspiration, and borrowed (copy and pasted) code from asdfree.com: # https://github.com/ajdamico/asdfree/blob/master/Youth%20Risk%20Behavior%20Surveillance%20System/replicate%20cdc%20software%20for%20analysis%20of%20yrbs%20data%20publication.R#L73-L91
# Dependencies library(jsonlite) library(survey) library(RCurl)
# Config variables fullDatasetBaseUrl <- "https://owh.demo.socrata.com/resource/j6wc-x2ek.json?$limit=100000000000"
# Relevant filters from full dataset filterParams <- "&year=2013&sitetype=National" # Fetch and store filtered sample sample <- fromJSON(paste(fullDatasetBaseUrl,filterParams, sep = '')) nrow(sample)
[1] 13583
sample <- subset(sample, !is.na(q8)) sample <- transform(sample, weight = as.numeric(weight)) sample <- transform(sample, q8 = as.numeric(q8)) yrbsSurvey <- svydesign( ~psu , strata = ~stratum, data = sample, weights = ~weight, nest = TRUE )
( helmet <- svymean( ~as.numeric( qn8 == 1 ) , yrbsSurvey , na.rm = TRUE ) )
mean SE as.numeric(qn8 == 1) 0.87873 0.0129