项目作者: SpectrumHealthResearch

项目描述 :
Calculate independent samples t test using summary statistics
高级语言: R
项目地址: git://github.com/SpectrumHealthResearch/t-test.git
创建时间: 2018-05-31T01:47:55Z
项目社区:https://github.com/SpectrumHealthResearch/t-test

开源协议:GNU General Public License v3.0

下载


Calculate two sample Student’s t-test with summary statistics

These are simple scripts to facilitate the computation of the two independent
samples Student’s t test when only the summary statistics of the data are
available, but not the raw data. To compute the t statistic, you will need
the following:

  • Group means
  • Group standard deviations
  • Group sizes

Instructions

R

Installation

The function is housed in an R package. To use the function, first you must
install the package. To do so, execute the following in your R console:

  1. if (!require(devtools)) install.packages("devtools")
  2. devtools::install_github("SpectrumHealthResearch/t-test/R")

Example

  1. # Load the package into your session
  2. library(stt)
  3. # Using chickwts data from datasets
  4. summary_chicks <- tapply(
  5. chickwts$weight,
  6. chickwts$feed,
  7. function(x) c(mean = mean(x), sd = sd(x), n = length(x))
  8. )
  9. # We now have a named list of vectors containing summary stats
  10. summary_chicks
  11. # Execute the t test using summary stats
  12. with(summary_chicks,
  13. summary_t_test(
  14. linseed["mean"],
  15. soybean["mean"],
  16. linseed["sd"],
  17. soybean["sd"],
  18. linseed["n"],
  19. soybean["n"],
  20. alternative = "less",
  21. method = "sat"
  22. )
  23. )
  24. ## Two Sample t-test (satterthwaite)
  25. ##
  26. ## data: summary statistics
  27. ## t = -1.3246, df = 23.63, p-value = 0.09899
  28. ## alternative hypothesis: true difference in means is less than 0
  29. ## 95 percent confidence interval:
  30. ## -Inf 8.09536
  31. ## sample estimates:
  32. ## difference in means
  33. ## -27.67857
  34. # Compare with stats::t.test using raw data
  35. t.test(
  36. weight ~ feed,
  37. chickwts,
  38. feed %in% c("linseed", "soybean"),
  39. alternative = "less"
  40. )
  41. ## Welch Two Sample t-test
  42. ##
  43. ## data: weight by feed
  44. ## t = -1.3246, df = 23.63, p-value = 0.09899
  45. ## alternative hypothesis: true difference in means is less than 0
  46. ## 95 percent confidence interval:
  47. ## -Inf 8.09536
  48. ## sample estimates:
  49. ## mean in group linseed mean in group soybean
  50. ## 218.7500 246.4286

SAS

There are many ways to make use of this program. One suggested route:

  1. Clone this repository or download the SAS code in the SAS folder.
  2. Run the macro definition in the source editor or using %include.
  3. Run the macro call.