Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cyrilobolonsky/e2ae55ad0b4d153d9540 to your computer and use it in GitHub Desktop.
Save cyrilobolonsky/e2ae55ad0b4d153d9540 to your computer and use it in GitHub Desktop.
A #glfintech R turorial on statistics discussing hypothesis tests - parametric tests (z-test, t-test and ANOVA) and non-parametric tests (Mann-Whitney Test, Wilcoxon Rank-sum test, Wilcoxon Signed-rank Test, Kruskal Wallis Test).
#Conducting t-tests in R.
t.test(death_rt)
t.test(lifeexpf, lifeexpm)
t.test(lifeexpf, lifeexpm, var.equal=T)
t.test(lifeexpf, lifeexpm, paired=T)
#A function for creating random examples of t-tests
ttest.for.examination <- function(x,y,z,k)
{
subjects <- x
mean1 <- y
mean2 <- z
standarddev <- k
print( c("Number of measurements: ", x))
print( c("Mean of group 1: ", y))
print( c( "Mean of group 2: ",z))
print( c("Standard deviation: ", k))
group1 <- round(rnorm(x, y, k))
group2 <- round(rnorm(x, z, k))
framedata <- cbind(group1, group2)
print(framedata)
print( list (t.test(group1, group2, var.equal = T), t.test(group1, group2, var.equal = T, paired = T)))
}
#Now you can run the new function.
ttest.for.examination(13,90,105,10)
ttest.for.examination(13,92,100,10)
#Try running the same arguments twice
ttest.for.examination(13,92,100,10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment