R: Confidence intervals for differences of Simpson indices
Simpsonci
R Documentation
Confidence intervals for differences of Simpson indices
Description
Calculates simultaneous and local confidence intervals for differences of Simpson indices under the assumption of multinomial count data.
Usage
Simpsonci(X, f, cmat = NULL, type = "Dunnett",
alternative = "two.sided", conf.level = 0.95, dist = "MVN", ...)
Arguments
X
a data.frame of dimensions n times p with integer entries, where n is the number of samples and p is the number of species
f
a factor variable of length n, grouping the observations in X
cmat
an contrast matrix; the number of columns should match the number of levels in f
type
a single character string, currently one of "Dunnett","Tukey","Sequen"
alternative
a single character string, one of "two.sided","less" (upper bounds),"greater" (lower bounds)
conf.level
the confidence level of the simultaneous (or local) confidence intervals
dist
a single character string, defining the type of quantiles to be used for interval calculation; "MVN" invokes simultaneous intervals, "N" invokes unadjusted confidence intervals with coverage probability conf.level for each of them
...
further arguments to be passed; currently only base is used,a single integer value, specifying which group to be taken as the control in case that type="Dunnett", ignored otherwise
Details
This function implements confidence intervals described by Rogers and Hsu (1999) for the difference of Shannon indices between several groups. Deviating from Fritsch and Hsu, quantiles of the multivariate normal distribution based on a plug-in-estamator for the correlation matrix.
Note, that this approach, by assuming multinomial distribution for the vectors of counts, ignores the variability of the individual samples. If such extra-multinomial variatio is present in the data, the intervals will be too narrow, coverage probability will be substantially lower than specified in 'conf.level'. Consider approaches based on bootstrap instead (e.g., package simboot).
Value
A list containing the elements:
conf.int
a matrix, containing the lower and upper confidence limits in the columns
quantile
a single numeric value, the quantile used for interval calculation
estimate
a matrix,containing the point estimates of the contrasts in its column
cmat
the contrast matrix used
methodname
a character string, for printing
sample.estimate
A list of sample estimates as returned by estShannonf
and some of the input arguments.
Author(s)
Frank Schaarschmidt
References
Rogers, JA and Hsu, JC (2001): Multiple Comparisons of Biodiversity. Biometrical Journal 43, 617-625.
See Also
Shannonci
Examples
data(HCD)
HCDcounts<-HCD[,-1]
HCDf<-HCD[,1]
# Rogers and Hsu (2001), Table 2:
# All pair wise comparisons:
Simpsonci(X=HCDcounts, f=HCDf, type = "Tukey",
conf.level = 0.95, dist = "MVN")
# Rogers and Hsu (2001), Table 3:
# Comparison to the lower cretaceous:
Simpsonci(X=HCDcounts, f=HCDf, type = "Dunnett",
alternative = "less", conf.level = 0.95, dist = "MVN")
# Note, that the confidence bounds here differ
# from the bounds in Rogers and Hsu (2001)
# in the second digit, whenever the group Upper
# is involved in the comparison.
# Stepwise comparison between the strata:
SimpsonS<-Simpsonci(X=HCDcounts, f=HCDf, type = "Sequen",
alternative = "greater", conf.level = 0.95, dist = "MVN")
SimpsonS
summary(SimpsonS)
plot(SimpsonS)
# # # Hell Creek Dinosaur data:
# Is there a downward trend in biodiversity during the
# Creataceous period?
# A trend test based on multiple contrasts:
cmatTREND<-rbind(
"U-LM"=c(-0.5,-0.5,1),
"MU-L"=c(-1,0.5,0.5),
"U-L"=c(-1,0,1)
)
TrendCI<-Simpsonci(X=HCDcounts, f=HCDf, cmat=cmatTREND,
alternative = "greater", conf.level = 0.95, dist = "MVN")
TrendCI
plot(TrendCI)
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(MCPAN)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/MCPAN/Simpsonci.Rd_%03d_medium.png", width=480, height=480)
> ### Name: Simpsonci
> ### Title: Confidence intervals for differences of Simpson indices
> ### Aliases: Simpsonci
> ### Keywords: htest
>
> ### ** Examples
>
>
> data(HCD)
>
> HCDcounts<-HCD[,-1]
> HCDf<-HCD[,1]
>
> # Rogers and Hsu (2001), Table 2:
> # All pair wise comparisons:
>
> Simpsonci(X=HCDcounts, f=HCDf, type = "Tukey",
+ conf.level = 0.95, dist = "MVN")
Simultaneous 95 percent-confidence intervals
for differences of Simpson indices
estimate lower upper
Middle - Lower 0.0353 -0.1597 0.2303
Upper - Lower -0.0151 -0.2209 0.1908
Upper - Middle -0.0504 -0.1556 0.0548
>
> # Rogers and Hsu (2001), Table 3:
> # Comparison to the lower cretaceous:
>
> Simpsonci(X=HCDcounts, f=HCDf, type = "Dunnett",
+ alternative = "less", conf.level = 0.95, dist = "MVN")
Simultaneous 95 percent-confidence intervals
for differences of Simpson indices
estimate lower upper
Middle - Lower 0.0353 -Inf 0.1885
Upper - Lower -0.0151 -Inf 0.1466
>
>
> # Note, that the confidence bounds here differ
> # from the bounds in Rogers and Hsu (2001)
> # in the second digit, whenever the group Upper
> # is involved in the comparison.
>
>
> # Stepwise comparison between the strata:
>
> SimpsonS<-Simpsonci(X=HCDcounts, f=HCDf, type = "Sequen",
+ alternative = "greater", conf.level = 0.95, dist = "MVN")
>
> SimpsonS
Simultaneous 95 percent-confidence intervals
for differences of Simpson indices
estimate lower upper
Middle - Lower 0.0353 -0.1296 Inf
Upper - Middle -0.0504 -0.1393 Inf
> summary(SimpsonS)
Data:
Cr Ha Hy Pa Ty Or Sa Dr
Lower 19 7 1 0 2 0 3 0
Middle 53 51 2 0 3 8 6 0
Upper 50 29 3 0 3 4 1 0
Summary statistics:
Lower Middle Upper
Total number of individuals 32.0000 123.0000 90.0000
Estimated Simpson index 0.6048 0.6401 0.5898
Variance estimate 0.0065 0.0006 0.0014
Contrast matrix:
Multiple Comparisons of Means: Sequen Contrasts
Lower Middle Upper
Middle - Lower -1 1 0
Upper - Middle 0 -1 1
Simultaneous 95 percent-confidence intervals
for differences of Simpson indices
estimate lower upper
Middle - Lower 0.0353 -0.1296 Inf
Upper - Middle -0.0504 -0.1393 Inf
>
> plot(SimpsonS)
>
> # # # Hell Creek Dinosaur data:
> # Is there a downward trend in biodiversity during the
> # Creataceous period?
>
> # A trend test based on multiple contrasts:
>
> cmatTREND<-rbind(
+ "U-LM"=c(-0.5,-0.5,1),
+ "MU-L"=c(-1,0.5,0.5),
+ "U-L"=c(-1,0,1)
+ )
>
> TrendCI<-Simpsonci(X=HCDcounts, f=HCDf, cmat=cmatTREND,
+ alternative = "greater", conf.level = 0.95, dist = "MVN")
> TrendCI
Simultaneous 95 percent-confidence intervals
for differences of Simpson indices
estimate lower upper
U-LM -0.0327 -0.1378 Inf
MU-L 0.0101 -0.1448 Inf
U-L -0.0151 -0.1799 Inf
>
> plot(TrendCI)
>
>
>
>
>
>
>
> dev.off()
null device
1
>