knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
We recommend installing NetGAM using the install_github function in the devtools
package.
library(devtools) devtools::install_github("sgleich/NetGAM")
library(NetGAM) # install.packages(c("mgcv","dplyr","compositions","stats","psych","pulsar","batchtools","huge")) library(mgcv) library(pulsar) library(batchtools) library(dplyr) library(psych) library(huge) library(stats)
The first function available in the NetGAM package will take a species abundance datafame (samples as rows and species as columns) and will GAM-transform the species abundance data. These GAM-transformed species abundance values can be thought of as species abundance values with a reduced influence of time. The GAM-transformed dataframe can be used as input for a downstream network analysis of your choice.
# Load in species abundance dataframe. Here, the samples are rows (1-200) and the columns are species (V1-V20). The species abundance values here are relative abundance values. data <- system.file("extdata", "output_asvs.csv", package = "NetGAM") df <- read.csv(data,header=TRUE,row.names=1) # The netGAM.df function requires two vectors as input: the month of year vector and the day of time-series vector. We will set up our vectors for input in the function. moy <- rep(1:12,length=200) dayOfTs <- 1:200 # Now, we will run the netGAM.df function. The parameter clrt is being set to TRUE here (default) because we want to CLR-transform our data to account for compositionality. df.out <- NetGAM::netGAM.df(df,moy,dayOfTs,clrt=TRUE) # df.out is the GAM-transformed dataframe that can be used in downstream association network analyses.
The second function available in the NetGAM package will use GAM-transformed data (i.e. the output of the netGAM.df function) and will be use those GAM-transformed data as input for a graphical lasso (glasso), pairwise spearman correlation (scc), or pairwise pearson correlation (pcc) network analysis. The result of the netGAM.network function will be a species-species adjacency matrix in which 1s imply an association between two species and 0s imply no association between two species. This adjacnecy matrix can then be used to graph the network in the igraph
package.
# Run the netGAM.network function using the output of the netGAM.df function (i.e. df.out) as input. We will first run a glasso network (default) and then we can try running a scc network after. glasso.net <- NetGAM::netGAM.network(df.out,method="glasso") library(igraph) glasso.graph <- graph_from_adjacency_matrix(glasso.net,mode="undirected") plot(glasso.graph,vertex.label=NA)
We can also run the netGAM.network function to build a GAM-transformed SCC network.
# Run the netGAM.network function using the output of the netGAM.df function (i.e. df.out) as input. Here, will will run a scc network. scc.net <- NetGAM::netGAM.network(df.out,method="scc",pvalue=0.05) library(igraph) scc.graph <- graph_from_edgelist(scc.net,directed=FALSE) plot(scc.graph,vertex.label=NA)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.