Last data update: 2014.03.03

R: Function to compute the fuzzy Student t test based on...
fuzzy.ttestR Documentation

Function to compute the fuzzy Student t test based on weighted mean and weighted variance

Description

This function allows for computing the weighted mean and weighted variance of a vector of continuous values.

Usage

fuzzy.ttest(x, w1, w2, alternative=c("two.sided", "less", "greater"), 
check.w = TRUE, na.rm = FALSE)

Arguments

x

an object containing the observed values.

w1

a numerical vector of weights of the same length as x giving the weights to use for elements of x in the first class.

w2

a numerical vector of weights of the same length as x giving the weights to use for elements of x in the second class.

alternative

a character string specifying the alternative hypothesis, must be one of "two.sided" (default), "greater" or "less". You can specify just the initial letter.

check.w

TRUE if weights should be checked such that 0 <= w <= 1 and (w1[i] + w2[i]) < 1 for 1 <= i <= length(x), FALSE otherwise. Beware that weights greater than one may inflate over-optimistically resulting p-values, use with caution.

na.rm

TRUE if missing values should be removed, FALSE otherwise.

Details

The weights w1 and w2 should represent the likelihood for each observation stored in x to belong to the first and second class, respectively. Therefore the values contained in w1 and w2 should lay in [0,1] and 0 <= (w1[i] + w2[i]) <= 1 for i in {0,1,...,n} where n is the length of x.

The Welch's version of the t test is implemented in this function, therefore assuming unequal sample size and unequal variance. The sample size of the first and second class are calculated as the sum(w1) and sum(w2), respectively.

Value

A numeric vector of six values that are the difference between the two weighted means, the value of the t statistic, the sample size of class 1, the sample size of class 2, the degree of freedom and the corresponding p-value.

Author(s)

Benjamin Haibe-Kains

References

http://en.wikipedia.org/wiki/T_test

See Also

weighted.mean

Examples

set.seed(54321)
## random generation of 50 normally distributed values for each of the two classes
xx <- c(rnorm(50), rnorm(50)+1)
## fuzzy membership to class 1
ww1 <- runif(50) + 0.3
ww1[ww1 > 1] <- 1
ww1 <- c(ww1, 1 - ww1)
## fuzzy membership to class 2
ww2 <- 1 - ww1
## Welch's t test weighted by fuzzy membership to class 1 and 2 
wt <- fuzzy.ttest(x=xx, w1=ww1, w2=ww2)
print(wt)
## Not run: 
## permutation test to compute the null distribution of the weighted t statistic
wt <- wt[2]
rands <- t(sapply(1:1000, function(x,y) { return(sample(1:y)) }, y=length(xx)))
randst <- apply(rands, 1, function(x, xx, ww1, ww2) 
{ return(fuzzy.ttest(x=xx, w1=ww1[x], w2=ww2[x])[2]) }, xx=xx, ww1=ww1, ww2=ww2)
ifelse(wt < 0, sum(randst <= wt), sum(randst >= wt)) / length(randst)

## End(Not run)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(genefu)
Loading required package: survcomp
Loading required package: survival
Loading required package: prodlim
Loading required package: mclust
Package 'mclust' version 5.2
Type 'citation("mclust")' for citing this R package in publications.
Loading required package: limma
Loading required package: biomaRt
Loading required package: iC10
Loading required package: pamr
Loading required package: cluster
Loading required package: iC10TrainingData
Loading required package: AIMS
Loading required package: e1071
Loading required package: Biobase
Loading required package: BiocGenerics
Loading required package: parallel

Attaching package: 'BiocGenerics'

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

    clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
    clusterExport, clusterMap, parApply, parCapply, parLapply,
    parLapplyLB, parRapply, parSapply, parSapplyLB

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

    plotMA

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

    IQR, mad, xtabs

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

    Filter, Find, Map, Position, Reduce, anyDuplicated, append,
    as.data.frame, cbind, colnames, do.call, duplicated, eval, evalq,
    get, grep, grepl, intersect, is.unsorted, lapply, lengths, mapply,
    match, mget, order, paste, pmax, pmax.int, pmin, pmin.int, rank,
    rbind, rownames, sapply, setdiff, sort, table, tapply, union,
    unique, unsplit

Welcome to Bioconductor

    Vignettes contain introductory material; view with
    'browseVignettes()'. To cite Bioconductor, see
    'citation("Biobase")', and for packages 'citation("pkgname")'.

> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/genefu/fuzzy.ttest.Rd_%03d_medium.png", width=480, height=480)
> ### Name: fuzzy.ttest
> ### Title: Function to compute the fuzzy Student t test based on weighted
> ###   mean and weighted variance
> ### Aliases: fuzzy.ttest
> ### Keywords: htest
> 
> ### ** Examples
> 
> set.seed(54321)
> ## random generation of 50 normally distributed values for each of the two classes
> xx <- c(rnorm(50), rnorm(50)+1)
> ## fuzzy membership to class 1
> ww1 <- runif(50) + 0.3
> ww1[ww1 > 1] <- 1
> ww1 <- c(ww1, 1 - ww1)
> ## fuzzy membership to class 2
> ww2 <- 1 - ww1
> ## Welch's t test weighted by fuzzy membership to class 1 and 2 
> wt <- fuzzy.ttest(x=xx, w1=ww1, w2=ww2)
> print(wt)
       diff     t.value          n1          n2          df     p.value 
-0.46562992 -2.10753749 50.00000000 50.00000000 97.37120588  0.03763985 
> ## Not run: 
> ##D ## permutation test to compute the null distribution of the weighted t statistic
> ##D wt <- wt[2]
> ##D rands <- t(sapply(1:1000, function(x,y) { return(sample(1:y)) }, y=length(xx)))
> ##D randst <- apply(rands, 1, function(x, xx, ww1, ww2) 
> ##D { return(fuzzy.ttest(x=xx, w1=ww1[x], w2=ww2[x])[2]) }, xx=xx, ww1=ww1, ww2=ww2)
> ##D ifelse(wt < 0, sum(randst <= wt), sum(randst >= wt)) / length(randst)
> ## End(Not run)
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>