Title: | Spatially Explicit Structural Equation Modeling |
---|---|
Description: | Structural equation modeling is a powerful statistical approach for the testing of networks of direct and indirect theoretical causal relationships in complex data sets with inter-correlated dependent and independent variables. Here we implement a simple method for spatially explicit structural equation modeling based on the analysis of variance co-variance matrices calculated across a range of lag distances. This method provides readily interpreted plots of the change in path coefficients across scale. |
Authors: | Eric Lamb [aut, cre], Kerrie Mengersen [aut], Katherine Stewart [aut], Udayanga Attanayake [aut], Steven Siciliano [aut] |
Maintainer: | Eric Lamb <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.0.2 |
Built: | 2025-01-22 03:40:47 UTC |
Source: | https://github.com/cran/sesem |
Structural equation modeling (SEM) is a powerful statistical approach for the testing of networks of direct and indirect theoretical causal relationships in complex datasets with intercorrelated dependent and independent variables. Here we implement a simple method for spatially explicit SEM (SE-SEM) based on the analysis of variance covariance matrices calculated across a range of lag distances. This method provides readily interpretable plots of the change in path coefficients across scale.
Package: | sesem |
Type: | Package |
Version: | 1.0 |
Date: | 2016-06-09 |
License: | GPL (>= 2) |
Package sesem allows spatially explicit structural equation modeling. It allows a structural equation model to be fit to a number of spatially explicit covariance matrices to explore how the strength of structural path coefficients changes with scale. In brief an SESEM analysis involves: calculating pairwise differences among samples selecting a series of lag distance bins generating spatially explicit variance - covariance matrices for each lag distance bin fitting a structural equation model to each of those bins comparing and examining how the strength of path coefficients change with scale
Eric G. Lamb, Kerrie Mengersen, Katherine J. Stewart, Udayanga Attanayake, and Steven D. Siciliano
Maintainer: Eric Lamb <[email protected]>
Lamb, E. G., K. Mengersen, K. J. Stewart, U. Attanayake, and S. D. Siciliano. 2014. Spatially explicit structural equation modeling. Ecology 95:2434-2442.
Rosseel, Y. 2012 lavaan: an R package for structural equation modeling. Journal of Statistical Software 48:1-36.
data=truelove truelove_red<-truelove[c(1:60),c(1:7)] distancematrix<-calc.dist(truelove_red) Truelove_bins<-make.bin(distancematrix,type="ALL",p.dist=10) binsize<-Truelove_bins[1][[1]] #truelove lowland bin sizes binname<-Truelove_bins[2][[1]] #truelove lowland bin names plotbin(distancematrix,binsize) covariances<-make.covar(truelove_red,distancematrix,binsize,binname) covariances # reduced path model for the truelove dataset spatial_model<-' N_Fix ~ Bryoph + Lich + SoilCrust SoilCrust ~ Bryoph + Lich Lich ~ Bryoph + Moisture Bryoph ~ Moisture ' results<-runModels(spatial_model,covariances) modelsummary(results) plotmodelfit(results) plotpath(results)
data=truelove truelove_red<-truelove[c(1:60),c(1:7)] distancematrix<-calc.dist(truelove_red) Truelove_bins<-make.bin(distancematrix,type="ALL",p.dist=10) binsize<-Truelove_bins[1][[1]] #truelove lowland bin sizes binname<-Truelove_bins[2][[1]] #truelove lowland bin names plotbin(distancematrix,binsize) covariances<-make.covar(truelove_red,distancematrix,binsize,binname) covariances # reduced path model for the truelove dataset spatial_model<-' N_Fix ~ Bryoph + Lich + SoilCrust SoilCrust ~ Bryoph + Lich Lich ~ Bryoph + Moisture Bryoph ~ Moisture ' results<-runModels(spatial_model,covariances) modelsummary(results) plotmodelfit(results) plotpath(results)
This dataset summarizes ground cover and nitrogen fixation activity along a 93 point variably spaced transect at Alexandra Fiord, Ellesmere Island, Nunavut, Canada.
A data frame with 93 rows and 10 variables.
Variables are: X, Y, Moisture, N_Fix, SoilCrust, Bryoph, Lich, Forbs, Gram, Shrubs
Stewart, K. J., E. G. Lamb, D. S. Coxon, and S. D. Siciliano. 2011b. Bryophyte-cyanobacterial associations as a key factor in N2-fixation across the Canadian Arctic. Plant and Soil 344:335-346.
Modification indices averaged across all lag distance bins (the non-spatial bin is not included) are calculated for each potential path addition to the structural model. Option modcut suppresses the printing of modification indices of less than that value.
avg.modindices(spatial_model_results, modcut = 4)
avg.modindices(spatial_model_results, modcut = 4)
spatial_model_results |
a list object produced by function runModels |
modcut |
The minimum averaged modification index to print. Default is 4. |
Eric Lamb
Lamb, E. G., K. Mengersen, K. J. Stewart, U. Attanayake, and S. D. Siciliano. 2014. Spatially explicit structural equation modeling. Ecology 95:2434-2442.
Rosseel, Y. 2012 lavaan: an R package for structural equation modeling. Journal of Statistical Software 48:1-36.
sem
, modelsummary
, runModels
, plotmodelfit
#data=truelove #distancematrix<-calc.dist(truelove) #Truelove_bins<-make.bin(distancematrix,type="ALL",p.dist=20) #binsize<-Truelove_bins[1][[1]] #truelove lowland bin sizes #binname<-Truelove_bins[2][[1]] #truelove lowland bin names #covariances<-make.covar(truelove,distancematrix,binsize,binname) #covariances # path model for the truelove dataset #spatial_model<-' # Gram ~ Moisture # N_Fix ~ Bryoph + Lich + SoilCrust # SoilCrust ~ Bryoph + Lich + Gram + Shrubs + Forbs # Bryoph ~ Gram + Shrubs + Forbs + Moisture # Lich ~ Moisture + Forbs + Gram + Shrubs + Bryoph # Forbs ~ Moisture # Gram ~~ Forbs # Shrubs ~ Moisture # Gram ~~ Shrubs # Shrubs ~~ Forbs # ' # #results<-runModels(spatial_model,covariances) #The above script produces the sesem object stored as truelove_results data=truelove_results modelsummary(truelove_results) avg.modindices(truelove_results) avg.modindices(truelove_results,modcut=10)
#data=truelove #distancematrix<-calc.dist(truelove) #Truelove_bins<-make.bin(distancematrix,type="ALL",p.dist=20) #binsize<-Truelove_bins[1][[1]] #truelove lowland bin sizes #binname<-Truelove_bins[2][[1]] #truelove lowland bin names #covariances<-make.covar(truelove,distancematrix,binsize,binname) #covariances # path model for the truelove dataset #spatial_model<-' # Gram ~ Moisture # N_Fix ~ Bryoph + Lich + SoilCrust # SoilCrust ~ Bryoph + Lich + Gram + Shrubs + Forbs # Bryoph ~ Gram + Shrubs + Forbs + Moisture # Lich ~ Moisture + Forbs + Gram + Shrubs + Bryoph # Forbs ~ Moisture # Gram ~~ Forbs # Shrubs ~ Moisture # Gram ~~ Shrubs # Shrubs ~~ Forbs # ' # #results<-runModels(spatial_model,covariances) #The above script produces the sesem object stored as truelove_results data=truelove_results modelsummary(truelove_results) avg.modindices(truelove_results) avg.modindices(truelove_results,modcut=10)
Function to extract path coefficients, standard errors, and standardized coefficients for a particular bin in a readable format
bin.results(spatial_model_results, bin = "binflat")
bin.results(spatial_model_results, bin = "binflat")
spatial_model_results |
a list object produced by function run.Models |
bin |
Name of the bin that results are desired for. Defaults to flat model. |
Given a spatial SEM object produced by runModels, bin.results allows the results for a particular lag distance bin to be inspected in a readable format.
Eric Lamb
Lamb, E. G., K. Mengersen, K. J. Stewart, U. Attanayake, and S. D. Siciliano. 2014. Spatially explicit structural equation modeling. Ecology 95:2434-2442.
sem
, make.covar
, runModels
, modelsummary
#data=truelove #distancematrix<-calc.dist(truelove) #Truelove_bins<-make.bin(distancematrix,type="ALL",p.dist=20) #binsize<-Truelove_bins[1][[1]] #truelove lowland bin sizes #binname<-Truelove_bins[2][[1]] #truelove lowland bin names #covariances<-make.covar(truelove,distancematrix,binsize,binname) #covariances # path model for the truelove dataset #spatial_model<-' # Gram ~ Moisture # N_Fix ~ Bryoph + Lich + SoilCrust # SoilCrust ~ Bryoph + Lich + Gram + Shrubs + Forbs # Bryoph ~ Gram + Shrubs + Forbs + Moisture # Lich ~ Moisture + Forbs + Gram + Shrubs + Bryoph # Forbs ~ Moisture # Gram ~~ Forbs # Shrubs ~ Moisture # Gram ~~ Shrubs # Shrubs ~~ Forbs # ' # #results<-runModels(spatial_model,covariances) #The above script produces the sesem object stored as truelove_results data=truelove_results bin.results(truelove_results) bin.results(truelove_results,bin="Bin2")
#data=truelove #distancematrix<-calc.dist(truelove) #Truelove_bins<-make.bin(distancematrix,type="ALL",p.dist=20) #binsize<-Truelove_bins[1][[1]] #truelove lowland bin sizes #binname<-Truelove_bins[2][[1]] #truelove lowland bin names #covariances<-make.covar(truelove,distancematrix,binsize,binname) #covariances # path model for the truelove dataset #spatial_model<-' # Gram ~ Moisture # N_Fix ~ Bryoph + Lich + SoilCrust # SoilCrust ~ Bryoph + Lich + Gram + Shrubs + Forbs # Bryoph ~ Gram + Shrubs + Forbs + Moisture # Lich ~ Moisture + Forbs + Gram + Shrubs + Bryoph # Forbs ~ Moisture # Gram ~~ Forbs # Shrubs ~ Moisture # Gram ~~ Shrubs # Shrubs ~~ Forbs # ' # #results<-runModels(spatial_model,covariances) #The above script produces the sesem object stored as truelove_results data=truelove_results bin.results(truelove_results) bin.results(truelove_results,bin="Bin2")
extracts rsquare values from for dependent variables in a spatial SEM object for a particular lag distance bin in a readable format
bin.rsquare(spatial_model_results, bin = "binflat")
bin.rsquare(spatial_model_results, bin = "binflat")
spatial_model_results |
a list object produced by function run.Models |
bin |
Name of the bin that results are desired for. Defaults to flat (nonspatial) model |
Eric Lamb
Lamb, E. G., K. Mengersen, K. J. Stewart, U. Attanayake, and S. D. Siciliano. 2014. Spatially explicit structural equation modeling. Ecology 95:2434-2442.
sem
, make.covar
, runModels
, modelsummary
, bin.results
#data=truelove #distancematrix<-calc.dist(truelove) #Truelove_bins<-make.bin(distancematrix,type="ALL",p.dist=20) #binsize<-Truelove_bins[1][[1]] #truelove lowland bin sizes #binname<-Truelove_bins[2][[1]] #truelove lowland bin names #covariances<-make.covar(truelove,distancematrix,binsize,binname) #covariances # path model for the truelove dataset #spatial_model<-' # Gram ~ Moisture # N_Fix ~ Bryoph + Lich + SoilCrust # SoilCrust ~ Bryoph + Lich + Gram + Shrubs + Forbs # Bryoph ~ Gram + Shrubs + Forbs + Moisture # Lich ~ Moisture + Forbs + Gram + Shrubs + Bryoph # Forbs ~ Moisture # Gram ~~ Forbs # Shrubs ~ Moisture # Gram ~~ Shrubs # Shrubs ~~ Forbs # ' # #results<-runModels(spatial_model,covariances) #The above script produces the sesem object stored as truelove_results data=truelove_results bin.rsquare(truelove_results) bin.rsquare(truelove_results,bin="Bin2")
#data=truelove #distancematrix<-calc.dist(truelove) #Truelove_bins<-make.bin(distancematrix,type="ALL",p.dist=20) #binsize<-Truelove_bins[1][[1]] #truelove lowland bin sizes #binname<-Truelove_bins[2][[1]] #truelove lowland bin names #covariances<-make.covar(truelove,distancematrix,binsize,binname) #covariances # path model for the truelove dataset #spatial_model<-' # Gram ~ Moisture # N_Fix ~ Bryoph + Lich + SoilCrust # SoilCrust ~ Bryoph + Lich + Gram + Shrubs + Forbs # Bryoph ~ Gram + Shrubs + Forbs + Moisture # Lich ~ Moisture + Forbs + Gram + Shrubs + Bryoph # Forbs ~ Moisture # Gram ~~ Forbs # Shrubs ~ Moisture # Gram ~~ Shrubs # Shrubs ~~ Forbs # ' # #results<-runModels(spatial_model,covariances) #The above script produces the sesem object stored as truelove_results data=truelove_results bin.rsquare(truelove_results) bin.rsquare(truelove_results,bin="Bin2")
calc.dist calculates and stores the distance matrix for all X-Y pairs. It works on a dataset where the first two columns are x and y coordinates
calc.dist(datafile)
calc.dist(datafile)
datafile |
a dataset where the first two columns are x and y coordinates. Further columns can contain observed variables for subsequent modeling; these are ignored here. |
datafile is a dataset where the first two columns are x and y coordinates. If data are distributed on only one dimension (i.e. along a linear transect) one of the columns should contain zeroes.
a vector containing distances between each pair of samples in the input data
Kerrie Mengersen, Eric Lamb
Lamb, E. G., K. Mengersen, K. J. Stewart, U. Attanayake, and S. D. Siciliano. 2014. Spatially explicit structural equation modeling. Ecology 95:2434-2442.
data=truelove distdata<-truelove[c(1:60),] distances<-calc.dist(distdata) distances
data=truelove distdata<-truelove[c(1:60),] distances<-calc.dist(distdata) distances
This function fits generalized additive models (gam) of the path coefficient vs. lag distance relationship for each path in the spatial SEM model. Gam functions and figures are produced. Requires function mgcv
gam.path(spatial_model_results, path.type = "directed",selectpath = "none selected", plot.points = T, se.plot = T, lwd.pred = 2, lty.pred = 1, lwd.se = 2, lty.se = 3, cex = 1, cex.axis = 1, cex.lab = 1, xlab = "Lag Distance", ylab = "Unst. Path Coeff.", yaxt = "s", xaxt = "s")
gam.path(spatial_model_results, path.type = "directed",selectpath = "none selected", plot.points = T, se.plot = T, lwd.pred = 2, lty.pred = 1, lwd.se = 2, lty.se = 3, cex = 1, cex.axis = 1, cex.lab = 1, xlab = "Lag Distance", ylab = "Unst. Path Coeff.", yaxt = "s", xaxt = "s")
spatial_model_results |
a list object produced by function runModels |
path.type |
An option to select the paths to be plotted. "directed" = only directed paths plotted; "undirected" = only undirected correlations plotted; "both" = all paths plotted; "user" = allows user to specify particular paths and a particular order for plotting. Argument selectpath must also be provided with path.type="user" |
selectpath |
An option to select specific paths for plotting. Usage is as follows: selectpath==c(5,18,16,23,29) where values refer to path numbers. Path numbers can be obtained using spatial_model_results[[2]] |
plot.points |
Should points for individual models be plotted? |
se.plot |
Should standard error lines for each gam model be plotted? |
lwd.pred |
width of the predicted line from the gam model |
lty.pred |
format of the predicted line from the gam model |
lwd.se |
width of the standard error line |
lty.se |
format of the standard error line |
cex |
point size |
cex.axis |
axis font size |
cex.lab |
label font size |
xlab |
x-axis label |
ylab |
y-axis label |
yaxt |
argument to suppress plotting of y-axis if set to "n" |
xaxt |
argument to suppress plotting of x-axis if set to "n" |
Generalized additive models (gam) allow flexible modeling of nonlinear relationships with minimal assumptions about the shape of those relationships. This function utilizes the gam fitting function in library mgcv to fit and display gam models of the relationships between lag distance and unstandardized path coefficients. This is an alternative to the lowess smoothed lines available in function plot.path. Potential advantages of the gam models include the ability to obtain predictions for lag distance values intermediate between modeled lag distances.
Eric Lamb
Lamb, E. G., K. Mengersen, K. J. Stewart, U. Attanayake, and S. D. Siciliano. 2014. Spatially explicit structural equation modeling. Ecology 95:2434-2442.
Rosseel, Y. 2012 lavaan: an R package for structural equation modeling. Journal of Statistical Software 48:1-36
Wood, S.N. 2011 Fast stable restricted maximum likelihood and marginal likelihood estimation of semiparametric generalized linear models. Journal of the Royal Statistical Society (B) 73(1):3-36
Wood, S.N. 2006 Generalized Additive Models: An Introduction with R. Chapman and Hall/CRC
sem
, gam
, make.covar
, runModels
,
modelsummary
, plotmodelfit
, plotpath
#data=truelove #distancematrix<-calc.dist(truelove) #Truelove_bins<-make.bin(distancematrix,type="ALL",p.dist=20) #binsize<-Truelove_bins[1][[1]] #truelove lowland bin sizes #binname<-Truelove_bins[2][[1]] #truelove lowland bin names #covariances<-make.covar(truelove,distancematrix,binsize,binname) #covariances # path model for the truelove dataset #spatial_model<-' # Gram ~ Moisture # N_Fix ~ Bryoph + Lich + SoilCrust # SoilCrust ~ Bryoph + Lich + Gram + Shrubs + Forbs # Bryoph ~ Gram + Shrubs + Forbs + Moisture # Lich ~ Moisture + Forbs + Gram + Shrubs + Bryoph # Forbs ~ Moisture # Gram ~~ Forbs # Shrubs ~ Moisture # Gram ~~ Shrubs # Shrubs ~~ Forbs # ' # #results<-runModels(spatial_model,covariances) #The above script produces the sesem object stored as truelove_results data=truelove_results gam.path(truelove_results) truelove_results[[2]]# list of path names gam.path(truelove_results,path.type="user",selectpath=c(5,7,8))
#data=truelove #distancematrix<-calc.dist(truelove) #Truelove_bins<-make.bin(distancematrix,type="ALL",p.dist=20) #binsize<-Truelove_bins[1][[1]] #truelove lowland bin sizes #binname<-Truelove_bins[2][[1]] #truelove lowland bin names #covariances<-make.covar(truelove,distancematrix,binsize,binname) #covariances # path model for the truelove dataset #spatial_model<-' # Gram ~ Moisture # N_Fix ~ Bryoph + Lich + SoilCrust # SoilCrust ~ Bryoph + Lich + Gram + Shrubs + Forbs # Bryoph ~ Gram + Shrubs + Forbs + Moisture # Lich ~ Moisture + Forbs + Gram + Shrubs + Bryoph # Forbs ~ Moisture # Gram ~~ Forbs # Shrubs ~ Moisture # Gram ~~ Shrubs # Shrubs ~~ Forbs # ' # #results<-runModels(spatial_model,covariances) #The above script produces the sesem object stored as truelove_results data=truelove_results gam.path(truelove_results) truelove_results[[2]]# list of path names gam.path(truelove_results,path.type="user",selectpath=c(5,7,8))
For spatial SEM, lag distance bins need to be described by 2 vectors: binsize and binname. make.bin is a function to automatically generate lag distance bins for a given dataset. Options to automatically specify bins based on desired within bin sample size, or desired number of bins are available.
make.bin(dist.mat, type = "n.bins", p.dist = 50, n.bins = 10, s.size = 100)
make.bin(dist.mat, type = "n.bins", p.dist = 50, n.bins = 10, s.size = 100)
dist.mat |
a vector containing distances between all X-Y sample pairs in a dataset. Produced by function calc.dist |
type |
should a particular number of bins be created ("n.bins"), or should bins each contain a particular number of sample pairs ("s.size"), or should all possible bins be created ("ALL"). Note that "ALL" will only yield sensible results for regular sampling designs. |
p.dist |
Inference distance (i.e. upper limit of largest lag distance bin) as a percentage of the maximum distance sampled |
n.bins |
number of bins to be generated if type="n.bins" |
s.size |
sample size within each bin to be used if type="s.size" |
make.bin generates cut off values for lag distance bins and corresponding bin names The function has three default parameter values available, if user does not want to specify:
(1) Inference distance as a percentage(p.dist) = 50. This sets the upper limit of the largest bin. Normally lag distances greater than 50
You can use type="ALL","n.bins" OR "s.size" to control parameter values. ALL will only produce sensible results for regular sampling designs. The function produces a list object containing (1.)binsize and (2.)binname. These two vectors (binsize and binname) will be used by make.covar to calculate variance covariance matrices for each lag distance bin
Special note: User specified number of lag distance bins OR sample size will be used to calculate initial cutoff value of each lag distance bin. However, if the cutoff point is in between a lag distance bin, real cutoff will apply at the upper margin of the particular bin. Therefore, resulting number of bins are less than or equal AND resulting sample sizes are greater than or equal to the value specified by the user.
a List with two components:
comp1 |
a vector of bin size cutoff distances starting with zero |
comp2 |
a character vector of bin names. This vector has one element less than component 1 |
Udayanga Attanayake, Eric Lamb
Lamb, E. G., K. Mengersen, K. J. Stewart, U. Attanayake, and S. D. Siciliano. 2014. Spatially explicit structural equation modeling. Ecology 95:2434-2442.
calc.dist
, make.covar
, plotbin
data=truelove distdata<-truelove[c(1:60),] distances<-calc.dist(distdata) Truelove_bins<-make.bin(distances,type="ALL") # inference distance=50% AND number of bins=ALL # note the need to extract sizes and names from the bin size object # as shown below for use in function make.covar binsize<-Truelove_bins[1][[1]] #truelove lowland bin sizes binsize binname<-Truelove_bins[2][[1]] #truelove lowland bin names binname # function make.bin to generate bins with 120 samples each to a maximum inference # distance of 20% note the need to extract sizes and names from the bin size object # as shown below for use in make.covar data=plantcomp distdata<-plantcomp[c(1:60),] distances<-calc.dist(distdata) #using subset of plantcomp dataset to cut computation time Plant_bins<-make.bin(distances,type="s.size",s.size=60,p.dist=20) #inference distance=20% AND sample size=120 # note the need to extract sizes and names from the bin size object # as shown below for use in function make.covar binsize<-Plant_bins[1][[1]] #plant competition bin sizes binsize binname<-Plant_bins[2][[1]] #plant competition bin names binname # if manual bin sizes are needed use the following approach. # Note that the bin name vector must have one fewer elements than bin size binsize = c(0,1,2,2.2,4,5,8,16,32,64,96,128,160) binsize binname=c("Bin1","Bin2","Bin3","Bin4","Bin5","Bin6","Bin7","Bin8", "Bin9","Bin10","Bin11","Bin12") binname
data=truelove distdata<-truelove[c(1:60),] distances<-calc.dist(distdata) Truelove_bins<-make.bin(distances,type="ALL") # inference distance=50% AND number of bins=ALL # note the need to extract sizes and names from the bin size object # as shown below for use in function make.covar binsize<-Truelove_bins[1][[1]] #truelove lowland bin sizes binsize binname<-Truelove_bins[2][[1]] #truelove lowland bin names binname # function make.bin to generate bins with 120 samples each to a maximum inference # distance of 20% note the need to extract sizes and names from the bin size object # as shown below for use in make.covar data=plantcomp distdata<-plantcomp[c(1:60),] distances<-calc.dist(distdata) #using subset of plantcomp dataset to cut computation time Plant_bins<-make.bin(distances,type="s.size",s.size=60,p.dist=20) #inference distance=20% AND sample size=120 # note the need to extract sizes and names from the bin size object # as shown below for use in function make.covar binsize<-Plant_bins[1][[1]] #plant competition bin sizes binsize binname<-Plant_bins[2][[1]] #plant competition bin names binname # if manual bin sizes are needed use the following approach. # Note that the bin name vector must have one fewer elements than bin size binsize = c(0,1,2,2.2,4,5,8,16,32,64,96,128,160) binsize binname=c("Bin1","Bin2","Bin3","Bin4","Bin5","Bin6","Bin7","Bin8", "Bin9","Bin10","Bin11","Bin12") binname
calculates variance covariance matrices for each lag distance bin and for a flat (non-spatial) bin
make.covar(datafile,dist.mat,binsize,binname)
make.covar(datafile,dist.mat,binsize,binname)
datafile |
a dataset where the first two columns are x and y coordinates. Further columns contain observed variables for subsequent sesem modeling. |
dist.mat |
a vector containing distances between all X-Y sample pairs in a dataset. Produced by function calc.dist. |
binsize |
A vector of bin size cutoff distances starting with zero. Produced using make.bin |
binname |
A character vector of bin names. This vector has one element less than binsize. |
Calculates variance-covariance matrices for a series of lag distance bins and for a flat (non-spatial) bin. This function produces a list object with four components: [[1]]bin.summary, [[2]] variable names [[3]] flat covariance matrix, [[4]][,,i] covariance matrices for each bin i. A summary of the bins is printed.
1 |
A bin summary with colums binname, lower cutoff distance, upper cutoff distance, and sample size |
2 |
A list of observed variable names |
3 |
the flat (non-spatial) variance-covariance matrix |
4 |
contains elements [[4]][,,i] where each i is the variance - covariance matrix for a particular lag distance bin |
Kerrie Mengersen, Eric Lamb
Lamb, E. G., K. Mengersen, K. J. Stewart, U. Attanayake, and S. D. Siciliano. 2014. Spatially explicit structural equation modeling. Ecology 95:2434-2442.
make.bin
, make.covar
, runModels
data=truelove truelove_red<-truelove[c(1:60),c(1:5)] distancematrix<-calc.dist(truelove_red) #calc.dist and make.covar can be time consuming to run, # therefore only a small dataset utilized here Truelove_bins<-make.bin(distancematrix,type="ALL",p.dist=5) binsize<-Truelove_bins[1][[1]] #truelove lowland bin sizes binname<-Truelove_bins[2][[1]] #truelove lowland bin names covariances<-make.covar(truelove_red,distancematrix,binsize,binname) covariances
data=truelove truelove_red<-truelove[c(1:60),c(1:5)] distancematrix<-calc.dist(truelove_red) #calc.dist and make.covar can be time consuming to run, # therefore only a small dataset utilized here Truelove_bins<-make.bin(distancematrix,type="ALL",p.dist=5) binsize<-Truelove_bins[1][[1]] #truelove lowland bin sizes binname<-Truelove_bins[2][[1]] #truelove lowland bin names covariances<-make.covar(truelove_red,distancematrix,binsize,binname) covariances
extracts basic model summary information from the bin.summary file and the object created by run.Models in a readable format
modelsummary(spatial_model_results)
modelsummary(spatial_model_results)
spatial_model_results |
a list object produced by runModels |
Eric Lamb
Lamb, E. G., K. Mengersen, K. J. Stewart, U. Attanayake, and S. D. Siciliano. 2014. Spatially explicit structural equation modeling. Ecology 95:2434-2442.
Rosseel, Y. 2012 lavaan: an R package for structural equation modeling. Journal of Statistical Software 48:1-36.
sem
, make.covar
, runModels
, plotmodelfit
, plotpath
#data=truelove #distancematrix<-calc.dist(truelove) #Truelove_bins<-make.bin(distancematrix,type="ALL",p.dist=20) #binsize<-Truelove_bins[1][[1]] #truelove lowland bin sizes #binname<-Truelove_bins[2][[1]] #truelove lowland bin names #covariances<-make.covar(truelove,distancematrix,binsize,binname) #covariances # path model for the truelove dataset #spatial_model<-' # Gram ~ Moisture # N_Fix ~ Bryoph + Lich + SoilCrust # SoilCrust ~ Bryoph + Lich + Gram + Shrubs + Forbs # Bryoph ~ Gram + Shrubs + Forbs + Moisture # Lich ~ Moisture + Forbs + Gram + Shrubs + Bryoph # Forbs ~ Moisture # Gram ~~ Forbs # Shrubs ~ Moisture # Gram ~~ Shrubs # Shrubs ~~ Forbs # ' # #results<-runModels(spatial_model,covariances) #The above script produces the sesem object stored as truelove_results data=truelove_results modelsummary(truelove_results)
#data=truelove #distancematrix<-calc.dist(truelove) #Truelove_bins<-make.bin(distancematrix,type="ALL",p.dist=20) #binsize<-Truelove_bins[1][[1]] #truelove lowland bin sizes #binname<-Truelove_bins[2][[1]] #truelove lowland bin names #covariances<-make.covar(truelove,distancematrix,binsize,binname) #covariances # path model for the truelove dataset #spatial_model<-' # Gram ~ Moisture # N_Fix ~ Bryoph + Lich + SoilCrust # SoilCrust ~ Bryoph + Lich + Gram + Shrubs + Forbs # Bryoph ~ Gram + Shrubs + Forbs + Moisture # Lich ~ Moisture + Forbs + Gram + Shrubs + Bryoph # Forbs ~ Moisture # Gram ~~ Forbs # Shrubs ~ Moisture # Gram ~~ Shrubs # Shrubs ~~ Forbs # ' # #results<-runModels(spatial_model,covariances) #The above script produces the sesem object stored as truelove_results data=truelove_results modelsummary(truelove_results)
This dataset summarizes plant community characteristics, competition intensity, and topographic features in a mesic grassland in central Alberta, Canada.
A data frame with 192 rows and 10 variables.
Variables are: Easting ,Northing ,Comp.Intensity ,ShootBio ,RootBio ,SpRich , SoilMoist ,LightInt ,Topog.Pos ,TotalN
Lamb, E. G. and J. F. Cahill. 2008. When competition does not matter: grassland diversity and community composition. American Naturalist 171:777-787
A convenience function that provides a histogram of distances among of all sample pairs and a plot of sample sizes for each the selected bin size.
plotbin(dist.mat,binsize)
plotbin(dist.mat,binsize)
dist.mat |
a vector of x-y distances among all sample pairs as produced by calc.dist |
binsize |
A vector of bin sizes as produced by make.bin, or of the form c(0,2,3,4,....) where the values are the desired bin cutoffs beginning with zero. |
This function is to assist in visualization of both the distribution of x-y distances in the dataset and sample sizes resulting from the selected lag distance bins. See the help files for calc.dist and make.bin for the inputs to this function.
Eric Lamb
Lamb, E. G., K. Mengersen, K. J. Stewart, U. Attanayake, and S. D. Siciliano. 2014. Spatially explicit structural equation modeling. Ecology 95:2434-2442.
make.bin
, calc.dist
, make.covar
data=plantcomp distancematrix<-calc.dist(plantcomp[c(1:100),]) #using subset of plantcomp dataset to cut computation time Plant_bins<-make.bin(distancematrix,type="s.size",s.size=200) #inference distance=50% AND sample size=200 binsize<-Plant_bins[1][[1]] #plant competition bin sizes plotbin(distancematrix,binsize)
data=plantcomp distancematrix<-calc.dist(plantcomp[c(1:100),]) #using subset of plantcomp dataset to cut computation time Plant_bins<-make.bin(distancematrix,type="s.size",s.size=200) #inference distance=50% AND sample size=200 binsize<-Plant_bins[1][[1]] #plant competition bin sizes plotbin(distancematrix,binsize)
A function to plot model fit indices across lag distances. The default is to plot all of the chi square, cfi, rmsea (including confidence intervals), and srmr indices. Horizontal lines indicating significant cutoffs for each index are plotted (chi square p=0.05, cfi=0.9, rmsea=0.05, and srmr=0.08). Options to add trend lines are available.
plotmodelfit(spatial_model_results, plots = "all", add.line = "none", rmsea_err = T, pch = 16, lwd = 2, lty = 1, cex = 1, cex.lab = 1, cex.axis = 1, cex.main = 1.5)
plotmodelfit(spatial_model_results, plots = "all", add.line = "none", rmsea_err = T, pch = 16, lwd = 2, lty = 1, cex = 1, cex.lab = 1, cex.axis = 1, cex.main = 1.5)
spatial_model_results |
a list object produced by function runModels |
plots |
Indicates which indices should be plotted. The default "all" produces plots of all of the chi square, cfi, rmsea (including confidence intervals), and srmr indices. plot="chi", "cfi", "rmsea", or "srmr" will produce only a single plot. |
add.line |
Indicates whether a trendline should be added connecting the points. The default "none" indicates no line, "step" plots straight line segments between points, and "smooth" plots a smoothed curve fit using function lowess. Smoothed lines do not include the flat model (lag distance zero). |
rmsea_err |
Should the rmsea index be plotted with confidence intervals? rmsea_err=T is the default, rmsea_err=F will suppress confidence intervals. Note that warnings will likely arise if rmsea_err=T is used and there are confidence intervals of zero. All these warnings indicate is that that particular confidence interval is equal to the estimated value and will not be plotted. |
pch |
plotting symbol |
lwd |
line width |
lty |
line format |
cex |
symbol size |
cex.lab |
label font size |
cex.axis |
axis label font size |
cex.main |
plot title font size |
Warnings may arise from the plotting of the rsmea error bars if rmsea_err=T is used and there are confidence intervals of zero. All these warnings indicate is that that particular confidence interval is equal to the estimated value and will not be plotted.
Eric Lamb
Lamb, E. G., K. Mengersen, K. J. Stewart, U. Attanayake, and S. D. Siciliano. 2014. Spatially explicit structural equation modeling. Ecology 95:2434-2442.
sem
, make.covar
, runModels
, modelsummary
, avg.modindices
, plotpath
, gam.path
#data=truelove #distancematrix<-calc.dist(truelove) #Truelove_bins<-make.bin(distancematrix,type="ALL",p.dist=20) #binsize<-Truelove_bins[1][[1]] #truelove lowland bin sizes #binname<-Truelove_bins[2][[1]] #truelove lowland bin names #covariances<-make.covar(truelove,distancematrix,binsize,binname) #covariances # path model for the truelove dataset #spatial_model<-' # Gram ~ Moisture # N_Fix ~ Bryoph + Lich + SoilCrust # SoilCrust ~ Bryoph + Lich + Gram + Shrubs + Forbs # Bryoph ~ Gram + Shrubs + Forbs + Moisture # Lich ~ Moisture + Forbs + Gram + Shrubs + Bryoph # Forbs ~ Moisture # Gram ~~ Forbs # Shrubs ~ Moisture # Gram ~~ Shrubs # Shrubs ~~ Forbs # ' # #results<-runModels(spatial_model,covariances) #The above script produces the sesem object stored as truelove_results data=truelove_results plotmodelfit(truelove_results) #note that the warnings that arise here can be ignored plotmodelfit(truelove_results,rmsea_err=FALSE) plotmodelfit(truelove_results,plots="chi")
#data=truelove #distancematrix<-calc.dist(truelove) #Truelove_bins<-make.bin(distancematrix,type="ALL",p.dist=20) #binsize<-Truelove_bins[1][[1]] #truelove lowland bin sizes #binname<-Truelove_bins[2][[1]] #truelove lowland bin names #covariances<-make.covar(truelove,distancematrix,binsize,binname) #covariances # path model for the truelove dataset #spatial_model<-' # Gram ~ Moisture # N_Fix ~ Bryoph + Lich + SoilCrust # SoilCrust ~ Bryoph + Lich + Gram + Shrubs + Forbs # Bryoph ~ Gram + Shrubs + Forbs + Moisture # Lich ~ Moisture + Forbs + Gram + Shrubs + Bryoph # Forbs ~ Moisture # Gram ~~ Forbs # Shrubs ~ Moisture # Gram ~~ Shrubs # Shrubs ~~ Forbs # ' # #results<-runModels(spatial_model,covariances) #The above script produces the sesem object stored as truelove_results data=truelove_results plotmodelfit(truelove_results) #note that the warnings that arise here can be ignored plotmodelfit(truelove_results,rmsea_err=FALSE) plotmodelfit(truelove_results,plots="chi")
A function to plot unstandardized path coefficients across lag distances. The default is to plot all directed paths with standard error bars, and greyed bars to indicate nonsignificant paths (z>0.05). A range of options are available to change the paths plotted, to add trendlines, and to alter the look of the plots.
plotpath(spatial_model_results, path.type = "directed", selectpath = "none selected", add.line = "none", add.error = T, pcut = 0.05, pch = 16, lwd = 2, lty = 1,cex.main=1.2)
plotpath(spatial_model_results, path.type = "directed", selectpath = "none selected", add.line = "none", add.error = T, pcut = 0.05, pch = 16, lwd = 2, lty = 1,cex.main=1.2)
spatial_model_results |
a list object produced by function runModels |
path.type |
An option to select the paths to be plotted. "directed" = only directed paths plotted; "undirected" = only undirected correlations plotted; "both" = all paths plotted; "user" = allows user to specify particular paths and a particular order for plotting. Argument selectpath must also be provided with path.type="user" |
selectpath |
An option to select specific paths for plotting. Usage is as follows: selectpath==c(5,18,16,23,29) where values refer to path numbers. Path numbers can be obtained using spatial_model_results[[2]] |
add.line |
Options for plotting a fit line. "none" indicates no line; "step" plots straight line segments between points; "smooth" plots a smoothed curve fit using function lowess |
add.error |
Should standard error bars be added for each path coefficient |
pcut |
p-value cutoff above which points with non significant p-values are shaded grey. Set pcut=1 to have all points black. |
pch |
Selects plotting symbols |
lwd |
Sets trendline width |
lty |
Sets trendline format |
cex.main |
Sets plot title font |
Eric Lamb
Lamb, E. G., K. Mengersen, K. J. Stewart, U. Attanayake, and S. D. Siciliano. 2014. Spatially explicit structural equation modeling. Ecology 95:2434-2442.
Rosseel, Y. 2012 lavaan: an R package for structural equation modeling. Journal of Statistical Software 48:1-36.
sem
, make.covar
, runModels
, modelsummary
, plotmodelfit
, gam.path
#data=truelove #distancematrix<-calc.dist(truelove) #Truelove_bins<-make.bin(distancematrix,type="ALL",p.dist=20) #binsize<-Truelove_bins[1][[1]] #truelove lowland bin sizes #binname<-Truelove_bins[2][[1]] #truelove lowland bin names #covariances<-make.covar(truelove,distancematrix,binsize,binname) #covariances # path model for the truelove dataset #spatial_model<-' # Gram ~ Moisture # N_Fix ~ Bryoph + Lich + SoilCrust # SoilCrust ~ Bryoph + Lich + Gram + Shrubs + Forbs # Bryoph ~ Gram + Shrubs + Forbs + Moisture # Lich ~ Moisture + Forbs + Gram + Shrubs + Bryoph # Forbs ~ Moisture # Gram ~~ Forbs # Shrubs ~ Moisture # Gram ~~ Shrubs # Shrubs ~~ Forbs # ' # #results<-runModels(spatial_model,covariances) #The above script produces the sesem object stored as truelove_results data=truelove_results plotpath(truelove_results) truelove_results[[2]]# list of path names plotpath(truelove_results,path.type="user",selectpath=c(5,7,8))
#data=truelove #distancematrix<-calc.dist(truelove) #Truelove_bins<-make.bin(distancematrix,type="ALL",p.dist=20) #binsize<-Truelove_bins[1][[1]] #truelove lowland bin sizes #binname<-Truelove_bins[2][[1]] #truelove lowland bin names #covariances<-make.covar(truelove,distancematrix,binsize,binname) #covariances # path model for the truelove dataset #spatial_model<-' # Gram ~ Moisture # N_Fix ~ Bryoph + Lich + SoilCrust # SoilCrust ~ Bryoph + Lich + Gram + Shrubs + Forbs # Bryoph ~ Gram + Shrubs + Forbs + Moisture # Lich ~ Moisture + Forbs + Gram + Shrubs + Bryoph # Forbs ~ Moisture # Gram ~~ Forbs # Shrubs ~ Moisture # Gram ~~ Shrubs # Shrubs ~~ Forbs # ' # #results<-runModels(spatial_model,covariances) #The above script produces the sesem object stored as truelove_results data=truelove_results plotpath(truelove_results) truelove_results[[2]]# list of path names plotpath(truelove_results,path.type="user",selectpath=c(5,7,8))
Given a path model (spatial_model) specified using lavaan syntax, and a list object containing covariance matrices generated by make.covar, runs an sem model using function sem from the lavaan package for each lag distance bin.
runModels(spatial_model,covdata)
runModels(spatial_model,covdata)
spatial_model |
a path model specified using lavaan syntax. See the |
covdata |
a list object containing covariance matrices and other descriptors as produced by make.covar |
Given a path model (spatial_model) specified using lavaan syntax, and a list object containing covariance matrices generated by make.covar, runs an sem model using function sem from the lavaan package for each lag distance bin. Produces a list object containing the model results.
1 |
a table of model fit estimates for each model. See the lavaan documentation for an explanation of each value. |
2 |
table containing a vector of parameter numbers and a character vector containing the names of the paths included in each model. |
3 |
a table of unstandardized path coefficient estimates for each path in each model |
4 |
standard error of unstandardized path coefficient estimates for each path in each model |
5 |
p-values for each unstandardized path coefficient estimate for each path in each model |
6 |
standardized parameter estimates for each path in each model |
7 |
character vector containing list of names of dependent variables within the models |
8 |
r-square values for each dependent variable in each model |
9 |
names of each path for which there is a modification index value |
10 |
modification index values for each potential path addition for each model |
11 |
a copy of the bin.summary table in the input covdata object |
Should model convergence fail for certain lag bins, those bins will be skipped and no results written.
Eric Lamb
Lamb, E. G., K. Mengersen, K. J. Stewart, U. Attanayake, and S. D. Siciliano. 2014. Spatially explicit structural equation modeling. Ecology 95:2434-2442.
Rosseel, Y. 2012 lavaan: an R package for structural equation modeling. Journal of Statistical Software 48:1-36.
sem
, make.covar
, modelsummary
, plotmodelfit
, plotpath
data=truelove truelove_red<-truelove[c(1:60),c(1:7)] distancematrix<-calc.dist(truelove_red) Truelove_bins<-make.bin(distancematrix,type="ALL",p.dist=10) binsize<-Truelove_bins[1][[1]] #truelove lowland bin sizes binname<-Truelove_bins[2][[1]] #truelove lowland bin names plotbin(distancematrix,binsize) covariances<-make.covar(truelove_red,distancematrix,binsize,binname) covariances # reduced path model for the truelove dataset spatial_model<-' N_Fix ~ Bryoph + Lich + SoilCrust SoilCrust ~ Bryoph + Lich Lich ~ Bryoph + Moisture Bryoph ~ Moisture ' results<-runModels(spatial_model,covariances) plotmodelfit(results,rmsea_err=FALSE)
data=truelove truelove_red<-truelove[c(1:60),c(1:7)] distancematrix<-calc.dist(truelove_red) Truelove_bins<-make.bin(distancematrix,type="ALL",p.dist=10) binsize<-Truelove_bins[1][[1]] #truelove lowland bin sizes binname<-Truelove_bins[2][[1]] #truelove lowland bin names plotbin(distancematrix,binsize) covariances<-make.covar(truelove_red,distancematrix,binsize,binname) covariances # reduced path model for the truelove dataset spatial_model<-' N_Fix ~ Bryoph + Lich + SoilCrust SoilCrust ~ Bryoph + Lich Lich ~ Bryoph + Moisture Bryoph ~ Moisture ' results<-runModels(spatial_model,covariances) plotmodelfit(results,rmsea_err=FALSE)
This dataset summarizes ground cover and nitrogen fixation activity along a 129 point regularly spaced transect on Truelove Lowland, Devon Island, Nunavut, Canada.
A data frame with 129 rows and 10 variables.
Variables are: X, Y, Moisture, N_Fix, SoilCrust, Bryoph, Lich, Forbs, Gram, Shrubs
Stewart, K. J., E. G. Lamb, D. S. Coxon, and S. D. Siciliano. 2011. Bryophyte-cyanobacterial associations as a key factor in N2-fixation across the Canadian Arctic. Plant and Soil 344:335-346.
This list object is an example of the output produced by function make.covar
. It was produced by the following script, and is provided to reduce the computation load of some of the examples in this library.
data=truelove
distancematrix<-calc.dist(truelove)
Truelove_bins<-make.bin(distancematrix,type="ALL",p.dist=20)
binsize<-Truelove_bins[1][[1]] #truelove lowland bin sizes
binname<-Truelove_bins[2][[1]] #truelove lowland bin names
covariances<-make.covar(truelove,distancematrix,binsize,binname)
A list object with covariances for 11 lag distance bins.
calc.dist
, make.bin
, make.covar
This list object is an example of the output produced by function runModels. It was produced by the following script, and is provided to reduce the computation load of some of the examples in this library.
data=truelove
distancematrix<-calc.dist(truelove)
Truelove_bins<-make.bin(distancematrix,type="ALL",p.dist=20)
binsize<-Truelove_bins[1][[1]] #truelove lowland bin sizes
binname<-Truelove_bins[2][[1]] #truelove lowland bin names
covariances<-make.covar(truelove,distancematrix,binsize,binname)
path model for the truelove dataset:
spatial_model<-'
Gram ~ Moisture
N_Fix ~ Bryoph + Lich + SoilCrust
SoilCrust ~ Bryoph + Lich + Gram + Shrubs + Forbs
Bryoph ~ Gram + Shrubs + Forbs + Moisture
Lich ~ Moisture + Forbs + Gram + Shrubs + Bryoph
Forbs ~ Moisture
Gram ~~ Forbs
Shrubs ~ Moisture
Gram ~~ Shrubs
Shrubs ~~ Forbs'
results<-runModels(spatial_model,covariances)
A list object sesem results for the truelove path model and 11 lag distance bins.
calc.dist
, make.bin
, make.covar
, runModels