@@ -50,24 +50,28 @@ calc_chao1 = function(x) {
50
50
51
51
# ' Calculate probability of interspecific encounter (PIE)
52
52
# '
53
- # ' \code{calc_PIE} returns the probability of interspecific encounter (PIE)
53
+ # ' \code{calc_PIE} returns the probability of interspecific encounter (PIE)
54
54
# ' which is also known as Simpson's evenness index and Gini-Simpson index.
55
55
# '
56
- # ' Per default, Hurlbert's (1971) sample-size corrected formula is used:
56
+ # ' By default, Hurlbert's (1971) sample-size corrected formula is used:
57
57
# '
58
58
# ' \eqn{PIE = N /(N - 1) * (1 - sum(p_i^2))}
59
59
# '
60
- # ' where N is the total number of individuals and \eqn{p_i} is the relative abundance
61
- # ' of species i. This formulation uses sampling without replacement (\code{replace = F} )
62
- # ' For the uncorrected version (i.e. using sampling with replacement), set \code{replace = T}.
63
- # '
64
- # ' In earlier versions of \code{mobr}, there was an additional argument (\code{ENS}) for
65
- # ' the conversion into an effective number of species (i.e S_PIE). Now, \code{calc_SPIE} has become
66
- # ' its own function and the (\code{ENS}) argument is no longer supported . Please, use \code{calc_SPIE} instead.
67
- # '
60
+ # ' where N is the total number of individuals and \eqn{p_i} is the relative
61
+ # ' abundance of species i. This formulation uses sampling without replacement
62
+ # ' (\code{replace = F} ) For sampling with replacement (i.e., the sample-size
63
+ # ' uncorrected version), set \code{replace = T}.
64
+ # '
65
+ # ' In earlier versions of \code{mobr}, there was an additional argument
66
+ # ' (\code{ENS}) for the conversion into an effective number of species (i.e
67
+ # ' S_PIE). Now, \code{calc_SPIE} has become its own function and the
68
+ # ' (\code{ENS}) argument is no longer supported . Please, use \code{calc_SPIE}
69
+ # ' instead.
70
+ # '
68
71
# '
69
72
# ' @inheritParams rarefaction
70
- # ' @param replace if TRUE, sampling with replacement is used. Otherwise, sampling without replacement (default).
73
+ # ' @param replace if TRUE, sampling with replacement is used. Otherwise,
74
+ # ' sampling without replacement (default).
71
75
# '
72
76
# ' @author Dan McGlinn, Thore Engel
73
77
# '
@@ -79,11 +83,13 @@ calc_chao1 = function(x) {
79
83
# ' @examples
80
84
# ' data(inv_comm)
81
85
# ' calc_PIE(inv_comm)
82
- # ' calc_PIE(c(23,21,12,5,1,2,3), replace=TRUE)
83
- calc_PIE = function (x , replace = FALSE , ... ) {
86
+ # ' calc_PIE(inv_comm, replace = TRUE)
87
+ # ' calc_PIE(c(23,21,12,5,1,2,3))
88
+ # ' calc_PIE(c(23,21,12,5,1,2,3), replace = TRUE)
89
+ calc_PIE = function (x , replace = FALSE , ... ) {
84
90
85
91
args = as.list(match.call())
86
- if ( any(names(args ) == " ENS" ))
92
+ if (any(names(args ) == " ENS" ))
87
93
stop(" The ENS argumet was removed from this function. Please, use calc_SPIE() for the ENS transformation of PIE. " )
88
94
89
95
if (' mob_in' %in% class(x )) {
@@ -93,7 +99,7 @@ calc_PIE = function(x, replace=FALSE, ...) {
93
99
if (any(x < 0 , na.rm = TRUE ))
94
100
stop(" input data must be non-negative" )
95
101
96
- if (any(x %% 1 != 0 , na.rm = TRUE ))
102
+ if (any(x %% 1 != 0 , na.rm = TRUE ))
97
103
stop(" input data must be integers" )
98
104
99
105
if (length(dim(x )) > 1 ) {
@@ -113,47 +119,58 @@ calc_PIE = function(x, replace=FALSE, ...) {
113
119
}
114
120
115
121
# calculate PIE without replacement (for total >= 2)
116
- if (replace ){
117
- PIE = 1 - H
122
+ if (replace ) {
123
+ PIE = 1 - H
118
124
} else {
119
125
PIE = total / (total - 1 ) * (1 - H )
120
126
}
121
- if (! replace ) PIE [total == 1 ] <- NA
122
- if (any(is.na(PIE ))) warning(" NA was returned because because the sample just contains one individual." )
127
+ # if sample had zero individuals set PIE to 0
128
+ PIE [total == 0 ] = 0
129
+ # if sample only contains 1 individual set PIE to NA
130
+ if (! replace )
131
+ PIE [total == 1 ] = NA
132
+ if (any(is.na(PIE )))
133
+ warning(" NA was returned because because the sample just contains one individual." )
123
134
124
135
return (PIE )
125
136
}
126
137
127
138
# ' Calculate S_PIE
128
- # '
129
- # ' S_PIE is the effective number transformation of the probability of interspecific encounter (PIE).
130
- # '
131
- # ' Per default the sample size corrected version is returned (\code{replace = F}), which is the asymptotic
132
- # ' estimator for the Hill number of diversity order q=2 (Chao et al, 2014). If \code{replace = T} the uncorrected
133
- # ' hill number is returned. This is the same as vegan::diversity(x, index="invsimpson").
134
- # '
139
+ # '
140
+ # ' S_PIE is the effective number of species transformation of the probability of
141
+ # ' interspecific encounter (PIE) which is equal to the number of equally common
142
+ # ' species that result in that value of PIE.
143
+ # '
144
+ # ' By default the sample size corrected version is returned (\code{replace =
145
+ # ' F}), which is the asymptotic estimator for the Hill number of diversity order
146
+ # ' q=2 (Chao et al, 2014). If \code{replace = T} the uncorrected hill number is
147
+ # ' returned. This is the same as vegan::diversity(x, index="invsimpson").
148
+ # '
135
149
# '
136
150
# ' @inheritParams calc_PIE
137
151
# ' @return
138
152
# ' @export
139
153
# '
140
154
# ' @references
141
- # ' Chao, A., Gotelli, N. J., Hsieh, T. C., Sander, E. L., Ma, K. H., Colwell, R. K., & Ellison, A. M. (2014).
142
- # ' Rarefaction and extrapolation with Hill numbers: A framework for sampling and estimation in species diversity studies.
143
- # ' Ecological Monographs 84(1), 45-67.
155
+ # ' Chao, A., Gotelli, N. J., Hsieh, T. C., Sander, E. L., Ma, K. H., Colwell, R.
156
+ # ' K., & Ellison, A. M. (2014). Rarefaction and extrapolation with Hill numbers:
157
+ # ' A framework for sampling and estimation in species diversity studies.
158
+ # ' Ecological Monographs 84(1), 45-67.
144
159
# '
145
160
# ' @examples
146
161
# ' data(inv_comm)
147
162
# ' calc_SPIE(inv_comm)
163
+ # ' calc_SPIE(inv_comm, replace = TRUE)
148
164
# ' calc_SPIE(c(23,21,12,5,1,2,3), replace=TRUE)
149
- calc_SPIE = function (x , replace = F ){
150
- PIE = calc_PIE(x , replace = replace )
151
- SPIE = 1 / (1 - PIE )
152
- SPIE [PIE == 1 ]= NA
153
- if (any(PIE == 1 , na.rm = T )) warning(" NA was returned because PIE = 1. This happens in samples where all species are singletons." )
165
+ calc_SPIE = function (x , replace = F ) {
166
+ PIE = calc_PIE(x , replace = replace )
167
+ SPIE = 1 / (1 - PIE )
168
+ SPIE [PIE == 0 ] = 0
169
+ SPIE [PIE == 1 ] = NA
170
+ if (any(PIE == 1 , na.rm = T ))
171
+ warning(" NA was returned because PIE = 1. This happens in samples where all species are singletons." )
154
172
155
173
return (SPIE )
156
-
157
174
}
158
175
159
176
0 commit comments