Generic function for calculating individual-level diversity.

inddiv(data, qs)

# S4 method for powermean
inddiv(data, qs)

# S4 method for relativeentropy
inddiv(data, qs)

# S4 method for metacommunity
inddiv(data, qs)

Arguments

data

matrix of mode numeric; containing diversity components

qs

vector of mode numeric containing q values

Value

inddiv() returns a standard output of class rdiv

Details

data may be input as three different classes:

  • power_mean: calculates raw and normalised subcommunity alpha, rho or gamma diversity by taking the powermean of diversity components

  • relativeentropy: calculates raw or normalised subcommunity beta diversity by taking the relative entropy of diversity components

  • metacommunity: calculates all subcommunity measures of diversity

References

Reeve, R., T. Leinster, C. Cobbold, J. Thompson, N. Brummitt, S. Mitchell, and L. Matthews. 2016. How to partition diversity. arXiv 1404.6520v3:1–9.

See also

subdiv for subcommunity-level diversity and metadiv for metacommunity-level diversity.

Examples

# Define metacommunity
pop <- cbind.data.frame(A = c(1,1), B = c(2,0), C = c(3,1))
row.names(pop) <- paste0("sp", 1:2)
pop <- pop/sum(pop)
meta <- metacommunity(pop)

# Calculate subcommunity gamma diversity (takes the power mean)
g <- raw_gamma(meta)
inddiv(g, 0:2)
#>    measure q type_level type_name partition_level partition_name diversity
#> 1    gamma 0       type       sp1    subcommunity              A  1.333333
#> 2    gamma 0       type       sp2    subcommunity              A  4.000000
#> 3    gamma 0       type       sp1    subcommunity              B  1.333333
#> 4    gamma 0       type       sp2    subcommunity              B  0.000000
#> 5    gamma 0       type       sp1    subcommunity              C  1.333333
#> 6    gamma 0       type       sp2    subcommunity              C  4.000000
#> 7    gamma 1       type       sp1    subcommunity              A  1.333333
#> 8    gamma 1       type       sp2    subcommunity              A  4.000000
#> 9    gamma 1       type       sp1    subcommunity              B  1.333333
#> 10   gamma 1       type       sp2    subcommunity              B  0.000000
#> 11   gamma 1       type       sp1    subcommunity              C  1.333333
#> 12   gamma 1       type       sp2    subcommunity              C  4.000000
#> 13   gamma 2       type       sp1    subcommunity              A  1.333333
#> 14   gamma 2       type       sp2    subcommunity              A  4.000000
#> 15   gamma 2       type       sp1    subcommunity              B  1.333333
#> 16   gamma 2       type       sp2    subcommunity              B  0.000000
#> 17   gamma 2       type       sp1    subcommunity              C  1.333333
#> 18   gamma 2       type       sp2    subcommunity              C  4.000000
#>    dat_id transformation normalised  k max_d
#> 1   naive             NA         NA NA    NA
#> 2   naive             NA         NA NA    NA
#> 3   naive             NA         NA NA    NA
#> 4   naive             NA         NA NA    NA
#> 5   naive             NA         NA NA    NA
#> 6   naive             NA         NA NA    NA
#> 7   naive             NA         NA NA    NA
#> 8   naive             NA         NA NA    NA
#> 9   naive             NA         NA NA    NA
#> 10  naive             NA         NA NA    NA
#> 11  naive             NA         NA NA    NA
#> 12  naive             NA         NA NA    NA
#> 13  naive             NA         NA NA    NA
#> 14  naive             NA         NA NA    NA
#> 15  naive             NA         NA NA    NA
#> 16  naive             NA         NA NA    NA
#> 17  naive             NA         NA NA    NA
#> 18  naive             NA         NA NA    NA

