Skip to content

Instantly share code, notes, and snippets.

@wulingyun
Created June 19, 2016 12:43
Show Gist options
  • Select an option

  • Save wulingyun/aff10747a268d7cbd0efb151b89dc3f7 to your computer and use it in GitHub Desktop.

Select an option

Save wulingyun/aff10747a268d7cbd0efb151b89dc3f7 to your computer and use it in GitHub Desktop.
Calculate normal test
# one sample normal test
norm_test1 <- function(x.n, x.mu, x.var, mu, side=0)
{
nu <- x.n - 1
z <- (x.mu - mu) / sqrt(x.var / x.n)
p <- p.value(pnorm, z, side=side)
data.frame(mean=x.mu, df=nu, statistic=z, p.value=p)
}
# two samples normal test
norm_test2 <- function(x.n, x.mu, x.var, y.n, y.mu, y.var, side=0)
{
mu <- x.mu - y.mu
nu <- x.n + y.n
z <- mu / sqrt(x.var/x.n + y.var/y.n)
p <- p.value(pnorm, z, side=side)
data.frame(mean=mu, df=nu, statistic=z, p.value=p)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment