# ----------------------------------------------------------
# tt for two groups, from a formula
# ----------------------------------------------------------
# create simulated data, no population mean difference
# X has two values only, Y is numeric
# put into a data frame, required for formula version
n <- 12
X <- sample(c("Group1","Group2"), size=n, replace=TRUE)
Y <- round(rnorm(n=n, mean=50, sd=10),2)
mydata <- data.frame(X,Y)
rm(X); rm(Y)
# analyze data with formula version
# variable names and levels of X are automatically obtained from data
# although data frame not attached, reference variable names directly
ttest(Y ~ X)
# short form
tt(Y ~ X)
# brief version of results
tt.brief(Y ~ X)
# Compare to standard R function t.test
t.test(mydata$Y ~ mydata$X, var.equal=TRUE)
# consider the practical importance of the difference
ttest(Y ~ X, msmd=.5)
# variable of interest is in a data frame which is not the default mydata
# access the data frame in the lessR dat.twogroup data set
# although data not attached, access the variables directly by their name
data(dataGroups2)
ttest(ShipTime ~ Supplier, dframe=dataGroups2)
# -------------------------------------------------------
# tt for two groups from data stored in two vectors
# -------------------------------------------------------
# create two separate vectors of response variable Y
# the vectors exist are not in a data frame
# their lengths need not be equal
Y1 <- round(rnorm(n=10, mean=50, sd=10),2)
Y2 <- round(rnorm(n=8, mean=60, sd=10),2)
# analyze the two vectors directly
# usually explicitly specify variable names and levels of X
# to enhance the readability of the output
ttest(Y1, Y2, Ynm="MyY", Xnm="MyX", X1nm="Group1", X2nm="Group2")
# ----------------------------------------------------------
# tt for a single group, from data
# ----------------------------------------------------------
# confidence interval only, from data
ttest(Y)
# confidence interval and hypothesis test, from data
ttest(Y, mu0=52)
# -------------------------------------------------------
# tt from summary statistics
# -------------------------------------------------------
# one group: sample size, mean and sd
# optional variable name added
tt(n=34, m=8.92, s=1.67, Ynm="Time")
# confidence interval and hypothesis test, from descriptive stats
tt(n=34, m=8.92, s=1.67, mu0=9)
# two groups: sample size, mean and sd for each group
# specify the briefer form of the output
tt.brief(n1=19, m1=9.57, s1=1.45, n2=15, m2=8.09, s2=1.59)
Run the code above in your browser using DataLab