# Calculate subcommunity beta diversity (takes the relative entropy)
b <- raw_beta(meta)
inddiv(b, 0:2)
#>     measure q type_level type_name partition_level partition_name diversity
#> 1  raw beta 0       type       sp1    subcommunity              A 0.1666667
#> 2  raw beta 0       type       sp2    subcommunity              A 0.5000000
#> 3  raw beta 0       type       sp1    subcommunity              B 0.3333333
#> 4  raw beta 0       type       sp2    subcommunity              B       NaN
#> 5  raw beta 0       type       sp1    subcommunity              C 0.5000000
#> 6  raw beta 0       type       sp2    subcommunity              C 0.5000000
#> 7  raw beta 1       type       sp1    subcommunity              A 0.1666667
#> 8  raw beta 1       type       sp2    subcommunity              A 0.5000000
#> 9  raw beta 1       type       sp1    subcommunity              B 0.3333333
#> 10 raw beta 1       type       sp2    subcommunity              B       NaN
#> 11 raw beta 1       type       sp1    subcommunity              C 0.5000000
#> 12 raw beta 1       type       sp2    subcommunity              C 0.5000000
#> 13 raw beta 2       type       sp1    subcommunity              A 0.1666667
#> 14 raw beta 2       type       sp2    subcommunity              A 0.5000000
#> 15 raw beta 2       type       sp1    subcommunity              B 0.3333333
#> 16 raw beta 2       type       sp2    subcommunity              B       NaN
#> 17 raw beta 2       type       sp1    subcommunity              C 0.5000000
#> 18 raw beta 2       type       sp2    subcommunity              C 0.5000000
#>    dat_id transformation normalised  k max_d
#> 1   naive             NA         NA NA    NA
#> 2   naive             NA         NA NA    NA
#> 3   naive             NA         NA NA    NA
#> 4   naive             NA         NA NA    NA
#> 5   naive             NA         NA NA    NA
#> 6   naive             NA         NA NA    NA
#> 7   naive             NA         NA NA    NA
#> 8   naive             NA         NA NA    NA
#> 9   naive             NA         NA NA    NA
#> 10  naive             NA         NA NA    NA
#> 11  naive             NA         NA NA    NA
#> 12  naive             NA         NA NA    NA
#> 13  naive             NA         NA NA    NA
#> 14  naive             NA         NA NA    NA
#> 15  naive             NA         NA NA    NA
#> 16  naive             NA         NA NA    NA
#> 17  naive             NA         NA NA    NA
#> 18  naive             NA         NA NA    NA

