***************************************************************************** *** Stata-program (do-file) associated with the lectures on day four. *** *** Erik Parner *** ***************************************************************************** * My data is in "D:\Teaching\BasicBiostat\Lectures\Day4" cd "D:\Teaching\BasicBiostat\Lectures\Day4" capture log close log using day4.log,text replace ***************************************************************************** * one sample from a binomial distribution * The current smokers data ***************************************************************************** use smokers, clear codebook * Tabulate the data tab1 smoker * The exact confidence interval ci prop smoker * In Stata 13 and prior: ci smoker,bin * Testing the hypothesis pi=0.13 -exact p-value bitest smoker=0.13 * Approximate inference prtest smoker=0.13 * Inference using the immediate commands cii prop 1000 123 * cii 1000 123,bin bitesti 1000 123 0.13 prtesti 1000 0.123 0.13 ***************************************************************************** * Samples from two independent binomial * (the influenza vaccine data) ***************************************************************************** use vaccine, clear codebook * Tabulation with row percentages tabu vaccine influenza, row * Confidence intervals for the two groups bysort vaccine: ci prop influenza * In Stata 13 and prior: bysort vaccine: ci influenza, bin * Risk difference, risk ratio and odds ratio * using the approx standard errors (i.e. "woolf") from the lectures * and a chi-squared test cs influenza vaccine,or woolf * Chi- squared test using table tab2 vaccine influenza,chi2 * Fisher's exact test tab2 vaccine influenza,exact * EXACT confidence interval for the odds ratio cc influenza vaccine * Analysis of the data by the immediate commands * "\" starts a new row in the table tabi 20 220 \80 140, row chi2 cii prop 240 20 cii prop 220 80 * In Stata 13 and prior: se above. csi 20 80 220 140, or woolf cci 20 80 220 140 ***************************************************************************** * Sample size. ***************************************************************************** * In Stata 13 and later. power twoproportions 0.05 0.035, power(0.85) * In Stata 12, and prior. * sampsi 0.05 0.035, power(0.85) ***************************************************************************** * Paired binomials * (the severe cold data) * Do not use prtest cold14=cold12 for paired binomial data!s ***************************************************************************** use cold, clear ci prop cold14 ci prop cold12 * In Stata 13 and prior: "ci cold14, bin" and "ci cold12, bin". mcc cold14 cold12 mcci 212 256 144 707 ***************************************************************************** * Sample size ***************************************************************************** power pairedproportions 0.30 0.40 , corr(0.30) ***************************************************************************** * Chi-squared test in RxC tables * (the Village and water source data) ***************************************************************************** use water, clear codebook tab2 village water, chi2 expected ***************************************************************************** * Spearmann's rank correlation for ordered RxC tables * (the Age at Menarche and triceps skinfold data) ***************************************************************************** use triceps,clear codebook tab2 age triceps, expected spearman age triceps log close