antivax-attitudes

Reanalyses of data from Horne, Powell, Hummel & Holyoak (2015)
git clone https://git.eamoncaddigan.net/antivax-attitudes.git
Log | Files | Refs | README | LICENSE

commit 44c4a7a7abc782e3e29462f9b6e4ad1faf18a00a
parent da836be5f37fbc90baee74fd260b650f77932a5a
Author: eamoncaddigan <eamon.caddigan@gmail.com>
Date:   Fri, 21 Aug 2015 17:02:07 -0400

Comments and cleanup.

Diffstat:
MJags-Yord-Xnom1grp-Mnormal.R | 13++-----------
Mantivax-attitudes.R | 7+++++--
2 files changed, 7 insertions(+), 13 deletions(-)

diff --git a/Jags-Yord-Xnom1grp-Mnormal.R b/Jags-Yord-Xnom1grp-Mnormal.R @@ -72,17 +72,7 @@ genMCMC = function( datFrm, yName , qName, # Write out modelString to a text file writeLines( modelString , con="TEMPmodel.txt" ) #----------------------------------------------------------------------------- - # INTIALIZE THE CHAINS. - # # Initial values of MCMC chains based on data: - # muInit = c( mean(y[x==1]) , mean(y[x==2]) ) - # sigmaInit = c( sd(y[x==1]) , sd(y[x==2]) ) - # threshInit = 1:(nYlevels-1)+0.5 - # threshInit[1] = NA - # threshInit[nYlevels-1] = NA - # # Regarding initial values in next line: (1) sigma will tend to be too big if - # # the data have outliers, and (2) nu starts at 5 as a moderate value. These - # # initial values keep the burn-in period moderate. - # initsList = list( mu=muInit, sigma=sigmaInit, nuMinusOne=4, thresh=threshInit ) + # This is where the chains would be initialized, but we'll just let JAGS do it initsList = NULL #----------------------------------------------------------------------------- # RUN THE CHAINS @@ -181,6 +171,7 @@ plotMCMC = function( codaSamples , datFrm , yName , qName, compVal , #RopeEff=NU xlab=bquote(sigma) , main=paste("Std. Dev.") , col="skyblue" ) + #----------------------------------------------------------------------------- # 4. effect size. effectSize = ( mu - compVal ) / sigma diff --git a/antivax-attitudes.R b/antivax-attitudes.R @@ -43,16 +43,19 @@ questionnaireData <- expData.clean %>% # "tidy" the data gather("question", "response", -subject_number, -intervention) %>% separate(question, c("interval", "question"), sep = "\\.") %>% - mutate(interval = factor(interval, c("pretest", "posttest"), ordered = TRUE)) + mutate(interval = factor(interval, c("pretest", "posttest"), ordered = TRUE), + question = factor(question)) # Some plots -------------------------------------------------------------- +# Check out the distribution of responses before and after the intervention p1 <- ggplot(questionnaireData, aes(x = question, y = response, fill = interval)) + geom_violin() + facet_grid(intervention ~ .) print(p1) +# Look at each subject's change for each question p2 <- ggplot(questionnaireData, aes(x = interval, y = response, group = subject_number)) + geom_line(alpha = 0.2, position = position_jitter(w = 0.15, h = 0.15)) + facet_grid(intervention ~ question) @@ -61,7 +64,7 @@ print(p2) # Bayesian analysis of survey data ---------------------------------------- -# For now, we'll just fit one model to all the questions pre-test. +# Fit a model to each question using pre-intervention data. modelData <- filter(questionnaireData, interval == "pretest") source("Jags-Yord-Xnom1grp-Mnormal.R")