# Calculate all measures of individual diversity
inddiv(meta, 0:2)
#>              measure q type_level type_name partition_level partition_name
#> 1          raw alpha 0       type       sp1    subcommunity              A
#> 2          raw alpha 0       type       sp2    subcommunity              A
#> 3          raw alpha 0       type       sp1    subcommunity              B
#> 4          raw alpha 0       type       sp2    subcommunity              B
#> 5          raw alpha 0       type       sp1    subcommunity              C
#> 6          raw alpha 0       type       sp2    subcommunity              C
#> 7          raw alpha 1       type       sp1    subcommunity              A
#> 8          raw alpha 1       type       sp2    subcommunity              A
#> 9          raw alpha 1       type       sp1    subcommunity              B
#> 10         raw alpha 1       type       sp2    subcommunity              B
#> 11         raw alpha 1       type       sp1    subcommunity              C
#> 12         raw alpha 1       type       sp2    subcommunity              C
#> 13         raw alpha 2       type       sp1    subcommunity              A
#> 14         raw alpha 2       type       sp2    subcommunity              A
#> 15         raw alpha 2       type       sp1    subcommunity              B
#> 16         raw alpha 2       type       sp2    subcommunity              B
#> 17         raw alpha 2       type       sp1    subcommunity              C
#> 18         raw alpha 2       type       sp2    subcommunity              C
#> 19  normalised alpha 0       type       sp1    subcommunity              A
#> 20  normalised alpha 0       type       sp2    subcommunity              A
#> 21  normalised alpha 0       type       sp1    subcommunity              B
#> 22  normalised alpha 0       type       sp2    subcommunity              B
#> 23  normalised alpha 0       type       sp1    subcommunity              C
#> 24  normalised alpha 0       type       sp2    subcommunity              C
#> 25  normalised alpha 1       type       sp1    subcommunity              A
#> 26  normalised alpha 1       type       sp2    subcommunity              A
#> 27  normalised alpha 1       type       sp1    subcommunity              B
#> 28  normalised alpha 1       type       sp2    subcommunity              B
#> 29  normalised alpha 1       type       sp1    subcommunity              C
#> 30  normalised alpha 1       type       sp2    subcommunity              C
#> 31  normalised alpha 2       type       sp1    subcommunity              A
#> 32  normalised alpha 2       type       sp2    subcommunity              A
#> 33  normalised alpha 2       type       sp1    subcommunity              B
#> 34  normalised alpha 2       type       sp2    subcommunity              B
#> 35  normalised alpha 2       type       sp1    subcommunity              C
#> 36  normalised alpha 2       type       sp2    subcommunity              C
#> 37          raw beta 0       type       sp1    subcommunity              A
#> 38          raw beta 0       type       sp2    subcommunity              A
#> 39          raw beta 0       type       sp1    subcommunity              B
#> 40          raw beta 0       type       sp2    subcommunity              B
#> 41          raw beta 0       type       sp1    subcommunity              C
#> 42          raw beta 0       type       sp2    subcommunity              C
#> 43          raw beta 1       type       sp1    subcommunity              A
#> 44          raw beta 1       type       sp2    subcommunity              A
#> 45          raw beta 1       type       sp1    subcommunity              B
#> 46          raw beta 1       type       sp2    subcommunity              B
#> 47          raw beta 1       type       sp1    subcommunity              C
#> 48          raw beta 1       type       sp2    subcommunity              C
#> 49          raw beta 2       type       sp1    subcommunity              A
#> 50          raw beta 2       type       sp2    subcommunity              A
#> 51          raw beta 2       type       sp1    subcommunity              B
#> 52          raw beta 2       type       sp2    subcommunity              B
#> 53          raw beta 2       type       sp1    subcommunity              C
#> 54          raw beta 2       type       sp2    subcommunity              C
#> 55   normalised beta 0       type       sp1    subcommunity              A
#> 56   normalised beta 0       type       sp2    subcommunity              A
#> 57   normalised beta 0       type       sp1    subcommunity              B
#> 58   normalised beta 0       type       sp2    subcommunity              B
#> 59   normalised beta 0       type       sp1    subcommunity              C
#> 60   normalised beta 0       type       sp2    subcommunity              C
#> 61   normalised beta 1       type       sp1    subcommunity              A
#> 62   normalised beta 1       type       sp2    subcommunity              A
#> 63   normalised beta 1       type       sp1    subcommunity              B
#> 64   normalised beta 1       type       sp2    subcommunity              B
#> 65   normalised beta 1       type       sp1    subcommunity              C
#> 66   normalised beta 1       type       sp2    subcommunity              C
#> 67   normalised beta 2       type       sp1    subcommunity              A
#> 68   normalised beta 2       type       sp2    subcommunity              A
#> 69   normalised beta 2       type       sp1    subcommunity              B
#> 70   normalised beta 2       type       sp2    subcommunity              B
#> 71   normalised beta 2       type       sp1    subcommunity              C
#> 72   normalised beta 2       type       sp2    subcommunity              C
#> 73           raw rho 0       type       sp1    subcommunity              A
#> 74           raw rho 0       type       sp2    subcommunity              A
#> 75           raw rho 0       type       sp1    subcommunity              B
#> 76           raw rho 0       type       sp2    subcommunity              B
#> 77           raw rho 0       type       sp1    subcommunity              C
#> 78           raw rho 0       type       sp2    subcommunity              C
#> 79           raw rho 1       type       sp1    subcommunity              A
#> 80           raw rho 1       type       sp2    subcommunity              A
#> 81           raw rho 1       type       sp1    subcommunity              B
#> 82           raw rho 1       type       sp2    subcommunity              B
#> 83           raw rho 1       type       sp1    subcommunity              C
#> 84           raw rho 1       type       sp2    subcommunity              C
#> 85           raw rho 2       type       sp1    subcommunity              A
#> 86           raw rho 2       type       sp2    subcommunity              A
#> 87           raw rho 2       type       sp1    subcommunity              B
#> 88           raw rho 2       type       sp2    subcommunity              B
#> 89           raw rho 2       type       sp1    subcommunity              C
#> 90           raw rho 2       type       sp2    subcommunity              C
#> 91    normalised rho 0       type       sp1    subcommunity              A
#> 92    normalised rho 0       type       sp2    subcommunity              A
#> 93    normalised rho 0       type       sp1    subcommunity              B
#> 94    normalised rho 0       type       sp2    subcommunity              B
#> 95    normalised rho 0       type       sp1    subcommunity              C
#> 96    normalised rho 0       type       sp2    subcommunity              C
#> 97    normalised rho 1       type       sp1    subcommunity              A
#> 98    normalised rho 1       type       sp2    subcommunity              A
#> 99    normalised rho 1       type       sp1    subcommunity              B
#> 100   normalised rho 1       type       sp2    subcommunity              B
#> 101   normalised rho 1       type       sp1    subcommunity              C
#> 102   normalised rho 1       type       sp2    subcommunity              C
#> 103   normalised rho 2       type       sp1    subcommunity              A
#> 104   normalised rho 2       type       sp2    subcommunity              A
#> 105   normalised rho 2       type       sp1    subcommunity              B
#> 106   normalised rho 2       type       sp2    subcommunity              B
#> 107   normalised rho 2       type       sp1    subcommunity              C
#> 108   normalised rho 2       type       sp2    subcommunity              C
#> 109            gamma 0       type       sp1    subcommunity              A
#> 110            gamma 0       type       sp2    subcommunity              A
#> 111            gamma 0       type       sp1    subcommunity              B
#> 112            gamma 0       type       sp2    subcommunity              B
#> 113            gamma 0       type       sp1    subcommunity              C
#> 114            gamma 0       type       sp2    subcommunity              C
#> 115            gamma 1       type       sp1    subcommunity              A
#> 116            gamma 1       type       sp2    subcommunity              A
#> 117            gamma 1       type       sp1    subcommunity              B
#> 118            gamma 1       type       sp2    subcommunity              B
#> 119            gamma 1       type       sp1    subcommunity              C
#> 120            gamma 1       type       sp2    subcommunity              C
#> 121            gamma 2       type       sp1    subcommunity              A
#> 122            gamma 2       type       sp2    subcommunity              A
#> 123            gamma 2       type       sp1    subcommunity              B
#> 124            gamma 2       type       sp2    subcommunity              B
#> 125            gamma 2       type       sp1    subcommunity              C
#> 126            gamma 2       type       sp2    subcommunity              C
#>     diversity dat_id transformation normalised  k max_d
#> 1   8.0000000  naive             NA         NA NA    NA
#> 2   8.0000000  naive             NA         NA NA    NA
#> 3   4.0000000  naive             NA         NA NA    NA
#> 4         NaN  naive             NA         NA NA    NA
#> 5   2.6666667  naive             NA         NA NA    NA
#> 6   8.0000000  naive             NA         NA NA    NA
#> 7   8.0000000  naive             NA         NA NA    NA
#> 8   8.0000000  naive             NA         NA NA    NA
#> 9   4.0000000  naive             NA         NA NA    NA
#> 10        NaN  naive             NA         NA NA    NA
#> 11  2.6666667  naive             NA         NA NA    NA
#> 12  8.0000000  naive             NA         NA NA    NA
#> 13  8.0000000  naive             NA         NA NA    NA
#> 14  8.0000000  naive             NA         NA NA    NA
#> 15  4.0000000  naive             NA         NA NA    NA
#> 16        NaN  naive             NA         NA NA    NA
#> 17  2.6666667  naive             NA         NA NA    NA
#> 18  8.0000000  naive             NA         NA NA    NA
#> 19  2.0000000  naive             NA         NA NA    NA
#> 20  2.0000000  naive             NA         NA NA    NA
#> 21  1.0000000  naive             NA         NA NA    NA
#> 22        NaN  naive             NA         NA NA    NA
#> 23  1.3333333  naive             NA         NA NA    NA
#> 24  4.0000000  naive             NA         NA NA    NA
#> 25  2.0000000  naive             NA         NA NA    NA
#> 26  2.0000000  naive             NA         NA NA    NA
#> 27  1.0000000  naive             NA         NA NA    NA
#> 28        NaN  naive             NA         NA NA    NA
#> 29  1.3333333  naive             NA         NA NA    NA
#> 30  4.0000000  naive             NA         NA NA    NA
#> 31  2.0000000  naive             NA         NA NA    NA
#> 32  2.0000000  naive             NA         NA NA    NA
#> 33  1.0000000  naive             NA         NA NA    NA
#> 34        NaN  naive             NA         NA NA    NA
#> 35  1.3333333  naive             NA         NA NA    NA
#> 36  4.0000000  naive             NA         NA NA    NA
#> 37  0.1666667  naive             NA         NA NA    NA
#> 38  0.5000000  naive             NA         NA NA    NA
#> 39  0.3333333  naive             NA         NA NA    NA
#> 40        NaN  naive             NA         NA NA    NA
#> 41  0.5000000  naive             NA         NA NA    NA
#> 42  0.5000000  naive             NA         NA NA    NA
#> 43  0.1666667  naive             NA         NA NA    NA
#> 44  0.5000000  naive             NA         NA NA    NA
#> 45  0.3333333  naive             NA         NA NA    NA
#> 46        NaN  naive             NA         NA NA    NA
#> 47  0.5000000  naive             NA         NA NA    NA
#> 48  0.5000000  naive             NA         NA NA    NA
#> 49  0.1666667  naive             NA         NA NA    NA
#> 50  0.5000000  naive             NA         NA NA    NA
#> 51  0.3333333  naive             NA         NA NA    NA
#> 52        NaN  naive             NA         NA NA    NA
#> 53  0.5000000  naive             NA         NA NA    NA
#> 54  0.5000000  naive             NA         NA NA    NA
#> 55  0.6666667  naive             NA         NA NA    NA
#> 56  2.0000000  naive             NA         NA NA    NA
#> 57  1.3333333  naive             NA         NA NA    NA
#> 58        NaN  naive             NA         NA NA    NA
#> 59  1.0000000  naive             NA         NA NA    NA
#> 60  1.0000000  naive             NA         NA NA    NA
#> 61  0.6666667  naive             NA         NA NA    NA
#> 62  2.0000000  naive             NA         NA NA    NA
#> 63  1.3333333  naive             NA         NA NA    NA
#> 64        NaN  naive             NA         NA NA    NA
#> 65  1.0000000  naive             NA         NA NA    NA
#> 66  1.0000000  naive             NA         NA NA    NA
#> 67  0.6666667  naive             NA         NA NA    NA
#> 68  2.0000000  naive             NA         NA NA    NA
#> 69  1.3333333  naive             NA         NA NA    NA
#> 70        NaN  naive             NA         NA NA    NA
#> 71  1.0000000  naive             NA         NA NA    NA
#> 72  1.0000000  naive             NA         NA NA    NA
#> 73  6.0000000  naive             NA         NA NA    NA
#> 74  2.0000000  naive             NA         NA NA    NA
#> 75  3.0000000  naive             NA         NA NA    NA
#> 76        NaN  naive             NA         NA NA    NA
#> 77  2.0000000  naive             NA         NA NA    NA
#> 78  2.0000000  naive             NA         NA NA    NA
#> 79  6.0000000  naive             NA         NA NA    NA
#> 80  2.0000000  naive             NA         NA NA    NA
#> 81  3.0000000  naive             NA         NA NA    NA
#> 82        NaN  naive             NA         NA NA    NA
#> 83  2.0000000  naive             NA         NA NA    NA
#> 84  2.0000000  naive             NA         NA NA    NA
#> 85  6.0000000  naive             NA         NA NA    NA
#> 86  2.0000000  naive             NA         NA NA    NA
#> 87  3.0000000  naive             NA         NA NA    NA
#> 88        NaN  naive             NA         NA NA    NA
#> 89  2.0000000  naive             NA         NA NA    NA
#> 90  2.0000000  naive             NA         NA NA    NA
#> 91  1.5000000  naive             NA         NA NA    NA
#> 92  0.5000000  naive             NA         NA NA    NA
#> 93  0.7500000  naive             NA         NA NA    NA
#> 94        NaN  naive             NA         NA NA    NA
#> 95  1.0000000  naive             NA         NA NA    NA
#> 96  1.0000000  naive             NA         NA NA    NA
#> 97  1.5000000  naive             NA         NA NA    NA
#> 98  0.5000000  naive             NA         NA NA    NA
#> 99  0.7500000  naive             NA         NA NA    NA
#> 100       NaN  naive             NA         NA NA    NA
#> 101 1.0000000  naive             NA         NA NA    NA
#> 102 1.0000000  naive             NA         NA NA    NA
#> 103 1.5000000  naive             NA         NA NA    NA
#> 104 0.5000000  naive             NA         NA NA    NA
#> 105 0.7500000  naive             NA         NA NA    NA
#> 106       NaN  naive             NA         NA NA    NA
#> 107 1.0000000  naive             NA         NA NA    NA
#> 108 1.0000000  naive             NA         NA NA    NA
#> 109 1.3333333  naive             NA         NA NA    NA
#> 110 4.0000000  naive             NA         NA NA    NA
#> 111 1.3333333  naive             NA         NA NA    NA
#> 112 0.0000000  naive             NA         NA NA    NA
#> 113 1.3333333  naive             NA         NA NA    NA
#> 114 4.0000000  naive             NA         NA NA    NA
#> 115 1.3333333  naive             NA         NA NA    NA
#> 116 4.0000000  naive             NA         NA NA    NA
#> 117 1.3333333  naive             NA         NA NA    NA
#> 118 0.0000000  naive             NA         NA NA    NA
#> 119 1.3333333  naive             NA         NA NA    NA
#> 120 4.0000000  naive             NA         NA NA    NA
#> 121 1.3333333  naive             NA         NA NA    NA
#> 122 4.0000000  naive             NA         NA NA    NA
#> 123 1.3333333  naive             NA         NA NA    NA
#> 124 0.0000000  naive             NA         NA NA    NA
#> 125 1.3333333  naive             NA         NA NA    NA
#> 126 4.0000000  naive             NA         NA NA    NA