### Data Loading and Preparation for Spider Example Source: https://github.com/eco-stats/mvabund/blob/master/docs/reference/plot.mvabund.html Loads the 'spider' dataset and converts the abundance and predictor variables into mvabund objects. This is a setup step for subsequent plotting examples. ```R data(spider) spiddat <- mvabund(spider$abund) spidx <- mvabund(spider$x) ``` -------------------------------- ### Access mvabund Vignettes Source: https://github.com/eco-stats/mvabund/blob/master/README.md Install mvabund with vignettes and access them in R for a detailed guide. This requires building the vignettes during installation. ```r remotes::install_github("eco-stats/mvabund", build_vignettes = TRUE) vignette("mvabund") ``` -------------------------------- ### Install mvabund Development Version from GitHub Source: https://github.com/eco-stats/mvabund/blob/master/README.md Install the latest development version of mvabund from GitHub. Requires the 'remotes' package. Load the library after installation. ```r # install.packages("remotes") remotes::install_github("eco-stats/mvabund") library(mvabund) ``` -------------------------------- ### Install mvabund with Vignettes Source: https://github.com/eco-stats/mvabund/blob/master/docs/index.html Install the mvabund package from GitHub, ensuring vignettes are built. This allows you to access detailed guides on using the package within R. ```R remotes::install_github("aliceyiwang/mvabund", build_vignettes = TRUE) vignette("mvabund") ``` -------------------------------- ### Extend a Formula to all of its Terms Source: https://github.com/eco-stats/mvabund/blob/master/docs/reference/extend.x.formula.html Demonstrates how to use extend.x.formula to expand a formula. Note that the example code provided in the source results in errors, indicating potential issues with the example's setup or dependencies. ```R data(spider) spiddat <- mvabund(spider$abund) X <- spider$x foo <- mvformula(spiddat~ X[,1]*X[,2]+log(X[,3])) #> Error in eval(terms(x)[[2]]): object 'spiddat' not found extend.x.formula(foo) #> Error in terms(formula): object 'foo' not found ``` -------------------------------- ### Install mvabund Development Version from GitHub Source: https://github.com/eco-stats/mvabund/blob/master/docs/index.html Install the development version of mvabund from GitHub using the remotes package. This is useful for accessing the latest features or bug fixes. Load the library after installation. ```R # install.packages("remotes") remotes::install_github("aliceyiwang/mvabund") library(mvabund) ``` -------------------------------- ### Install mvabund from CRAN Source: https://github.com/eco-stats/mvabund/blob/master/README.md Install the mvabund package from CRAN for general use. Load the library after installation. ```r install.packages("mvabund") library(mvabund) ``` -------------------------------- ### Basic mvabund Plotting Source: https://github.com/eco-stats/mvabund/blob/master/docs/reference/plot.mvabund.html Demonstrates basic plotting of multivariate abundance data using the `mvabund` function. This is a starting point for visualizing abundance variables. ```R require(graphics) ############################ ## Some "type (1)" plots ## ############################ data(solberg) ``` -------------------------------- ### Plotting an mvabund Object Directly Source: https://github.com/eco-stats/mvabund/blob/master/docs/reference/plot.mvabund.html Demonstrates how to plot an object that has already been converted to the mvabund class using the mvabund() function. This is an alternative way to achieve the same visualization as the previous example. ```R solbmvabund <- mvabund(solbdat) plot(solbmvabund) ``` -------------------------------- ### Create Univariate Formulas from Multivariate Response Source: https://github.com/eco-stats/mvabund/blob/master/docs/reference/formulaUnimva.html Demonstrates how to use formulaUnimva to create a list of univariate formulas from a multivariate response object. Note: This example will produce an error as 'spiddat' is not defined in this context. ```R data(spider) spiddat <- mvabund(spider$abund) X <- spider$x formulaUnimva(spiddat~X) ``` -------------------------------- ### Fitting GLM with glm2 package Source: https://github.com/eco-stats/mvabund/blob/master/docs/reference/manyany.html Demonstrates fitting a binomial GLM using the 'glm.fit2' method from the glm2 package. This can improve model fitting for certain datasets. Requires the glm2 package to be installed. ```R if (FALSE) library(glm2) if (FALSE) spidPA2<-manyany(PAdat~x,"glm",data=spider,family=binomial("cloglog"),method="glm.fit2") if (FALSE) plot(spidPA2) ``` -------------------------------- ### Predict Fourth Corner Model to New Sites Source: https://github.com/eco-stats/mvabund/blob/master/docs/reference/predict.traitglm.html This example shows how to use the predict function with a fitted traitglm object to obtain predictions for the first five sites, using new environmental data. ```R # predict to the first five sites predict(ft, newR=antTraits$env[1:5,]) ``` -------------------------------- ### Plotting mvabund Object with Treatment using Formula Source: https://github.com/eco-stats/mvabund/blob/master/docs/reference/plot.mvabund.html An alternative syntax for plotting species abundance by treatment group using a formula interface. This is equivalent to the previous example and can be more intuitive for some users. ```R plot(solbmvabund~treatment) ``` -------------------------------- ### Create mvabund Formula Source: https://github.com/eco-stats/mvabund/blob/master/docs/reference/tikus.html Defines a formula for mvabund analysis using the abundance data and explanatory variables. Note: This example may produce errors if 'tikusdat' is not defined. ```r foo <- mvformula(tikusdat~tikusid[,1] + tikusid[,2]) ``` -------------------------------- ### Fitting Ordinal Model with ordinal package Source: https://github.com/eco-stats/mvabund/blob/master/docs/reference/manyany.html Illustrates how to fit an ordinal regression model using the 'clm' function from the ordinal package. This involves first constructing an ordinal dataset from abundance data and then fitting the model. Requires the ordinal package to be installed. ```R if (FALSE) library(ordinal) ## First construct an ordinal dataset: if (FALSE) spidOrd = spider$abund if (FALSE) spidOrd[spider$abund>1 & spider$abund<=10]=2 if (FALSE) spidOrd[spider$abund>10]=3 ## Now fit a model using the clm function: if (FALSE) manyOrd=manyany(spidOrd~bare.sand+fallen.leaves,"clm",data=data.frame(spider$x)) if (FALSE) plot(manyOrd) ``` -------------------------------- ### Plotting an Environment Factor vs Abundance Source: https://github.com/eco-stats/mvabund/blob/master/docs/reference/plotMvaFactor.html This example demonstrates how to plot an environmental factor against abundance data using the plotMvaFactor function. It requires the 'mvabund' and 'graphics' packages and uses the 'spider' dataset. ```R require(graphics) ## Plot an Environment Factor vs Abundance plot data(spider) spiddat <- mvabund(spider$abund) ## Create a Environmental factor where TRUE=Sand, FALSE=No Sand) X <- as.factor(spider$x$bare.sand>0) plotMvaFactor(x=spiddat, y=X) ``` -------------------------------- ### Generate Prediction and Confidence Intervals Source: https://github.com/eco-stats/mvabund/blob/master/docs/reference/predict.manyglm.html Use the predict method with interval="prediction" to get prediction intervals and interval="confidence" to get confidence intervals. Requires a fitted manyglm model and new data. ```r pred.w.plim <- predict(glm.spid.poiss, newdata, interval="prediction") pred.w.clim <- predict(glm.spid.poiss, newdata, interval="confidence") ``` -------------------------------- ### Load and Plot Spider Abundance Data Source: https://github.com/eco-stats/mvabund/blob/master/docs/reference/spider.html Loads the spider dataset and creates a boxplot of the abundance data using the mvabund package. Ensure the mvabund package is installed and loaded. ```R require(graphics) data(spider) spiddat <- as.mvabund(spider$abund) plot(spiddat) ``` -------------------------------- ### Comparing Multiple Fourth Corner Model Fits Source: https://github.com/eco-stats/mvabund/blob/master/docs/reference/anova.traitglm.html This example shows how to compare multiple fourth corner model fits using anova.traitglm. It fits three models with different interaction terms and then compares them to assess the significance of shrub and CWD interactions. ```R # for an example using anova.traitglm for multiple fits, uncomment the following lines: # ft2=traitglm(antTraits$abund,antTraits$env[,3:4],antTraits$traits[,c(1,3)], # formula=~1,composition=TRUE) #no fourth corner terms # ft3=traitglm(antTraits$abund,antTraits$env[,3:4],antTraits$traits[,c(1,3)], # formula=~Shrub.cover:Femur.length+Shrub.cover:Pilosity,composition=TRUE) #shrub interactions # ft4=traitglm(antTraits$abund,antTraits$env[,3:4],antTraits$traits[,c(1,3)], # formula=~Shrub.cover:Femur.length+Shrub.cover:Pilosity+Volume.lying.CWD:Femur.length+ # Volume.lying.CWD:Pilosity, composition=TRUE) #all interactions only # anova(ft2,ft3,ft4) # Shrub interactions not significant but CWD interactions are. ``` -------------------------------- ### Perform Fourth Corner Analysis with antTraits Source: https://github.com/eco-stats/mvabund/blob/master/docs/reference/antTraits.html Performs a fourth corner analysis using the antTraits dataset. This example demonstrates how to use the traitglm function with the abundance, environment, and traits data. ```r data(antTraits) ft = traitglm(antTraits$abund,antTraits$env,antTraits$traits) #to do a fourth corner analysis ``` -------------------------------- ### Fit TraitGLM with LASSO and Interaction Terms Source: https://github.com/eco-stats/mvabund/blob/master/docs/reference/traitglm.html Fits a TraitGLM model using the 'glm1path' method, which incorporates LASSO regularization. This example demonstrates how to specify interaction terms in the formula and how LASSO can penalize coefficients to zero, effectively performing variable selection. The output shows the coefficients after regularization. ```R ft1=traitglm(antTraits$abund,antTraits$env[,3:4],antTraits$traits[,c(1,3)], formula=~Shrub.cover:Femur.length+Shrub.cover:Pilosity,composition=TRUE,method="glm1path") ft1$fourth ``` -------------------------------- ### Create an mvabund object Source: https://github.com/eco-stats/mvabund/blob/master/docs/reference/mvabund.html Demonstrates how to create an mvabund object from a data frame or matrix. This is the primary way to prepare data for mvabund functions. ```R data(solberg) ## Create an mvabund object: solbergdat <- mvabund(solberg$abund) ``` -------------------------------- ### Basic usage of best.r.sq Source: https://github.com/eco-stats/mvabund/blob/master/docs/reference/best.r.sq.html Demonstrates the basic usage of the best.r.sq function with sample data. This snippet shows how to call the function with a multivariate response and explanatory variables. ```R data(spider) spiddat <- mvabund(spider$abund) X <- as.matrix(spider$x) best.r.sq( spiddat~X ) #> Error in eval(parse(text = lab)): object 'X' not found ``` -------------------------------- ### Plot mvabund Formula Results Source: https://github.com/eco-stats/mvabund/blob/master/docs/reference/tikus.html Generates a plot based on the mvabund formula. Note: This example may produce errors if 'foo' is not defined. ```r plot(foo) ``` -------------------------------- ### Convert data to an mvabund object Source: https://github.com/eco-stats/mvabund/blob/master/docs/reference/mvabund.html Shows how to explicitly convert existing data into an mvabund object using the as.mvabund function. This ensures compatibility with mvabund methods. ```R ## Turn solberg$abund into an mvabund object and store as solbergdat: solbergdat <- as.mvabund(solberg$abund) ``` -------------------------------- ### Create and Unabund mvabund Object Source: https://github.com/eco-stats/mvabund/blob/master/docs/reference/unabund.html Demonstrates how to create an mvabund object using as.mvabund and then convert it back to a matrix using unabund. This snippet shows the basic usage of the unabund function. ```R abundances <- as.mvabund(matrix(1:20,5,4)) ## Restore the original object: mat <- unabund(x=abundances) mat ``` -------------------------------- ### Load and Visualize Tasmania Dataset Source: https://github.com/eco-stats/mvabund/blob/master/docs/reference/Tasmania.html Loads the Tasmania dataset and visualizes the abundance of copepod species across different blocks and treatments using mvabund. ```r require(graphics) data(Tasmania) tasm.cop <- mvabund(Tasmania$copepods) treatment <- Tasmania$treatment block <- Tasmania$block plot(tasm.cop~block*treatment) ``` -------------------------------- ### Load and Prepare Tikus Dataset Source: https://github.com/eco-stats/mvabund/blob/master/docs/reference/meanvar.plot.html Loads the 'tikus' dataset and prepares the abundance data for use with mvabund functions. ```R require(graphics) ## Load the tikus dataset: data(tikus) tikusdat <- mvabund(tikus$abund) ``` -------------------------------- ### Load mvabund and reveg dataset Source: https://github.com/eco-stats/mvabund/blob/master/docs/articles/Offsets.html Loads the necessary mvabund package and the reveg dataset for analysis. It also attaches the dataset for easier access to its components. ```R library(mvabund) library(ecostats) data(reveg) attach(reveg) ``` -------------------------------- ### Estimate Ridge Parameter Source: https://github.com/eco-stats/mvabund/blob/master/docs/reference/ridgeParamEst.html Demonstrates how to use ridgeParamEst to estimate the ridge parameter and minimum log-likelihood using sample data and a design matrix. ```R data(spider) spiddat <- mvabund(spider$abund) X <- as.matrix(spider$x) ridgeParamEst(dat = spiddat, X = model.matrix(spiddat~X)) ``` -------------------------------- ### Mean-Variance Plot with Subset and Custom Colors Source: https://github.com/eco-stats/mvabund/blob/master/docs/reference/meanvar.plot.html Creates a mean-variance plot for specific years (1981 and 1983) using a subset of the data and custom colors for the points. This example demonstrates filtering data based on a condition. ```R ## A mean-variance plot, data organised by year, ## for 1981 and 1983 only, as in Figure 7a of Warton (2008): is81or83 <- year==81 | year==83 meanvar.plot(tikusdat~year, subset=is81or83, col=c(1,10)) ``` -------------------------------- ### Calculate Deviance for manylm Object Source: https://github.com/eco-stats/mvabund/blob/master/docs/reference/deviance.manylm.html This example demonstrates how to calculate the deviance for a multivariate linear model fitted to spider abundance data. It first prepares the data and then uses the `deviance` function on the fitted `manylm` object. ```R data(spider) spiddat <- mvabund(spider$abund) ## Calculate the deviance: deviance(manylm(spiddat~., data=spider$x)) ``` -------------------------------- ### Basic Usage of glm1 Source: https://github.com/eco-stats/mvabund/blob/master/docs/reference/glm1.html Demonstrates fitting a GLM with a LASSO penalty using the glm1 function. Requires the 'mvabund' package and sample data. ```R data(spider) Alopacce <- spider$abund[,1] ``` -------------------------------- ### Advanced Boxplot with Transformations and Grouping Source: https://github.com/eco-stats/mvabund/blob/master/docs/reference/boxplot.mvabund.html Illustrates advanced boxplot customization for mvabund objects, including data transformation (sqrt), grouping by a factor (treatment), and visual enhancements like custom point types and colors. This example focuses on plotting the most abundant species. ```R data(solberg) solbdat <- mvabund(solberg$abund) treatment<- solberg$x # create pch type and colour vectors treat.pch <- treat.col <- unclass(treatment) # Boxplot for data plot.mvabund(x=solbdat,y=treatment,type="bx", main="BoxPlot of The 12 Highest Abundant Species", xlab="Abundance [sqrt scale]",ylab="", transformation="sqrt",t.lab="o",shift=TRUE) #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> A number of other arguments like `at` and `names` are only available for the `mvabund` method. ``` -------------------------------- ### Prepare and Model Multivariate Abundance Data Source: https://github.com/eco-stats/mvabund/blob/master/docs/reference/solberg.html Prepares the Solberg dataset for multivariate analysis by creating an mvabund object and fitting a multivariate linear model. Requires the 'mvabund' package to be loaded. ```R solbergdat <- mvabund( solberg$abund ) treatment <- solberg$x ## Create a formula for multivariate abundance data: foo.sol <- mvformula( solbergdat ~ treatment ) #> Error in eval(terms(x)[[2]]): object 'solbergdat' not found ## Fit a multivariate linear model: lm.solberg <- manylm(foo.sol) #> Error in model.frame(formula = foo.sol, drop.unused.levels = TRUE): object 'foo.sol' not found lm.solberg #> Error in eval(expr, envir, enclos): object 'lm.solberg' not found ``` -------------------------------- ### Create a Formula for Multivariate Abundance Data Source: https://github.com/eco-stats/mvabund/blob/master/docs/reference/mvformula.html Demonstrates how to create a mvformula object using the mvformula function. This is useful for setting up models for multivariate abundance data. ```r require(graphics) data(spider) spiddat <- mvabund(spider$abund) X=as.matrix(spider$x) ## Create a formula for multivariate abundance data: foo <- mvformula( spiddat~X ) #> Error in eval(terms(x)[[2]]): object 'spiddat' not found ``` -------------------------------- ### Load Package and Data Source: https://github.com/eco-stats/mvabund/blob/master/docs/articles/mvabund.html Loads the mvabund package and the Tasmania dataset. It then attaches the dataset to make its contents searchable and uses skimr to provide an overview of the copepods data frame. ```R library(mvabund) data(Tasmania) attach(Tasmania) skimr::skim(copepods) # Great function to get an overview of the data ``` -------------------------------- ### Basic Boxplot of mvabund Object Source: https://github.com/eco-stats/mvabund/blob/master/docs/reference/boxplot.mvabund.html Demonstrates the fundamental usage of boxplot() with an mvabund object. Requires the 'graphics' package and the 'mvabund' object to be created first. ```R require(graphics) #### Basic Use #### data(spider) spiddat <- spider$abund X <- spider$x ## Create the mvabund object: spiddat <- mvabund(spiddat) ## Draw a boxplot for a mvabund object: boxplot(spiddat) #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> #> A different way to get the same plot could be by using plot(spiddat, type="bx"). ``` -------------------------------- ### Prepare Explanatory Variables Source: https://github.com/eco-stats/mvabund/blob/master/docs/reference/tikus.html Extracts the explanatory variables (location ID and time) from the tikus dataset. These are used in the mvabund formula. ```r tikusid <- tikus$x ``` -------------------------------- ### traitglm with Custom Formula Source: https://github.com/eco-stats/mvabund/blob/master/docs/reference/traitglm.html Shows how to specify a custom formula for modeling abundance as a function of environmental and trait variables. This allows for specific inclusion of terms and interactions. ```R traitglm(L, R, Q, formula = ~ env1 + trait1 + env1:trait1) ``` -------------------------------- ### Compare Models using anova.manyany Source: https://github.com/eco-stats/mvabund/blob/master/docs/reference/anova.manyany.html This snippet compares two previously fitted `manyany` models (`ftRep` and `ftTimeRep`) using the `anova` function. It performs the comparison with a small number of resamples (`nBoot=9`) for demonstration purposes, noting that this may take a few seconds to run. ```R anova(ftRep,ftTimeRep,nBoot=9) #this takes a few seconds to run even for just 9 resamples #> Warning: only the first element is used as variable name #> Warning: only the first element is used as variable name #> Warning: glm.fit: algorithm did not converge #> Warning: glm.fit: algorithm did not converge #> Warning: only the first element is used as variable name #> Warning: only the first element is used as variable name #> Warning: glm.fit: algorithm did not converge #> Warning: glm.fit: algorithm did not converge #> Warning: only the first element is used as variable name #> Warning: only the first element is used as variable name #> Warning: glm.fit: algorithm did not converge #> Warning: glm.fit: algorithm did not converge #> Warning: only the first element is used as variable name #> Warning: only the first element is used as variable name #> Warning: glm.fit: algorithm did not converge #> Warning: glm.fit: algorithm did not converge #> Warning: only the first element is used as variable name ``` -------------------------------- ### manyany Function Usage Source: https://github.com/eco-stats/mvabund/blob/master/docs/reference/manyany.html Demonstrates the basic usage of the manyany function with formula, function name, family, and data arguments. The 'composition' argument controls whether to fit separate models per species or a single compositional model. ```R manyany(formula, fn, family="negative.binomial", data, composition = FALSE, block = NULL, get.what="details", var.power=NA, na.action = "na.exclude", ...) ``` -------------------------------- ### Usage of manylm.wfit Source: https://github.com/eco-stats/mvabund/blob/master/docs/reference/manylm.fit.html Illustrates the function signature for manylm.wfit, which includes weights for fitting multivariate linear models using weighted least squares. ```R manylm.wfit(x, y, w, offset = NULL, tol=1.0e-010, singular.ok = TRUE, ...) ```