Movatterモバイル変換


[0]ホーム

URL:


mvabund

This vignette takes you through the main functions inmvabund to help you get started! We recommend reading themanuscriptassociated with the package and taking a look atOther Resources in our README.

First things first

Let’s load the package and get our hands on theTasmaniadata set to look at the effects of disturbance treatment on invertebrateabundances. Note that theTasmania data set is a listobject. We will only look at thecopepods data frame forthis walk-through. Thecopepods data frame can be accessedusingTasmania$copepods or theattach()function which will make the contents ofTasmaniasearchable.

library(mvabund)data(Tasmania)attach(Tasmania)#> The following objects are masked from reveg:#>#>     abund, treatmentskimr::skim(copepods)# Great function to get an overview of the data
Data summary
Namecopepods
Number of rows16
Number of columns12
_______________________
Column type frequency:
numeric12
________________________
Group variablesNone

Variable type: numeric

skim_variablen_missingcomplete_ratemeansdp0p25p50p75p100hist
Ameira0155.4446.6046.7558.592.25142▇▂▃▃▂
Adopsyllus010.691.2500.000.01.004▇▂▁▁▁
Ectinosoma011.312.3000.000.01.257▇▁▁▁▁
Ectinosomat014.504.4601.003.55.5015▇▃▂▁▂
Haloschizo010.120.5000.000.00.002▇▁▁▁▁
Lepta.A0140.6947.1503.0028.057.25151▇▂▁▂▁
Lepta.B011.442.9200.000.01.2511▇▁▁▁▁
Lepta.C0112.7544.7300.000.01.50180▇▁▁▁▁
Mictyricola011.312.3300.000.01.508▇▁▁▁▁
Parevansula010.250.5800.000.00.002▇▁▁▁▁
Quin010.440.9600.000.00.003▇▁▁▁▁
Rhizothrix010.812.0400.000.00.006▇▁▁▁▁

Visualise the multivariate data

We first need to turn our data into amvabund object sofunctions for this package and work with the data

copepod_abund<-mvabund(copepods)

Now lets take a look at abundance for each species across ourtreatment sites (Disturbed vs. Undisturbed). Observations were collectedusing a spatially blocked design where researchers took four samples ateach block (2 per treatment). We can set the colour (col)of the points to represent that four sampling blocks

plot(copepod_abund~treatment,col = block)#> Overlapping points were shifted along the y-axis to make them visible.#>#>  PIPING TO 2nd MVFACTOR

Fitting Predictive Models

It was hypothesised that the abundance ofAmeira andEctinosoma was reduced in Disturbed sites, whereas theabundance ofMictyricola may have increased. Lets test thishypothesis using themanyglm() function. This function fitsa generalised linear model for each species. We specifiedfamily = "negative.binomial" as count data tends to followa negative binomial distribution. Other distributions are available too!See?manyglm()

cope.nb<-manyglm(copepods~ treatment*block,family ="negative.binomial")

Checking Model Assumptions

Before we look at the model output, we should check on the modelresiduals. What we want to see islittle pattern as thisimplies that our choice of negative binomial distribution isappropriate.

plot(cope.nb)

Now, lets proceed to check on themean-variancerelationship. We want to to see if themean-variancerelationship of our data adheres to that of a negative binomialdistribution which tends to be quadratic rather than linear. Themeanvar.plot() function plots the sample variance againstthe sample mean for each species within each factor level of(tr.block). A quadratic relationship seems appropriate forour sample mean and variance.

meanvar.plot(copepods~tr.block,col = treatment)#> START SECTION 2#> Plotting if overlay is TRUE#> using grouping variable tr.block 46 mean values were 0 and could#>                                      not be included in the log-plot#> using grouping variable tr.block 49 variance values were 0 and could not#>                                      be included in the log-plot

#> FINISHED SECTION 2

Hypothesis Testing

To test whethertreatment andblock had aneffect on the abundances of copepods we can use theanova()function. This function returns a Analysis of Deviance table which teststhe significance of each model term. Settingp.uni = "adjusted" allows for our p-values to be adjustedfor multiple testing of different species.

