# ----------------------------------------------------------
# call tt with 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 <- rnorm(n=n, mean=50, sd=10)
mydata <- data.frame(X,Y)
# analyze data with formula version
# variable names and levels of X are automatically obtained from data
# although data frame is not attached, can reference the variable
# names directly
tt(Y ~ X)
# brief version of results
tt.brief(Y ~ X)
# Compare to standard R function t.test
t.test(Y ~ X, var.equal=TRUE)
# consider the practical importance of the difference
tt(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(dat.twogroup)
tt(ShipTime ~ Supplier, dframe=dat.twogroup)
# ----------------------------------------------------------
# tt for a single group
# ----------------------------------------------------------
# confidence interval only, from data
tt(Y)
# confidence interval and hypothesis test, from data
tt(Y, mu0=52)
# confidence interval only, from descriptive stats
tt(n=34, m=8.92, s=1.67)
# confidence interval and hypothesis test, from descriptive stats
tt(n=34, m=8.92, s=1.67, mu0=9)
# -------------------------------------------------------
# tt 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
n <- 10
Y1 <- rnorm(n=n/2, mean=50, sd=10)
Y2 <- rnorm(n=n/2, mean=60, sd=10)
# analyze the two vectors directly
# usually explicitly specify variable names and levels of X
# to enhance the readability of the output
tt(Y1, Y2, Ynm="MyY", Xnm="MyX", X1nm="Group1", X2nm="Group2")
# -------------------------------------------------------
# analysis proceeds 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")
# 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