One Sample t-test
data: Time
t = 1.8244, df = 29, p-value = 0.03921
alternative hypothesis: true mean is greater than 160
95 percent confidence interval:
162.8305 Inf
sample estimates:
mean of x
201.2333
Reject null; mean (for all people to complete form) greater than 160.
dbinom
gives the probability of eg. exactly 17 successes in a binomial with \(n = 30\) and \(p = 0.5\):or
and hence (note first input):
This last is \(P(X \ge 17) = P(X > 16)\).
smmr
smmr
to do the sign test (and some other things). Installation is non-standard:smmr
for sign testsmmr
’s function sign_test
needs three inputs: a data frame, a column and a null median:Test | P-value |
---|---|
\(t\) | 0.0392 |
Sign | 0.2923 |
Test decision | Confidence interval | |
---|---|---|
Reject \(H_0\) at level \(\alpha\) | \(\iff\) | \(C\%\) CI does not contain \(H_0\) value |
Do not reject \(H_0\) at level \(\alpha\) | \(\iff\) | \(C\%\) CI contains \(H_0\) value |
Idea: “Plausible” parameter value inside CI, not rejected; “Implausible” parameter value outside CI, rejected.
“for each null median, run the function pval_sign
for that null median and get the P-value”:
for
since we don’t know how many times we’re going around. Keep going while
a condition is true:[1] 210.00000000 0.09873715
[1] 215.00000000 0.06142835
[1] 217.50000000 0.04277395
[1] 216.25000000 0.04277395
[1] 215.62500000 0.04277395
smmr
has function ci_median
that does this (by default 95% CI):Suppose we want to know whether people are in favour of having daylight savings time all year round. We ask 20 males and 20 females whether they each agree with having DST all year round (“yes”) or not (“no”). Some randomly chosen data:
Count up individuals in each category combination, and arrange in contingency table:
chisq.test
.
Pearson's Chi-squared test
data: tab
X-squared = 7.033, df = 1, p-value = 0.008002
correct = FALSE
uses “Yates correction”.
Pearson's Chi-squared test
data: tab
X-squared = 4.4638, df = 1, p-value = 0.03462
median_test
does the whole thing:$grand_median
[1] 47
$table
above
group above below
c 8 15
t 14 7
$test
what value
1 statistic 4.46376812
2 df 1.00000000
3 P-value 0.03462105
Values aligned in columns:
my_url <-
"http://ritsokiguess.site/datafiles/analgesic.txt"
pain <- read_table(my_url)
pain %>% mutate(diff = druga - drugb) -> pain
glimpse(pain)
Rows: 12
Columns: 4
$ subject <dbl> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
$ druga <dbl> 2.0, 3.6, 2.6, 2.6, 7.3, 3.4, 14.9, 6.6, 2.3, 2.0, 6.8, 8.5
$ drugb <dbl> 3.5, 5.7, 2.9, 2.4, 9.9, 3.3, 16.7, 6.0, 3.8, 4.0, 9.1, 20.9
$ diff <dbl> -1.5, -2.1, -0.3, 0.2, -2.6, 0.1, -1.8, 0.6, -1.5, -2.0, -2.3,…
$above_below
below above
9 3
$p_values
alternative p_value
1 lower 0.07299805
2 upper 0.98071289
3 two-sided 0.14599609
Bootstrap sampling distribution of sample mean differences:
Yes we did need to worry; this is clearly skewed left and not normal.
Comments