wtd.t.test: Produces weighted Student's t-tests with standard errors and...

Description Usage Arguments Value Author(s) See Also Examples

View source: R/wtd.t.test.r

Description

wtd.t.test produces either one- or two-sample t-tests comparing weighted data streams to one another. Note that weights run with the default parameters here treat the weights as an estimate of the precision of the information. For survey data, users should run this code with bootstrapped standard errors bootse=TRUE, which are robust to heteroskadesticity, although these will vary slightly each time the weights are run. A prior version of this software was set to default to mean1=FALSE and bootse=FALSE.

Usage

1
2
3
wtd.t.test(x, y=0, weight=NULL, weighty=NULL, samedata=TRUE,
alternative="two.tailed", mean1=TRUE, bootse=FALSE, bootp=FALSE,
bootn=1000, drops="pairwise")

Arguments

x

x is a numerical vector which the researcher wishes to test against y.

y

y can be either a single number representing an alternative hypothesis or a second numerical vector which the researcher wishes to compare against x.

weight

weight is an optional vector of weights to be used to determine the weighted mean and variance for the x vector for all t-tests. If weighty is unspecified and samedata is TRUE, this weight will be assumed to apply to both x and y.

weighty

weighty is an optional vector of weights to be used to determine the weighted mean and variance for the y vector for two-sample t-tests. If weighty is unspecified and samedata is TRUE, this weight will be assumed to equal weightx. If weighty is unspecified and samedata is FALSE, this weight will be assumed to equal 1 for all cases.

samedata

samedata is an optional identifier for whether the x and y data come from the same data stream for a two-sample test. If true, wtd.t.test assumes that weighty should equal weightx if (1) weighty is unspecified, and (2) the lengths of the two vectors are identical.

alternative

alternative is an optional marker for whether one or two-tailed p-values shoould be returned. By default, two-tailed values will be returned (type="two.tailed"). To set to one-tailed values, alternative can be set to type="greater" to test x>y or type="less" to test x<y.

mean1

mean1 is an optional parameter for determining whether the weights should be forced to have an average value of 1. If this is set as false, the weighted correlations will be produced with the assumption that the true N of the data is equivalent to the sum of the weights.

bootse

bootse is an optional parameter that produces bootstrapped standard errors. This should be used to address heteroskadesticity issues when weights indicate probabilities of selection rather than the precision of estimates.

bootp

bootp is an optional parameter that produces bootstrapped p values instead of estimating p values from the standard errors. This parameter only operates when bootse=TRUE.

bootn

bootn is an optional parameter that is used to indicate the number of bootstraps that should be run for bootse and bootp.

drops

drops is set to limit a t-test on the same data to cases with nonmissing data for x, y, and weights (if specified). If drops is anything other than "pairwise", means for x and y are calculated on all available data rather than data that are available for both x and y. This parameter does nothing if x and y are not from the same dataset.

Value

A list element with an identifier for the test; coefficients for the t value, degrees of freedom, and p value of the t-test; and additional statistics of potential interest.

Author(s)

Josh Pasek, Assistant Professor of Communication Studies at the University of Michigan (www.joshpasek.com). Gene Culter added code for a one-tailed version of the test.

See Also

stdz wtd.cor wtd.chi.sq

Examples

1
2
3
4
5
6
7
test <- c(1,1,1,1,1,1,2,2,2,3,3,3,4,4)
t2 <- rev(test)+1
weight <- c(.5,.5,.5,.5,.5,1,1,1,1,2,2,2,2,2)

wtd.t.test(test, t2)
wtd.t.test(test, t2, weight)
wtd.t.test(test, t2, weight, bootse=TRUE)

Example output

Loading required package: Hmisc
Loading required package: lattice
Loading required package: survival
Loading required package: Formula
Loading required package: ggplot2

Attaching package: 'Hmisc'

The following objects are masked from 'package:base':

    format.pval, units

Loading required package: gdata
sh: 1: cannot create /dev/null: Permission denied
gdata: Unable to locate valid perl interpreter
gdata: 
gdata: read.xls() will be unable to read Excel XLS and XLSX files
gdata: unless the 'perl=' argument is used to specify the location of a
gdata: valid perl intrpreter.
gdata: 
gdata: (To avoid display of this message in the future, please ensure
gdata: perl is installed and available on the executable search path.)
sh: 1: cannot create /dev/null: Permission denied
gdata: Unable to load perl libaries needed by read.xls()
gdata: to support 'XLX' (Excel 97-2004) files.

gdata: Unable to load perl libaries needed by read.xls()
gdata: to support 'XLSX' (Excel 2007+) files.

gdata: Run the function 'installXLSXsupport()'
gdata: to automatically download and install the perl
gdata: libaries needed to support Excel XLS and XLSX formats.

Attaching package: 'gdata'

The following object is masked from 'package:stats':

    nobs

The following object is masked from 'package:utils':

    object.size

The following object is masked from 'package:base':

    startsWith

Loading required package: mice

Attaching package: 'mice'

The following objects are masked from 'package:base':

    cbind, rbind

$test
[1] "Two Sample Weighted T-Test (Welch)"

$coefficients
   t.value         df    p.value 
-2.3185184 26.0000000  0.0285483 

$additional
Difference     Mean.x     Mean.y   Std. Err 
-1.0000000  2.0714286  3.0714286  0.4313099 

$test
[1] "Two Sample Weighted T-Test (Welch)"

$coefficients
   t.value         df    p.value 
 0.2357023 25.1885350  0.8155696 

$additional
Difference     Mean.x     Mean.y   Std. Err 
0.09090909 2.63636364 2.54545455 0.38569461 

$test
[1] "Two Sample Weighted T-Test (Welch)"

$coefficients
   t.value         df    p.value 
 0.2538813 25.1885350  0.8016482 

$additional
Difference     Mean.x     Mean.y   Std. Err 
0.09090909 2.63636364 2.54545455 0.35807711 

weights documentation built on June 11, 2021, 1:06 a.m.

Related to wtd.t.test in weights...