24_deb_pkg_gov/R/calculatePower.R

50 lines
1.5 KiB
R
Raw Normal View History

2023-11-08 17:10:54 +00:00
##############################################################################
#
# Purpose:
# Use pilot project data to calculate power of a full study through simulation
#
# Parts:
# (0) - Setup
# (1) - Get the pilot data and clean it
# (2) - Run the model on the pilot data and extract effects
# (3) - Set up and run the simulation
# ====> Set variables at the arrows <====
#
##############################################################################
rm(list=ls())
set.seed(424242)
# (1) - Get the pilot data and clean it
source('~/Research/tor_wikipedia_edits/handcoded_edits/inter_coder_reliability_ns0.R')
d$nd <- to_logical(d$not.damaging, custom_true=c("Y"))
levels(d$source) <- c("IP-based Editors", "New Editors", "Registered Editors", "Tor-based Editors")
# (2) - Run the model on the pilot data
pilotM <- glm(nd ~ source, family=binomial(link="logit"), data=d)
summary(pilotM) #we expect effect sizes on this order
pilot.b0 <- coef(summary(pilotM))[1,1]
pilot.b1 <- coef(summary(pilotM))[2,1]
pilot.b2 <- coef(summary(pilotM))[3,1]
pilot.b3 <- coef(summary(pilotM))[4,1]
# (3) - Set up and run the simulation
source('powerAnalysis.R') #my little "lib"
#====>
nSims <- 5000 #how many simulations to run
n <- 100 #a guess for necessary sample size (per group)
#makeData(10) #DEBUGGING CODE -- you can uncomment this if you want to see it work
#<====
print("Levels are:")
print(levels(d$source))
powerCheck(n, nSims)
#Sample values
powerCheck(50, 100)
powerCheck(80, 1000)
powerCheck(200, 5000)