anova(cope.nb,p.uni ="adjusted")#> Time elapsed: 0 hr 0 min 34 sec#> Analysis of Deviance Table#>#> Model: copepods ~ treatment * block#>#> Multivariate test:#>                 Res.Df Df.diff    Dev Pr(>Dev)#> (Intercept)         15#> treatment           14       1  32.52    0.047 *#> block               11       3 151.87    0.001 ***#> treatment:block      8       3  37.41    0.081 .#> ---#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1#>#> Univariate Tests:#>                 Ameira          Adopsyllus          Ectinosoma#>                    Dev Pr(>Dev)        Dev Pr(>Dev)        Dev Pr(>Dev)#> (Intercept)#> treatment        6.257    0.150      0.032    0.978      7.026    0.144#> block           12.615    0.153     17.691    0.054     15.361    0.072#> treatment:block  6.349    0.510      1.295    0.868      0.836    0.868#>                 Ectinosomat          Haloschizo          Lepta.A#>                         Dev Pr(>Dev)        Dev Pr(>Dev)     Dev Pr(>Dev)#> (Intercept)#> treatment             0.366    0.943      1.497    0.805   0.281    0.943#> block                 10.92    0.186      3.742    0.246  20.756    0.022#> treatment:block       1.122    0.868          0    0.868  13.072    0.162#>                 Lepta.B          Lepta.C          Mictyricola#>                     Dev Pr(>Dev)     Dev Pr(>Dev)         Dev Pr(>Dev)#> (Intercept)#> treatment         0.575    0.926   2.141    0.748       7.093    0.144#> block               8.8    0.186  17.419    0.056      11.415    0.186#> treatment:block   7.402    0.453    0.34    0.868       5.268    0.510#>                 Parevansula           Quin          Rhizothrix#>                         Dev Pr(>Dev)   Dev Pr(>Dev)        Dev Pr(>Dev)#> (Intercept)#> treatment                 0    0.996 5.385    0.202      1.869    0.748#> block                   6.1    0.186  9.44    0.186     17.613    0.056#> treatment:block       1.726    0.835     0    0.868          0    0.868#> Arguments:#>  Test statistics calculated assuming uncorrelated response (for faster computation)#> P-value calculated using 999 iterations via PIT-trap resampling.

The test statistics in this table are by default calculated bysumming the change in deviance across all responses. You could use adifferent type of test statistic by changing thetest andcor.type arguments. We can see that there is asignificant effect of the treatment factor meaning thattreatment has a significant multiplicative effect on mean abundance. Theinteraction between blocks and treatments isnotsignificant, meaning that the multiplicative treatment effectis consistent across blocks.

If you do not have a specific hypothesis in mind that you want totest, and are instead interested in which model terms are statisticallysignificant, then thesummary() function will come inhandy. However results aren’t quite as trustworthy as foranova(). The reason is that re-samples are taken under thealternative hypothesis forsummary(), where there is agreater chance of fitted values being zero, especially for rarer taxa(e.g. if there is a treatment combination in which a taxon is neverpresent). Abundances don’t re-sample well if their predicted mean iszero.

summary(cope.nb)#>#> Test statistics:#>                             wald value Pr(>wald)#> (Intercept)                     18.493     0.001 ***#> treatmentUndisturbed             3.330     0.238#> block2                           4.710     0.052 .#> block3                           6.650     0.001 ***#> block4                           3.435     0.156#> treatmentUndisturbed:block2      2.747     0.266#> treatmentUndisturbed:block3      1.615     0.462#> treatmentUndisturbed:block4      4.262     0.043 *#> ---#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1#>#> Test statistic:  14.81, p-value: 0.002#> Arguments:#>  Test statistics calculated assuming response assumed to be uncorrelated#>  P-value calculated using 999 resampling iterations via pit.trap resampling (to account for correlation in testing).

If obtaining predicted values from the model is the goal, you may usethepredict() function. Note thattype = response will produce values on the scale of theresponse variable (i.e. counts)

