###INDEPENDENT GROUPS: COMPARISONS OF TWO MEANS # Minimum sample size for comparing two independent means # Compare mean SBP in treatment vs control group # We want to detect a difference of 5 mmHg, assuming: # SD=12 mmHg (from previous studies) # alpha=0.05 # power=0.80 library(Epi) epi.sscompc( n = NA, # sample size for each group (to be estimated) treat = 130, # expected mean in treatment group control = 135, # expected mean in control group sigma = 12, # assumed common standard deviation power = 0.80, # desired statistical power r = 1, # equal sample size in the two groups design = 1, # simple random sampling sided.test = 2, # two-sided test conf.level = 0.95 # significance level alpha = 0.05 ) ########################################################################## ###DEPENDENT GROUPS: COMPARISONS OF TWO MEANS # Minimum sample size for comparing the mean of two dependent groups # Compare mean FPG in the same patients before a dietary intervention and after 3 months # We want to detect a difference of 8 mg/dL, assuming: # SD of the paired differences=20 mg/dL (from previous studies) # alpha=0.05 # power=0.80 library(pwr) pwr.t.test( d = 8/20, # standardized effect size = mean difference / SD of paired differences power = 0.80, # desired statistical power sig.level = 0.05, # significance level type = "paired", # paired data alternative = "two.sided") #What if type="two.sample"? #The more similar the paired observations are, #the easier it is to detect a difference. #So fewer subjects are needed. ########################################################################## ###INDEPENDENT GROUPS: COMPARISONS OF TWO PROPORTIONS # Minimum sample size for comparing the proportions in two independent groups # Compare smoking cessation rates in two groups: # group 1 received standard counseling; group 2 counseling + a mobile app # We expect the following proportions: # 20% in the control group; 35% in the intervention group # We assume: # alpha=0.05 # power=0.80 library(pwrss) power.z.twoprops( prob1 = 0.20, # expected proportion in control group prob2 = 0.35, # expected proportion in intervention group power = 0.80, # desired statistical power alpha = 0.05, # significance level alternative = "two.sided", paired = FALSE # independent groups ) ########################################################################## ###DEPENDENT GROUPS: COMPARISONS OF TWO PROPORTIONS # Minimum sample size for comparing the proportions in two dependent groups # We want to evaluate whether an SMS reminder improves vaccination uptake in the same patients # Expected willingness was 50% before and 65% after the SMS reminder # We assume: # alpha=0.05 # power=0.80 # moderate correlation between paired responses (r=0.5) library(pwrss) power.z.twoprops( prob1 = 0.50, # expected proportion before intervention prob2 = 0.65, # expected proportion after intervention power = 0.80, # desired statistical power alpha = 0.05, # significance level alternative = "two.sided", paired = TRUE, # paired/matched data rho.paired = 0.50 # assumed correlation within pairs ) ########################################################################### ###SAMPLE SIZE FOR A CHI-SQUARE TEST # We want to test whether obesity status is associated with the presence of hypertension # We assume: # alpha=0.05 # power=0.8 # small-to-moderate effect size library(pwr) pwr.chisq.test( w = 0.3, # Cohen's effect size (0.1 small, 0.3 medium, 0.5 large) df = 1, # degrees of freedom for a 2x2 table sig.level = 0.05, # significance level power = 0.80 # desired statistical power ) ########################################################################### ###SAMPLE SIZE FOR A CORRELATION TEST # We want to test whether BMI is associated with fasting insulin # We assume: # alpha=0.05 # power=0.8 # expected r=0.3 # Sample size for testing a correlation coefficient # Example: correlation between BMI and fasting insulin library(pwr) pwr.r.test( r = 0.3, # expected correlation coefficient sig.level = 0.05, # significance level power = 0.80, # desired statistical power alternative = "two.sided" ) ####################################################################### ###SAMPLE SIZE FOR AN ODDS RATIO # A case-control study of the relationship between smoking and CHD is planned. # A sample of men with newly diagnosed CHD will be compared for smoking status with a sample of controls. # Assuming an equal number of cases and controls, how many study subject are required to detect an OR of 2.0 # with 0.90 power using a two-sided 0.05 test? # Previous surveys have shown that around 30% of males without CHD are smokers. library(epiR) epi.sscc(OR = 2.0, p0 = 0.30, n = NA, power = 0.90, r = 1, phi.coef = 0, design = 1, sided.test = 2, conf.level = 0.95, method = "unmatched") # p0: prevalence of the disease among the controls # phi.coef: correlation between case and control exposures for matched pairs. Set to null if unmatched. # design: design effect, used to take into account the possible presence of clustering in the random sampling of the data.