The notes for the topics on this page can be found in the lecture 4 folder on Canvas.
One method to conduct a hypothesis test for a single proportion in R is to use the prop_test
function in the catfun package. For more information run ?prop_test
in the R console. For further help, please watch the video example.
library(catfun)
prop_test(7, 50, method = "wald", p = 0.2)
## 7 out of 50, null probability = 0.2
## ----------------------------------------
## Observed proportion: 0.14
## Confidence interval method: wald
## Confidence interval: 0.04382187 0.2361781
##
## Exact limits: 0.0581917 0.267396
##
## Test that 0.14 = 0.2
## ----------------------------------------
## Chi-squared: 1.125
## Degrees freedom: 1
## p-value: 0.28884
The only thing that changes when conducting an exact test is that you must specify exact = TRUE
library(catfun)
prop_test(2, 6, method = "wald", p = 0.2, exact = TRUE)
## 2 out of 6, null probability = 0.2
## ----------------------------------------
## Observed proportion: 0.3333
## Confidence interval method: wald
## Confidence interval: 0 0.7105286
##
## Exact limits: 0.04327187 0.7772219
##
## Test that 0.3333 = 0.2
## ----------------------------------------
## Chi-squared: 0.6666667
## Degrees freedom: 1
## p-value: 0.41422
##
## Exact p-value: 0.34464
To conduct a hypothesis test for a single proportion in SAS you use the frequency procedure. For further help, please watch the video example.
The syntax is:
proc freq data = <dataset>;
table <variable name> / binomial(p = <null value>) alpha = <alpha level>;
weight <weighting variable if summary data>;
run;
Variable name corresponds to the variable in the dataset, null value corresponds to your null hypothesis, alpha level corresponds to your pre-specified alpha level, and weight corresponds to the variable in the dataset that contains your counts (in these cases, the same variable that proceeds your table statement).
data followup;
input loss;
cards;
7
43
;
run;
title 'Loss to Follow-up Example';
proc freq data = followup order = data;
table loss / binomial(p = 0.2) alpha = 0.05;
weight loss;
run;
## Loss to Follow-up Example
##
## The FREQ Procedure
##
## Cumulative Cumulative
## loss Frequency Percent Frequency Percent
## ---------------------------------------------------------
## 7 7 14.00 7 14.00
## 43 43 86.00 50 100.00
##
##
## Binomial Proportion
## loss = 7
##
## Proportion 0.1400
## ASE 0.0491
## 95% Lower Conf Limit 0.0438
## 95% Upper Conf Limit 0.2362
##
## Exact Conf Limits
## 95% Lower Conf Limit 0.0582
## 95% Upper Conf Limit 0.2674
##
## Test of H0: Proportion = 0.2
##
## ASE under H0 0.0566
## Z -1.0607
## One-sided Pr < Z 0.1444
## Two-sided Pr > |Z| 0.2888
##
## Sample Size = 50
The only thing that changes when conducting an exact test is you must add exact binomial
after the table statement.
data followupEX;
input loss;
cards;
2
4
;
run;
title 'Loss to Follow-Up Exact Example';
proc freq data = followupEX order = data;
table loss / binomial(p = 0.2) alpha = 0.05;
exact binomial;
weight loss;
run;
## Loss to Follow-Up Exact Example
##
## The FREQ Procedure
##
## Cumulative Cumulative
## loss Frequency Percent Frequency Percent
## ---------------------------------------------------------
## 2 2 33.33 2 33.33
## 4 4 66.67 6 100.00
##
##
## Binomial Proportion
## loss = 2
##
## Proportion (P) 0.3333
## ASE 0.1925
## 95% Lower Conf Limit 0.0000
## 95% Upper Conf Limit 0.7105
##
## Exact Conf Limits
## 95% Lower Conf Limit 0.0433
## 95% Upper Conf Limit 0.7772
##
## Test of H0: Proportion = 0.2
##
## ASE under H0 0.1633
## Z 0.8165
## One-sided Pr > Z 0.2071
## Two-sided Pr > |Z| 0.4142
##
## Exact Test
## One-sided Pr >= P 0.3446
## Two-sided = 2 * One-sided 0.6893
##
## Sample Size = 6