Skip to content

Instantly share code, notes, and snippets.

@simkimsia
Last active August 29, 2015 14:02
Show Gist options
  • Save simkimsia/9bb03404478228ef0a1c to your computer and use it in GitHub Desktop.
Save simkimsia/9bb03404478228ef0a1c to your computer and use it in GitHub Desktop.
working for two grouped means t-test
##Q4
## Refer to the setting of the previous question.
## To further test the system,
## administrators selected 20 nights and
## randomly assigned the new triage system to be used on
## 10 nights and the standard system on the remaining 10 nights.
## They calculated the nightly median waiting time (MWT) to see
## a physician. The average MWT for the new system was
## 3 hours with a variance of 0.60 while
## the average MWT for the
## old system was 5 hours with a variance of 0.68.
## Consider the 95% confidence interval estimate for the
## differences of the mean MWT associated with the new system.
## Assume a constant variance. What is the interval?
## Subtract in this order (New System - Old System).
mean_new_system = 3
sample_size_new_system = 10
variance_new_system = 0.6
degree_new_system = sample_size_new_system - 1
mean_old_system = 5
sample_size_old_system = 10
variance_old_system = 0.68
degree_old_system = sample_size_old_system - 1
sample_sizes_of_both_minus_2 = sample_size_new_system + sample_size_old_system -2
## calculate the pooled variance
sp <- sqrt((degree_new_system * variance_new_system + degree_old_system * variance_old_system)/(sample_size_new_system + sample_size_old_system - 2))
mean_new_system - mean_old_system + c(-1, 1) * qt(0.975, sample_sizes_of_both_minus_2) * sp * (1/sample_size_new_system + 1/sample_size_old_system)^0.5
## answer i get is
## [1] -2.602492 -1.397508
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment