Created
October 31, 2016 17:27
-
-
Save naomispence/7b31e11c1f554dd08cadb6889dd13871 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#add these libraries | |
library(lsr) | |
library(dplyr) | |
#the code below limits the dataset to the 2014 survey data and creates a new dataset named GSS2014 | |
GSS2014<-dplyr::filter(GSS, year==2014) | |
#get different confidence intervals for the same variable | |
ciMean(GSS2014$tvhours, na.rm=TRUE, conf =0.90) | |
ciMean(GSS2014$tvhours, na.rm=TRUE, conf =0.95) | |
ciMean(GSS2014$tvhours, na.rm=TRUE, conf=0.99) | |
#get mean for different groups with the code below | |
aggregate(GSS2014$tvhours, na.rm=TRUE, by=list(GSS2014$race), mean) | |
#Although it is not clearly labeled as such, the code below provides a 95% confidence interval | |
aggregate(GSS2014$tvhours, na.rm=TRUE, by=list(GSS2014$race), ciMean) | |
#dichotomize a variable and get confidence interval around proportion | |
GSS2014$nochild <-as.numeric(GSS2014$childs) <= 0 | |
crosstab(GSS2014, row.vars = "nochild") | |
mean(GSS2014$nochild) | |
ciMean(as.numeric(GSS2014$nochild), conf =0.90) | |
ciMean(as.numeric(GSS2014$nochild), conf =0.95) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment