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
#Now imagine we're looking at the effect of calorie restriction, and this does actually have a true effect | |
#Of 5kg weight loss | |
#And we've managed to get a bigger sample size so our power is better! | |
#First we need to calculate the post-treatment sd as this is an input in the power calculation | |
#The post-treatment variable has sd comprised of following variance sources: pretest variance and | |
#Random weight loss/gain during intervention (we'll assume this random noise again has SD = 3) | |
post_sd = sd(population_pre + rnorm(10000, 0, 3)) #SD of about 16.6 | |
#Now calculate power |
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
set.seed(123) | |
#Generate a population of pretest body weights for 10,000 men (1) and women (0), with some random noise | |
#Men, are, 13kg heavier than women on average in our population (I.e., gender is a relevant covariate) | |
gender = rbinom(10000, 1, 0.5) | |
population_pre = 65+13*gender + rnorm(10000, 0, 15) | |
#In each experiment, we will sample 30 people and randomly assign them to a paleo diet (1) or no treatment (0) | |
#Sadly, in our example, the paleo diet has zero effect on weight. | |
#But there is some random weight gain/loss during the intervention for each person |
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
#Power calculator function | |
power_fun = function(effect_d = 0.5, rel = 0.8){ | |
SEM = 1*sqrt(1-rel) | |
SEdiff = sqrt(2*SEM^2) | |
CR = 1.96*SEdiff | |
pnorm(q = CR, mean = effect_d, sd = SEdiff, lower.tail = FALSE) | |
} | |
#Plot power by true effect size and reliability |
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
<?xml version="1.0" encoding="utf-8"?> | |
<style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" version="1.0" demote-non-dropping-particle="sort-only" default-locale="en-US"> | |
<info> | |
<title>Journal of Dental Research</title> | |
<id>http://www.zotero.org/styles/journal-of-dental-research</id> | |
<link href="http://www.zotero.org/styles/journal-of-dental-research" rel="self"/> | |
<link href="http://www.zotero.org/styles/harvard1" rel="template"/> | |
<author> | |
<name>Emmanuel Charpentier</name> | |
<email>emm.charpentier@free.fr</email> |