Learn R Programming

lessR (version 2.1.1)

stats.ttest: Generic Method for One- or Two-Sample t-test from Summary Statistics

Description

Performs the two-tailed t-test and confidence interval for either one or two samples (groups) of the mean or mean difference, respectively, from sample statistics. For two groups, performs the independent-groups t-test assuming equal group population variances and a null hypothesis of zero. The comparison of means is accomplished from the six basic summary statistics, the sample size, sample mean and sample standard deviation for each group. Displays the basic t-value and p-value and also many of the intermediate computations, such as, for two groups, the within-group or pooled standard deviation. Also displays the standardized mean difference for the two-sample t-test.

Usage

stats.ttest(n = NULL, m = NULL, s = NULL, mu0 = NULL, 
         n1 = NULL, n2 = NULL,  m1 = NULL, m2 = NULL, s1 = NULL, s2 = NULL, 
         Ynm = "Y", Xnm = "X", X1nm = "Group1", X2nm = "Group2", 
         conf.level = 0.95, digits.d = NULL, ...)

Arguments

n
Sample size for one group.
m
Sample size for one group.
s
Sample size for one group.
mu0
Hypothesized mean for one group. If not present, then confidence interval only.
n1
Sample size for first of two groups.
n2
Sample size for second of two groups.
m1
Sample mean for first of two groups.
m2
Sample mean for second of two groups.
s1
Sample standard deviation for first of two groups.
s2
Sample standard deviation for second of two groups.
Ynm
Name of response variable.
Xnm
Name of predictor variable for two groups, the grouping variable or factor with exactly two levels.
X1nm
Value of grouping variable, the level that defines the first of two groups.
X2nm
Value of grouping variable, the level that defines the second of two groups.
conf.level
Confidence level of the interval, expressed as a proportion.
digits.d
Number of decimal digits for which to display numeric values. Suggestion only.
...
Further arguments to be passed to or from methods.

Details

This function parallels the ttest function included in this package, which performs the independent-groups t-test from the data, as well as the standard t.test function. In contrast, stats.ttest performs the analysis from the basic summary statistics: the sample size, sample mean and sample standard deviation for either one group or for each of two groups. Accordingly, there is no graphic output from this function as with ttest.

This version of stats.ttest assumes homogeneity of variance in the computation of the standard error of the mean difference. Also, only a two-sided test is provided. The null hypothesis is a population mean difference of 0.

If the sample size, sample mean and sample standard deviation are presented only for one group, then the hypothesized value should be specified with the mu0 parameter. If not specfied for one group, then the hypothesis is not done and only the confidence interval is reported. For two groups, the null hypothesis for the population mean difference is assumed to be zero.

The number of decimal digits is determined by default from the largest number of decimal digits of the entered descriptive statistics. The number of decimal digits is then set at that value, plus one more. Or, override the default with the digits.d parameter.

See Also

ttest, t.test.

Examples

Run this code
# two-groups
# null hypothesis mean difference is zero
stats.ttest(n1=19, n2=15, m1=9.5, m2=8, s1=1.4, s2=1.5, 
           Ynm="Time", Xnm="Gender", X1nm="Men", X2nm="Women", 
           conf.level=0.95, digits.d=2)

# one-group
stats.ttest(n=25, m=350.86, s=2.66, mu0=350, Ynm="Weight")

Run the code above in your browser using DataLab