Coder Social home page Coder Social logo

davidatlarge / t_test_means_sds Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 1.0 238 KB

calculate t-statistic and p-value from group means, SDs, and sample size

R 100.00%
r standard-deviations functional-programming function statistics data-science t-test

t_test_means_sds's Introduction

calculate t-statistic and p-value from group means, SDs, and sample size

David Kaiser 2018/02/23

Description

A function to calculate the t-statistic and the p-value from the means, standard deviations, and sample size of two groups. The sample size can be equal or not equal but two values need to be supplied. The t-statistic, the variance of the two groups and the degrees of freedom are calculated as described in wikipedia. The p-value is calculated as described in a post by Kelly Black.

Arguments

  • mean1 -- mean value of group 1
  • mean2 -- mean value of group 2
  • sd1 -- standard deviation of group 1
  • sd2 -- standard deviation of group 2
  • n1 -- sample size of group 1
  • n2 -- sample size of group 2
  • equal.variance -- logical; are group variances assumed to be equal? defaults to FALSE

Value

A named list in which

  • "diff" = difference between the means
  • "var" = variance of the two groups
  • "t" = t-statistic
  • "df" = degrees of freedom
  • "p" = p-value

Example

a <- rnorm(100)
b <- rnorm(200)
t.test.mean.sd(mean(a), mean(b), sd(a), sd(b), length(a), length(b))
## $diff
## [1] -0.0008404071
## 
## $var
## [1] 0.1125538
## 
## $t
## [1] -0.007466716
## 
## $df
## [1] 182.0833
## 
## $p
## [1] 0.9940507
mean(a) - mean(b)
## [1] -0.0008404071
t.test(a, b)
## 
##  Welch Two Sample t-test
## 
## data:  a and b
## t = -0.0074667, df = 235.49, p-value = 0.994
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.2225814  0.2209006
## sample estimates:
##   mean of x   mean of y 
## 0.004289820 0.005130227

t_test_means_sds's People

Contributors

davidatlarge avatar

Watchers

 avatar

Forkers

markolipka

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.