ttest: T-test with Improved Layout

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Produces table of relevant descriptive statistics and inference for either one- or two-sample t-test. In the two-sample case, the user can specify whether or not observations are matched, and whether or not equal variances should be presumed. Can also perform a test of equality of proportions (Wald based or exact binomial based).

Usage

1
2
3
4
## S3 method for class "ttest"
ttest(var1, var2 = NA, by = NA, strat=NULL, geom=FALSE, prop=FALSE,
        exact=FALSE, null.hypoth = 0, test.type = "two.sided", 
        var.eq = FALSE, conf.level = 0.95, matched = FALSE, more.digits = 0)

Arguments

var1

a (non-empty) numeric vector of data values.

var2

an optional (non-empty) numeric vector of data.

by

a variable of equal length to that of var1 with two outcomes. This will be used to define strata for a t-test on var1.

strat

a variable to use instead of by. However, using by instead is recommended.

geom

a logical indicating whether the geometric mean should be calculated and displayed.

prop

if TRUE, performs a test of equality of proportions with Wald based confidence intervals.

exact

must be FALSE if prop=FALSE. If true, performs a test of equality of proportions with Exact Binomial based confidence intervals.

null.hypoth

a number specifying the null hypothesis for the mean (or difference in means if performing a two-sample test). Defaults to zero.

test.type

a string: one of "less", "two.sided", or "greater" specifying the form of the test. Defaults to a two-sided test.

var.eq

a logical value, either TRUE or FALSE (default), specifying whether or not equal variances should be presumed in a two-sample t-test. Also controls robust standard errors.

conf.level

confidence level of the test. Defaults to 95/100.

matched

a logical value, either TRUE or FALSE, indicating whether or not the variables of a two-sample t-test are matched. Variables must be of equal length.

more.digits

a numeric value specifying whether or not to display more or fewer digits in the output. Non-integers are automatically rounded down. Any call to ttest() will run ttest.default(), with user specified values in place of the appropriate defaults.

...

only used in the generic S3 class.

Details

Missing values must be given by "NA"s to be recognized as missing values. Any call to ttest() is run by ttest.default(), with user specified values in place of defaults in the appropriate places.

Value

Prints a summary of the data and the corresponding t-test.

Variable

the variable name supplied to the t-test function

Group

the group name: either the variable names supplied to the function or the names of the strata if the variable by was specified.

Obs

Number of observations of each variable: includes missing values.

Missing

number of missing values in each data vector.

Mean

the sample mean of each data vector; also, the estimated difference in means in a two-sample test.

Std.Err.

the estimated standard error of the mean and of the difference in the two-sample test.

Std.Dev.

standard deviation estimates from the data.

CI

a confidence interval for the means, and for the difference in the two-sample test. This is at the confidence level specified in the argument. If prop and/or exact are TRUE, also returns the appropriate confidence interval for the test of equality of proportions.

Null hypothesis

a statement of the null hypothesis.

Alternative hypothesis

a statement of the alternative hypothesis.

t

value of the t-statistic.

df

the degrees of freedom for the test.

Pr

a p-value for inference on the corresponding hypothesis test.

Author(s)

Scott S. Emerson, M.D., Ph.D., Andrew J. Spieker, Brian D. Williamson, Travis Y. Hee Wai, Solomon Lim

See Also

t.test

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#- Read in data set -#
psa <- read.table("http://www.emersonstatistics.com/datasets/psa.txt", header=TRUE)
attach(psa)

#- Perform t-test -#
ttest(pretxpsa, null.hypoth = 100, test.type = "greater", more.digits = 1)

#- Define new binary variable as indicator -#
#- of whether or not bss was worst possible -#
bssworst <- bss
bssworst[bss == 1] <- 0
bssworst[bss == 2] <- 0
bssworst[bss == 3] <- 1

#- Perform t-test allowing for unequal -#
#- variances between strata -#
ttest(pretxpsa, by = bssworst)

#- Perform matched t-test -#
ttest(pretxpsa, nadirpsa, matched = TRUE, conf.level = 99/100, more.digits = 1)

uwIntroStats documentation built on May 2, 2019, 4:34 a.m.