predict(cope.nb,type ="response")#>      Ameira   Adopsyllus   Ectinosoma Ectinosomat   Haloschizo Lepta.A#> B1D1   53.0 3.678794e-07 3.678794e-07         8.0 3.678794e-07    63.5#> B1D2   53.0 3.678794e-07 3.678794e-07         8.0 3.678794e-07    63.5#> B1U1  114.5 3.678794e-07 1.000000e+00         7.0 1.000000e+00   134.0#> B1U2  114.5 3.678794e-07 1.000000e+00         7.0 1.000000e+00   134.0#> B2D1    4.5 3.678794e-07 3.678794e-07         9.0 3.678794e-07    31.0#> B2D2    4.5 3.678794e-07 3.678794e-07         9.0 3.678794e-07    31.0#> B2U1   74.0 3.678794e-07 3.678794e-07         4.5 3.678794e-07    51.5#> B2U2   74.0 3.678794e-07 3.678794e-07         4.5 3.678794e-07    51.5#> B3D1    6.5 3.678794e-07 3.678794e-07         2.5 3.678794e-07     2.0#> B3D2    6.5 3.678794e-07 3.678794e-07         2.5 3.678794e-07     2.0#> B3U1   35.0 5.000000e-01 2.500000e+00         2.5 3.678794e-07     1.5#> B3U2   35.0 5.000000e-01 2.500000e+00         2.5 3.678794e-07     1.5#> B4D1   37.0 2.500000e+00 5.000000e-01         1.0 3.678794e-07    38.0#> B4D2   37.0 2.500000e+00 5.000000e-01         1.0 3.678794e-07    38.0#> B4U1  119.0 2.500000e+00 6.500000e+00         1.5 3.678794e-07     4.0#> B4U2  119.0 2.500000e+00 6.500000e+00         1.5 3.678794e-07     4.0#>           Lepta.B      Lepta.C  Mictyricola  Parevansula         Quin#> B1D1 6.000000e+00 3.678794e-07 3.678794e-07 3.678794e-07 3.678794e-07#> B1D2 6.000000e+00 3.678794e-07 3.678794e-07 3.678794e-07 3.678794e-07#> B1U1 3.678794e-07 3.678794e-07 3.678794e-07 5.000000e-01 2.500000e+00#> B1U2 3.678794e-07 3.678794e-07 3.678794e-07 5.000000e-01 2.500000e+00#> B2D1 1.500000e+00 3.678794e-07 5.500000e+00 1.000000e+00 3.678794e-07#> B2D2 1.500000e+00 3.678794e-07 5.500000e+00 1.000000e+00 3.678794e-07#> B2U1 3.500000e+00 3.678794e-07 3.678794e-07 5.000000e-01 3.678794e-07#> B2U2 3.500000e+00 3.678794e-07 3.678794e-07 5.000000e-01 3.678794e-07#> B3D1 3.678794e-07 9.500000e+01 5.000000e-01 3.678794e-07 3.678794e-07#> B3D2 3.678794e-07 9.500000e+01 5.000000e-01 3.678794e-07 3.678794e-07#> B3U1 3.678794e-07 5.000000e+00 5.000000e-01 3.678794e-07 3.678794e-07#> B3U2 3.678794e-07 5.000000e+00 5.000000e-01 3.678794e-07 3.678794e-07#> B4D1 5.000000e-01 2.000000e+00 4.000000e+00 3.678794e-07 3.678794e-07#> B4D2 5.000000e-01 2.000000e+00 4.000000e+00 3.678794e-07 3.678794e-07#> B4U1 3.678794e-07 3.678794e-07 3.678794e-07 3.678794e-07 1.000000e+00#> B4U2 3.678794e-07 3.678794e-07 3.678794e-07 3.678794e-07 1.000000e+00#>        Rhizothrix#> B1D1 5.000000e-01#> B1D2 5.000000e-01#> B1U1 6.000000e+00#> B1U2 6.000000e+00#> B2D1 3.678794e-07#> B2D2 3.678794e-07#> B2U1 3.678794e-07#> B2U2 3.678794e-07#> B3D1 3.678794e-07#> B3D2 3.678794e-07#> B3U1 3.678794e-07#> B3U2 3.678794e-07#> B4D1 3.678794e-07#> B4D2 3.678794e-07#> B4U1 3.678794e-07#> B4U2 3.678794e-07

[8]ページ先頭

©2009-2025 Movatter.jp