library(dplyr)
library(lavaan)
library(DiagrammeR)
library(ggplot2)
library(tidyr)
library(lubridate)
source("functions/table_funcs.R")
# For saving SEM diagrams:
library(purrr)
library(DiagrammeRsvg)
library(rsvg)
library(png)
library(grid)
library(ggpubr)
library(patchwork)

Import data

combined=read.csv("data/monthly_averages/monthly_data_compiled_regions.csv",stringsAsFactors = F)
cnames=read.csv("analysis/column_names_region_monthly.csv", stringsAsFactors = F)
dsub=filter(combined, Year>=1995) %>% arrange(Region,Year,Month)
focaldata=dsub[,cnames$Datacolumn]
fvars=cnames$Shortname
colnames(focaldata)=fvars
regions=unique(focaldata$region)
regionorder=c("Far West","West","North","South")
regionorder_pub=c("San Pablo","Suisun","Sacramento","San Joaquin")
focaldata=focaldata%>% 
  mutate(decyear=year+(month-1)/12)
focaldata = focaldata %>% 
  mutate(tzoop=hcope+clad+mysid+pcope+rotif_m,
         tzoop_e=hcope_e+clad_e+mysid_e+pcope_e+rotif_e,
         hzoop=hcope+clad+rotif_m,
         hzoop_e=hcope_e+clad_e+rotif_e,
         pzoop=mysid+pcope,
         pzoop_e=mysid_e+pcope_e,
         turbid=-secchi) 
fvars=c(fvars,"tzoop","tzoop_e",
        "hzoop","hzoop_e",
        "pzoop","pzoop_e","turbid")
cnames=rbind(cnames,data.frame(Longname = c("Total zooplankton biomass",
                                            "Total zooplankton energy",
                                            "Herbivorous zooplankton biomass",
                                            "Herbivorous zooplankton energy",
                                            "Predatory zooplankton biomass",
                                            "Predatory zooplankton energy",
                                            "Turbidity"),
                               Shortname=c("tzoop","tzoop_e",
                                           "hzoop","hzoop_e",
                                           "pzoop","pzoop_e","turbid"),
                               Diagramname=c("total zooplankton",
                                             "total zooplankton\nenergy",
                                             "herbivorous\nzooplankton",
                                             "herbivorous\nzooplankton\nenergy",
                                             "predatory\nzooplankton",
                                             "predatory\nzooplankton\nenergy",
                                             "turbidity"),
                               Datacolumn=NA,Log=c(rep("yes",6),"no"),
                               Color=c("black","black","#ED7D31","#ED7D31","#7030A0",
                                       "#7030A0","#4472C4"),
                               Definition = c("summed zooplankton biomass",
                                              "summed zooplankton energy",
                                              "summed herbivorous zooplankton biomass",
                                              "summed herbivorous zooplankton energy",
                                              "summed predatory zooplankton biomass",
                                              "summed predatory zooplankton energy",
                                              "negative secchi depth")))
#focal variables
varnames=c("temp","flow","turbid","din","chla","hzoop","pzoop","potam","corbic","estfish_bsmt","sside","cent","sbass1_bsmt","marfish_bsmt","hcope","clad","amphi_m","pcope","mysid","rotif_m")
#labels for lagged vars
cnameslag=cnames
cnameslag$Shortname=paste0(cnameslag$Shortname,"_1")
cnameslag$Diagramname=paste(cnameslag$Diagramname,"(t-1)")
cnameslag=rbind(cnames,cnameslag)
#labeld for growth rate
cnamesgr=cnames
cnamesgr$Shortname=paste0(cnamesgr$Shortname,"_gr")
cnamesgr$Diagramname=paste(cnamesgr$Diagramname,"(gr)")
cnameslag=rbind(cnameslag,cnamesgr)
source("analysis/semDiagramFunctions.r")

Data prep

Log transform, scale.
Within and across regions.
Create set with regional monthly means removed.

#log transform
logvars=fvars[cnames$Log=="yes"]
logtrans=function(x) {
  x2=x[which(!is.na(x))]
  if(any(x2==0)) {log(x+min(x2[which(x2>0)],na.rm=T))}
  else {log(x)}
}
focaldatalog = focaldata %>% 
  mutate(flow=flow-min(flow,na.rm=T)) %>%  #get rid of negative flow values
  mutate_at(logvars,logtrans) %>% 
  group_by(region) %>%
  mutate_at(logvars,list("gr"=function(x) {c(NA,diff(x))})) %>% 
  ungroup()
#scale data
fdr0=focaldatalog
tvars=fvars[-(1:3)]
#scaled within regions
fdr=fdr0 %>% 
  group_by(region) %>% 
  #scale
  mutate_at(tvars,scale) %>% 
  #lag
  mutate_at(tvars,list("1"=lag,"2"=function(x) {lag(x,2)})) %>% 
  ungroup() %>% 
  as.data.frame()
#scaled within regions, remove monthly means
fdr_ds=fdr %>% 
  group_by(region,month) %>%
  mutate_at(tvars,list("mm"=function(x) {mean(x,na.rm = T)})) %>% 
  mutate_at(tvars,function(x) {x-mean(x,na.rm = T)}) %>% 
  ungroup() %>% 
  #lag
  group_by(region) %>% 
  mutate_at(tvars,scale) %>% 
  mutate_at(tvars,list("1"=lag,"2"=function(x) {lag(x,2)})) %>% 
  ungroup() %>% 
  as.data.frame()
#scaled across regions
# fdr1=fdr0 %>% 
#   #scale
#   mutate_at(tvars,scale) %>% 
#   #lag
#   group_by(region) %>% 
#   mutate_at(tvars,list("1"=lag,"2"=function(x) {lag(x,2)})) %>% 
#   ungroup() %>% 
#   as.data.frame()
#scaled across regions, monthly means removed
# fdr1_ds=fdr1 %>% 
#   group_by(region,month) %>%
#   mutate_at(tvars,list("mm"=function(x) {mean(x,na.rm = T)})) %>% 
#   mutate_at(tvars,function(x) {x-mean(x,na.rm = T)}) %>% 
#   ungroup() %>% 
#   #lag
#   group_by(region) %>% 
#   mutate_at(tvars,list("1"=lag,"2"=function(x) {lag(x,2)})) %>% 
#   ungroup() %>% 
#   as.data.frame()

Data availability

Exclude individual zooplankton plankton groups from zooplankton model if rare (95% of values in a region are less than the across site mean, or more than 10% of values in a region are zeros).

sside and cent have no data in FW and W.

marfish and clams excluded if 95% of values in a region are less than the across site mean, though this results in marfish being excluded from W.

FW: exclude clad, mysid, corbic, sside/cent
W: exclude clad, corbic, marfish, sside/cent
N: exclude clad, potam, marfish
S: exclude mysid, potam, marfish

dataavail=focaldata %>% 
  gather(var, value, 4:length(fvars)) %>% 
  group_by(var) %>% 
  mutate(varmean=mean(value, na.rm=T)) %>% ungroup() %>% 
  group_by(region, var) %>% 
  summarize(
    propmissing=length(which(is.na(value)))/length(value),
    propzeros=length(which(value==0))/length(which(!is.na(value))),
    exclude=ifelse(quantile(value,probs = 0.95, na.rm = T)<mean(varmean),T,F)) %>% 
  as.data.frame()
## `summarise()` has grouped output by 'region'. You can override using the
## `.groups` argument.
#these variables should not be used (too many zeros)
filter(dataavail,propzeros>0.1 | exclude) %>% filter(var %in% c("mysid","hcope","pcope","rotif_m","clad"))
##     region   var propmissing  propzeros exclude
## 1 Far West  clad 0.141025641 0.72388060    TRUE
## 2 Far West mysid 0.137820513 0.21933086    TRUE
## 3    North  clad 0.012820513 0.11363636   FALSE
## 4    South mysid 0.006410256 0.08709677    TRUE
## 5     West  clad 0.009615385 0.20064725   FALSE
filter(dataavail,exclude) %>% filter(var %in% c("marfish_bsmt","potam","corbic"))
##     region          var propmissing propzeros exclude
## 1 Far West       corbic   0.1410256 1.0000000    TRUE
## 2    North marfish_bsmt   0.1891026 0.9762846    TRUE
## 3    North        potam   0.1378205 0.1486989    TRUE
## 4    South marfish_bsmt   0.1826923 1.0000000    TRUE
## 5    South        potam   0.1378205 0.9702602    TRUE
## 6     West       corbic   0.1378205 0.8066914    TRUE
## 7     West marfish_bsmt   0.1666667 0.2192308    TRUE

Time series plots

Other useful plots

Breakdown of total zooplankton biomass.

## Warning: Removed 272 rows containing non-finite values (`stat_align()`).

Correlation between biomass and energy.

for(i in 1:length(regions)) {
  dtemp=filter(fdr,region==regions[i])
  print(regions[i])
  print(cor(dtemp$tzoop,dtemp$tzoop_e,use = "p"))
  print(cor(dtemp$hzoop,dtemp$hzoop_e,use = "p"))
  print(cor(dtemp$pzoop,dtemp$pzoop_e,use = "p"))
}
## [1] "Far West"
##           [,1]
## [1,] 0.9941835
##           [,1]
## [1,] 0.9945149
##           [,1]
## [1,] 0.9996106
## [1] "North"
##           [,1]
## [1,] 0.9938912
##           [,1]
## [1,] 0.9903659
##          [,1]
## [1,] 0.999494
## [1] "South"
##           [,1]
## [1,] 0.9955739
##           [,1]
## [1,] 0.9952125
##         [,1]
## [1,] 0.99925
## [1] "West"
##           [,1]
## [1,] 0.9797348
##           [,1]
## [1,] 0.9374501
##           [,1]
## [1,] 0.9983814

Cross-correlation matrices

(only sig correlations shown… no correction for multiple comparisons)

Other notes:

Detrended fish indices are NOT correlated in S!

Nitrate and ammonia are positively correlated, max at lag 0 all regions.
Nitrate and dophos are positively correlated, max at lag 0 all regions.
Ammonia and dophos are positively correlated, lag 0 for FW and S, ammonia lags dphos by 3 months in W and N.

Chla nitrate neg correlated, lag 0.
Chla ammonia neg correlated, lag 0.
Chla dophos relationship unclear.

High flow 2-4 month prev = high chla

Hcope lags chla by 1, positive, except FW.
Clad seem to precede chla by 2, positive.
Amphi relationship unclear, prob bc not eating chla in water column.
In N and W, chla lags potam, negative. The opposite in W.

Mysid and hcope postive, lag 0.
In S and W, hcope lags pcope, negative.

Flow-Turbidity-Estuarine Fishes Relationship

Scatterplots showing relationship between flow and turbidity and fish by region to accompany the discussion regarding flow-fish relationship. This shows how flow transports estuarine fishes downstream at a monthly scale, but turbidity-flow correlation swamps out the positive flow-fish relationship in San Pablo Bay.

## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 12 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 12 rows containing missing values (`geom_point()`).

## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 12 rows containing non-finite values (`stat_smooth()`).
## Removed 12 rows containing missing values (`geom_point()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 223 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 223 rows containing missing values (`geom_point()`).

## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 223 rows containing non-finite values (`stat_smooth()`).
## Removed 223 rows containing missing values (`geom_point()`).

Make a definition table

Make a table similar to table 1 in Mac Nally et al. 2010 in Eco. Apps.

## Warning: There was 1 warning in `summarise()`.
## ℹ In argument: `across(everything(), .f = mean, na.rm = TRUE)`.
## ℹ In group 1: `year_month = 1995-01-01`.
## Caused by warning:
## ! The `...` argument of `across()` is deprecated as of dplyr 1.1.0.
## Supply arguments directly to `.fns` through an anonymous function instead.
## 
##   # Previously
##   across(a:b, mean, na.rm = TRUE)
## 
##   # Now
##   across(a:b, \(x) mean(x, na.rm = TRUE))
## `summarise()` has grouped output by 'Shortname', 'Longname'. You can override
## using the `.groups` argument.
Variable Years (missing years) Definition
Ammonia 1995‒2020 (0) from the Discrete Environmental Monitoring Program (EMP) at DWR - year-round
Amphipods catch 1997‒2020 (18) from 5 different sources - year-round - see Bashevkin et al. 2022
Amphipods mass 1997‒2020 (18) from 5 different sources - year-round - see Bashevkin et al. 2022
Centrarchids DJFMP 1995‒2020 (3) year-round - beach seines - biomass
Phytoplankton 1995‒2020 (0) from the Discrete Environmental Monitoring Program (EMP) at DWR - year-round
Cladocera 1995‒2020 (2) from 5 different sources - year-round - see Bashevkin et al. 2022
Cladocera catch 1995‒2020 (2) from 5 different sources - year-round - see Bashevkin et al. 2022
Cladocera energy 1995‒2020 (2) from 5 different sources - year-round - see Bashevkin et al. 2022
Corbicula 1997‒2020 (18) from the Environmental Monitoring Program (EMP) Benthic Survey at DWR - year-round
Dissolved Inorganic Nitrogen 1995‒2020 (0) from the Discrete Environmental Monitoring Program (EMP) at DWR - year-round
Dissolved Orthophos 1995‒2020 (0) from the Discrete Environmental Monitoring Program (EMP) at DWR - year-round
Estuarine fishes BSMT 1995‒2020 (38) year-round - midwater trawl - biomass of estuarine pelagic forage fishes
Estuarine fishes BSOT 1995‒2020 (18) year-round - otter trawl - biomass of estuarine pelagic forage fishes
Flow 1995‒2020 (0) year-round - mean Delta outflow (water leaving the Delta to the Bay)
Herbivorous copepods 1995‒2020 (2) from 5 different sources - year-round - see Bashevkin et al. 2022
Herbivorous copepods catch 1995‒2020 (2) from 5 different sources - year-round - see Bashevkin et al. 2022
Herbivorous copepods energy 1995‒2020 (2) from 5 different sources - year-round - see Bashevkin et al. 2022
Herbivorous zooplankton biomass 1995‒2020 (2) summed herbivorous zooplankton biomass
Herbivorous zooplankton energy 1995‒2020 (2) summed herbivorous zooplankton energy
Longfin smelt BSMT 1995‒2020 (38) year-round - midwater trawl - biomass
Longfin smelt BSOT 1995‒2020 (18) year-round - otter trawl - biomass
Marine fishes BSMT 1995‒2020 (38) year-round - midwater trawl - biomass
Marine fishes BSOT 1995‒2020 (18) year-round - otter trawl - biomass
Mysids 1995‒2020 (2) from 5 different sources - year-round - see Bashevkin et al. 2022
Mysids catch 1995‒2020 (2) from 5 different sources - year-round - see Bashevkin et al. 2022
Mysids energy 1995‒2020 (2) from 5 different sources - year-round - see Bashevkin et al. 2022
Nitrate and Nitrite 1995‒2020 (0) from the Discrete Environmental Monitoring Program (EMP) at DWR - year-round
Predatory copepods 1995‒2020 (2) from 5 different sources - year-round - see Bashevkin et al. 2022
Predatory copepods catch 1995‒2020 (2) from 5 different sources - year-round - see Bashevkin et al. 2022
Predatory copepods energy 1995‒2020 (2) from 5 different sources - year-round - see Bashevkin et al. 2022
Potamocorbula 1997‒2020 (18) from the Environmental Monitoring Program (EMP) Benthic Survey at DWR - year-round
Predatory zooplankton biomass 1995‒2020 (2) summed predatory zooplankton biomass
Predatory zooplankton energy 1995‒2020 (2) summed predatory zooplankton energy
Rotifers catch 1995‒2020 (2) from 5 different sources - year-round - see Bashevkin et al. 2022
Rotifers energy 1995‒2020 (2) from 5 different sources - year-round - see Bashevkin et al. 2022
Rotifers mass 1995‒2020 (2) from 5 different sources - year-round - see Bashevkin et al. 2022
Striped bass age 1+ BSMT 1995‒2020 (38) year-round - midwater trawl - biomass of age 1+ individuals
Striped bass age 1+ BSOT 1995‒2020 (18) year-round - otter trawl - biomass of age 1+ individuals
Striped bass BSMT 1995‒2020 (38) year-round - midwater trawl - biomass of age 0 individuals
Striped bass BSOT 1995‒2020 (18) year-round - otter trawl - biomass of age 0 individuals
Secchi 1995‒2020 (0) from the Discrete Environmental Monitoring Program (EMP) at DWR - year-round
Delta smelt BSMT 1995‒2020 (38) year-round - midwater trawl - biomass
Delta smelt BSOT 1995‒2020 (18) year-round - otter trawl - biomass
Mississippi silverside DJFMP 1995‒2020 (3) year-round - beach seines - biomass
Temperature 1995‒2020 (0) from the Discrete Environmental Monitoring Program (EMP) at DWR - year-round
Turbidity 1995‒2020 (0) negative secchi depth
Total zooplankton biomass 1995‒2020 (2) summed zooplankton biomass
Total zooplankton energy 1995‒2020 (2) summed zooplankton energy

Exploratory plots

Fish-centered model (upper trophic level aggregates)

modFW='hzoop~hb1*chla_1+hs1*hzoop_1+ht1*pzoop_1+ht2*potam_1+ht3*estfish_bsmt_1+ha1*flow+ha2*temp+ha3*turbid
        pzoop~pb1*hzoop_1+ps1*pzoop_1+pt1*potam_1+pt2*estfish_bsmt_1+pa1*flow+pa2*temp+pa3*turbid
        estfish_bsmt~fb1*hzoop_1+fb2*pzoop_1+fs1*estfish_bsmt_1+fa1*flow+fa2*temp+fa3*turbid+ft1*marfish_bsmt_1+ft2*sbass1_bsmt_1
        
        hb:=sqrt(hb1^2)
        hs:=sqrt(hs1^2)
        ht:=sqrt(ht1^2+ht2^2+ht3^2)
        ha:=sqrt(ha1^2+ha2^2+ha3^2)
        
        pb:=sqrt(pb1^2)
        ps:=sqrt(ps1^2)
        pt:=sqrt(pt1^2+pt2^2)
        pa:=sqrt(pa1^2+pa2^2+pa3^2)
        
        fb:=sqrt(fb1^2+fb2^2)
        fs:=sqrt(fs1^2)
        ft:=sqrt(ft1^2+ft2^2)
        fa:=sqrt(fa1^2+fa2^2+fa3^2)
'
modW='hzoop~hb1*chla_1+hs1*hzoop_1+ht1*pzoop_1+ht2*potam_1+ht3*estfish_bsmt_1+ha1*flow+ha2*temp+ha3*turbid
        pzoop~pb1*chla_1+pb2*hzoop_1+ps1*pzoop_1+pt1*potam_1+pt2*estfish_bsmt_1+pa1*flow+pa2*temp+pa3*turbid
        estfish_bsmt~fb1*hzoop_1+fb2*pzoop_1+fs1*estfish_bsmt_1+fa1*flow+fa2*temp+fa3*turbid+ft1*sbass1_bsmt_1
        
        hb:=sqrt(hb1^2)
        hs:=sqrt(hs1^2)
        ht:=sqrt(ht1^2+ht2^2+ht3^2)
        ha:=sqrt(ha1^2+ha2^2+ha3^2)
        
        pb:=sqrt(pb1^2+pb2^2)
        ps:=sqrt(ps1^2)
        pt:=sqrt(pt1^2+pt2^2)
        pa:=sqrt(pa1^2+pa2^2+pa3^2)
        
        fb:=sqrt(fb1^2+fb2^2)
        fs:=sqrt(fs1^2)
        ft:=sqrt(ft1^2)
        fa:=sqrt(fa1^2+fa2^2+fa3^2)
'
modN='hzoop~hb1*chla_1+hs1*hzoop_1+ht1*pzoop_1+ht2*corbic_1+ht3*estfish_bsmt_1+ha1*flow+ha2*temp+ha3*turbid
        pzoop~pb1*chla_1+pb2*hzoop_1+ps1*pzoop_1+pt1*corbic_1+pt2*estfish_bsmt_1+pa1*flow+pa2*temp+pa3*turbid
        estfish_bsmt~fb1*hzoop_1+fb2*pzoop_1+fs1*estfish_bsmt_1+fa1*flow+fa2*temp+fa3*turbid+ft1*sside_1+ft2*cent_1+ft3*sbass1_bsmt_1
        
        hb:=sqrt(hb1^2)
        hs:=sqrt(hs1^2)
        ht:=sqrt(ht1^2+ht2^2+ht3^2)
        ha:=sqrt(ha1^2+ha2^2+ha3^2)
        
        pb:=sqrt(pb1^2+pb2^2)
        ps:=sqrt(ps1^2)
        pt:=sqrt(pt1^2+pt2^2)
        pa:=sqrt(pa1^2+pa2^2+pa3^2)
        
        fb:=sqrt(fb1^2+fb2^2)
        fs:=sqrt(fs1^2)
        ft:=sqrt(ft1^2+ft2^2+ft3^2)
        fa:=sqrt(fa1^2+fa2^2+fa3^2)
'
modS='hzoop~hb1*chla_1+hs1*hzoop_1+ht1*pzoop_1+ht2*corbic_1+ht3*estfish_bsmt_1+ha1*flow+ha2*temp+ha3*turbid
        pzoop~pb1*chla_1+pb2*hzoop_1+ps1*pzoop_1+pt1*corbic_1+pt2*estfish_bsmt_1+pa1*flow+pa2*temp+pa3*turbid
        estfish_bsmt~fb1*chla_1+fb2*hzoop_1+fb3*pzoop_1+fs1*estfish_bsmt_1+fa1*flow+fa2*temp+fa3*turbid+ft1*sside_1+ft2*cent_1+ft3*sbass1_bsmt_1
        
        hb:=sqrt(hb1^2)
        hs:=sqrt(hs1^2)
        ht:=sqrt(ht1^2+ht2^2+ht3^2)
        ha:=sqrt(ha1^2+ha2^2+ha3^2)
        
        pb:=sqrt(pb1^2+pb2^2)
        ps:=sqrt(ps1^2)
        pt:=sqrt(pt1^2+pt2^2)
        pa:=sqrt(pa1^2+pa2^2+pa3^2)
        
        fb:=sqrt(fb1^2+fb2^2+fb3^2)
        fs:=sqrt(fs1^2)
        ft:=sqrt(ft1^2+ft2^2+ft3^2)
        fa:=sqrt(fa1^2+fa2^2+fa3^2)
'
modfitFW=sem(modFW, data=filter(fdr_ds,region=="Far West"))
modfitW=sem(modW, data=filter(fdr_ds,region=="West"))
modfitN=sem(modN, data=filter(fdr_ds,region=="North"))
modfitS=sem(modS, data=filter(fdr_ds,region=="South"))
summary(modfitFW, standardized=T, rsq=T)
## lavaan 0.6.17 ended normally after 15 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        29
## 
##                                                   Used       Total
##   Number of observations                           191         312
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 7.526
##   Degrees of freedom                                 7
##   P-value (Chi-square)                           0.376
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   hzoop ~                                                               
##     chla_1   (hb1)   -0.002    0.076   -0.022    0.982   -0.002   -0.001
##     hzoop_1  (hs1)    0.315    0.065    4.851    0.000    0.315    0.326
##     pzoop_1  (ht1)    0.062    0.062    0.991    0.322    0.062    0.065
##     potam_1  (ht2)   -0.189    0.058   -3.246    0.001   -0.189   -0.212
##     estfs__1 (ht3)   -0.176    0.069   -2.552    0.011   -0.176   -0.175
##     flow     (ha1)   -0.021    0.075   -0.272    0.785   -0.021   -0.020
##     temp     (ha2)   -0.080    0.072   -1.110    0.267   -0.080   -0.076
##     turbid   (ha3)    0.040    0.080    0.501    0.616    0.040    0.036
##   pzoop ~                                                               
##     hzoop_1  (pb1)    0.055    0.067    0.811    0.417    0.055    0.054
##     pzoop_1  (ps1)    0.344    0.065    5.278    0.000    0.344    0.348
##     potam_1  (pt1)   -0.102    0.060   -1.697    0.090   -0.102   -0.110
##     estfs__1 (pt2)   -0.031    0.072   -0.428    0.668   -0.031   -0.029
##     flow     (pa1)    0.082    0.078    1.050    0.294    0.082    0.076
##     temp     (pa2)   -0.020    0.075   -0.272    0.786   -0.020   -0.019
##     turbid   (pa3)    0.252    0.084    3.005    0.003    0.252    0.215
##   estfish_bsmt ~                                                        
##     hzoop_1  (fb1)   -0.178    0.056   -3.151    0.002   -0.178   -0.192
##     pzoop_1  (fb2)    0.116    0.056    2.076    0.038    0.116    0.128
##     estfs__1 (fs1)    0.343    0.064    5.369    0.000    0.343    0.355
##     flow     (fa1)    0.092    0.068    1.349    0.177    0.092    0.092
##     temp     (fa2)   -0.032    0.065   -0.497    0.619   -0.032   -0.032
##     turbid   (fa3)    0.246    0.073    3.390    0.001    0.246    0.230
##     mrfsh__1 (ft1)    0.001    0.064    0.019    0.985    0.001    0.001
##     sbss1__1 (ft2)   -0.018    0.065   -0.285    0.776   -0.018   -0.019
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .hzoop ~~                                                              
##    .pzoop            -0.034    0.058   -0.586    0.558   -0.034   -0.042
##    .estfish_bsmt     -0.045    0.050   -0.905    0.365   -0.045   -0.066
##  .pzoop ~~                                                              
##    .estfish_bsmt     -0.088    0.052   -1.684    0.092   -0.088   -0.123
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .hzoop             0.773    0.079    9.772    0.000    0.773    0.754
##    .pzoop             0.842    0.086    9.772    0.000    0.842    0.750
##    .estfish_bsmt      0.606    0.062    9.772    0.000    0.606    0.641
## 
## R-Square:
##                    Estimate
##     hzoop             0.246
##     pzoop             0.250
##     estfish_bsmt      0.359
## 
## Defined Parameters:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##     hb                0.002    0.076    0.022    0.982    0.002    0.001
##     hs                0.315    0.065    4.851    0.000    0.315    0.326
##     ht                0.266    0.058    4.617    0.000    0.266    0.283
##     ha                0.092    0.072    1.283    0.199    0.092    0.086
##     pb                0.055    0.067    0.811    0.417    0.055    0.054
##     ps                0.344    0.065    5.278    0.000    0.344    0.348
##     pt                0.107    0.058    1.837    0.066    0.107    0.113
##     pa                0.265    0.073    3.627    0.000    0.265    0.229
##     fb                0.212    0.059    3.618    0.000    0.212    0.231
##     fs                0.343    0.064    5.369    0.000    0.343    0.355
##     ft                0.018    0.064    0.286    0.775    0.018    0.019
##     fa                0.265    0.062    4.263    0.000    0.265    0.249
summary(modfitW, standardized=T, rsq=T)
## lavaan 0.6.17 ended normally after 17 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        29
## 
##                                                   Used       Total
##   Number of observations                           210         312
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 2.513
##   Degrees of freedom                                 4
##   P-value (Chi-square)                           0.642
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   hzoop ~                                                               
##     chla_1   (hb1)    0.075    0.063    1.187    0.235    0.075    0.073
##     hzoop_1  (hs1)    0.360    0.072    5.019    0.000    0.360    0.349
##     pzoop_1  (ht1)    0.034    0.064    0.529    0.597    0.034    0.033
##     potam_1  (ht2)   -0.232    0.069   -3.369    0.001   -0.232   -0.216
##     estfs__1 (ht3)   -0.018    0.063   -0.287    0.774   -0.018   -0.017
##     flow     (ha1)    0.197    0.070    2.833    0.005    0.197    0.185
##     temp     (ha2)    0.025    0.061    0.414    0.679    0.025    0.025
##     turbid   (ha3)   -0.202    0.068   -2.974    0.003   -0.202   -0.187
##   pzoop ~                                                               
##     chla_1   (pb1)    0.185    0.060    3.065    0.002    0.185    0.186
##     hzoop_1  (pb2)    0.112    0.069    1.617    0.106    0.112    0.112
##     pzoop_1  (ps1)    0.414    0.062    6.675    0.000    0.414    0.411
##     potam_1  (pt1)   -0.089    0.066   -1.347    0.178   -0.089   -0.085
##     estfs__1 (pt2)    0.034    0.061    0.569    0.570    0.034    0.034
##     flow     (pa1)   -0.106    0.067   -1.577    0.115   -0.106   -0.103
##     temp     (pa2)    0.187    0.059    3.179    0.001    0.187    0.190
##     turbid   (pa3)    0.037    0.066    0.561    0.575    0.037    0.035
##   estfish_bsmt ~                                                        
##     hzoop_1  (fb1)    0.135    0.071    1.896    0.058    0.135    0.132
##     pzoop_1  (fb2)   -0.079    0.069   -1.147    0.251   -0.079   -0.077
##     estfs__1 (fs1)    0.175    0.072    2.430    0.015    0.175    0.169
##     flow     (fa1)   -0.222    0.074   -2.985    0.003   -0.222   -0.210
##     temp     (fa2)    0.017    0.064    0.269    0.788    0.017    0.017
##     turbid   (fa3)    0.248    0.071    3.503    0.000    0.248    0.232
##     sbss1__1 (ft1)    0.233    0.069    3.382    0.001    0.233    0.224
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .hzoop ~~                                                              
##    .pzoop             0.179    0.049    3.660    0.000    0.179    0.261
##    .estfish_bsmt     -0.078    0.053   -1.483    0.138   -0.078   -0.103
##  .pzoop ~~                                                              
##    .estfish_bsmt      0.136    0.052    2.633    0.008    0.136    0.185
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .hzoop             0.708    0.069   10.247    0.000    0.708    0.669
##    .pzoop             0.664    0.065   10.247    0.000    0.664    0.666
##    .estfish_bsmt      0.813    0.079   10.247    0.000    0.813    0.787
## 
## R-Square:
##                    Estimate
##     hzoop             0.331
##     pzoop             0.334
##     estfish_bsmt      0.213
## 
## Defined Parameters:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##     hb                0.075    0.063    1.187    0.235    0.075    0.073
##     hs                0.360    0.072    5.019    0.000    0.360    0.349
##     ht                0.235    0.069    3.401    0.001    0.235    0.219
##     ha                0.284    0.076    3.748    0.000    0.284    0.264
##     pb                0.216    0.054    4.041    0.000    0.216    0.217
##     ps                0.414    0.062    6.675    0.000    0.414    0.411
##     pt                0.095    0.063    1.518    0.129    0.095    0.092
##     pa                0.218    0.063    3.477    0.001    0.218    0.219
##     fb                0.156    0.080    1.956    0.050    0.156    0.153
##     fs                0.175    0.072    2.430    0.015    0.175    0.169
##     ft                0.233    0.069    3.382    0.001    0.233    0.224
##     fa                0.333    0.082    4.058    0.000    0.333    0.314
summary(modfitN, standardized=T, rsq=T)
## lavaan 0.6.17 ended normally after 13 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        31
## 
##                                                   Used       Total
##   Number of observations                           193         312
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 8.253
##   Degrees of freedom                                 8
##   P-value (Chi-square)                           0.409
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   hzoop ~                                                               
##     chla_1   (hb1)    0.037    0.066    0.556    0.578    0.037    0.037
##     hzoop_1  (hs1)    0.216    0.070    3.067    0.002    0.216    0.212
##     pzoop_1  (ht1)    0.040    0.073    0.544    0.586    0.040    0.039
##     corbic_1 (ht2)    0.005    0.068    0.071    0.944    0.005    0.005
##     estfs__1 (ht3)   -0.079    0.068   -1.160    0.246   -0.079   -0.084
##     flow     (ha1)    0.242    0.075    3.200    0.001    0.242    0.241
##     temp     (ha2)    0.107    0.066    1.624    0.104    0.107    0.111
##     turbid   (ha3)    0.189    0.070    2.720    0.007    0.189    0.185
##   pzoop ~                                                               
##     chla_1   (pb1)    0.247    0.059    4.195    0.000    0.247    0.248
##     hzoop_1  (pb2)    0.176    0.063    2.812    0.005    0.176    0.172
##     pzoop_1  (ps1)    0.232    0.065    3.585    0.000    0.232    0.229
##     corbic_1 (pt1)    0.031    0.060    0.516    0.606    0.031    0.030
##     estfs__1 (pt2)   -0.060    0.060   -0.990    0.322   -0.060   -0.064
##     flow     (pa1)   -0.436    0.067   -6.515    0.000   -0.436   -0.436
##     temp     (pa2)    0.079    0.058    1.349    0.177    0.079    0.082
##     turbid   (pa3)    0.004    0.062    0.063    0.950    0.004    0.004
##   estfish_bsmt ~                                                        
##     hzoop_1  (fb1)    0.152    0.074    2.057    0.040    0.152    0.139
##     pzoop_1  (fb2)    0.012    0.075    0.162    0.871    0.012    0.011
##     estfs__1 (fs1)    0.130    0.071    1.824    0.068    0.130    0.129
##     flow     (fa1)   -0.468    0.078   -6.002    0.000   -0.468   -0.435
##     temp     (fa2)   -0.016    0.067   -0.238    0.812   -0.016   -0.015
##     turbid   (fa3)    0.066    0.073    0.911    0.362    0.066    0.060
##     sside_1  (ft1)   -0.018    0.068   -0.263    0.793   -0.018   -0.017
##     cent_1   (ft2)   -0.132    0.069   -1.914    0.056   -0.132   -0.125
##     sbss1__1 (ft3)    0.095    0.071    1.332    0.183    0.095    0.091
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .hzoop ~~                                                              
##    .pzoop             0.177    0.053    3.347    0.001    0.177    0.248
##    .estfish_bsmt     -0.059    0.059   -1.002    0.317   -0.059   -0.072
##  .pzoop ~~                                                              
##    .estfish_bsmt     -0.002    0.052   -0.046    0.964   -0.002   -0.003
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .hzoop             0.803    0.082    9.823    0.000    0.803    0.816
##    .pzoop             0.632    0.064    9.823    0.000    0.632    0.642
##    .estfish_bsmt      0.830    0.085    9.823    0.000    0.830    0.731
## 
## R-Square:
##                    Estimate
##     hzoop             0.184
##     pzoop             0.358
##     estfish_bsmt      0.269
## 
## Defined Parameters:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##     hb                0.037    0.066    0.556    0.578    0.037    0.037
##     hs                0.216    0.070    3.067    0.002    0.216    0.212
##     ht                0.088    0.075    1.171    0.241    0.088    0.093
##     ha                0.325    0.071    4.605    0.000    0.325    0.323
##     pb                0.303    0.058    5.211    0.000    0.303    0.302
##     ps                0.232    0.065    3.585    0.000    0.232    0.229
##     pt                0.067    0.063    1.074    0.283    0.067    0.071
##     pa                0.443    0.065    6.848    0.000    0.443    0.443
##     fb                0.152    0.072    2.107    0.035    0.152    0.139
##     fs                0.130    0.071    1.824    0.068    0.130    0.129
##     ft                0.163    0.063    2.587    0.010    0.163    0.156
##     fa                0.473    0.080    5.935    0.000    0.473    0.440
summary(modfitS, standardized=T, rsq=T)
## lavaan 0.6.17 ended normally after 14 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        32
## 
##                                                   Used       Total
##   Number of observations                           199         312
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 5.565
##   Degrees of freedom                                 7
##   P-value (Chi-square)                           0.591
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   hzoop ~                                                               
##     chla_1   (hb1)    0.258    0.072    3.575    0.000    0.258    0.241
##     hzoop_1  (hs1)    0.217    0.069    3.140    0.002    0.217    0.208
##     pzoop_1  (ht1)   -0.030    0.076   -0.391    0.695   -0.030   -0.027
##     corbic_1 (ht2)    0.073    0.070    1.046    0.295    0.073    0.068
##     estfs__1 (ht3)    0.003    0.069    0.048    0.961    0.003    0.003
##     flow     (ha1)    0.213    0.071    2.979    0.003    0.213    0.195
##     temp     (ha2)    0.171    0.066    2.579    0.010    0.171    0.169
##     turbid   (ha3)   -0.042    0.068   -0.624    0.533   -0.042   -0.041
##   pzoop ~                                                               
##     chla_1   (pb1)    0.289    0.061    4.755    0.000    0.289    0.290
##     hzoop_1  (pb2)    0.151    0.058    2.598    0.009    0.151    0.156
##     pzoop_1  (ps1)    0.320    0.064    5.004    0.000    0.320    0.317
##     corbic_1 (pt1)   -0.062    0.058   -1.065    0.287   -0.062   -0.062
##     estfs__1 (pt2)    0.016    0.058    0.274    0.784    0.016    0.017
##     flow     (pa1)   -0.134    0.060   -2.216    0.027   -0.134   -0.131
##     temp     (pa2)   -0.035    0.056   -0.627    0.531   -0.035   -0.037
##     turbid   (pa3)    0.095    0.057    1.666    0.096    0.095    0.099
##   estfish_bsmt ~                                                        
##     chla_1   (fb1)    0.144    0.071    2.034    0.042    0.144    0.139
##     hzoop_1  (fb2)    0.144    0.068    2.103    0.035    0.144    0.142
##     pzoop_1  (fb3)   -0.052    0.074   -0.709    0.479   -0.052   -0.050
##     estfs__1 (fs1)    0.190    0.068    2.785    0.005    0.190    0.194
##     flow     (fa1)   -0.096    0.071   -1.359    0.174   -0.096   -0.091
##     temp     (fa2)   -0.027    0.065   -0.422    0.673   -0.027   -0.028
##     turbid   (fa3)    0.210    0.071    2.935    0.003    0.210    0.211
##     sside_1  (ft1)    0.055    0.065    0.859    0.390    0.055    0.056
##     cent_1   (ft2)   -0.073    0.067   -1.085    0.278   -0.073   -0.076
##     sbss1__1 (ft3)    0.067    0.069    0.983    0.325    0.067    0.068
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .hzoop ~~                                                              
##    .pzoop             0.117    0.051    2.300    0.021    0.117    0.165
##    .estfish_bsmt      0.042    0.058    0.730    0.465    0.042    0.052
##  .pzoop ~~                                                              
##    .estfish_bsmt      0.131    0.049    2.647    0.008    0.131    0.191
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .hzoop             0.837    0.084    9.975    0.000    0.837    0.810
##    .pzoop             0.597    0.060    9.975    0.000    0.597    0.664
##    .estfish_bsmt      0.785    0.079    9.975    0.000    0.785    0.810
## 
## R-Square:
##                    Estimate
##     hzoop             0.190
##     pzoop             0.336
##     estfish_bsmt      0.190
## 
## Defined Parameters:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##     hb                0.258    0.072    3.575    0.000    0.258    0.241
##     hs                0.217    0.069    3.140    0.002    0.217    0.208
##     ht                0.079    0.072    1.095    0.274    0.079    0.074
##     ha                0.276    0.071    3.914    0.000    0.276    0.261
##     pb                0.326    0.057    5.686    0.000    0.326    0.329
##     ps                0.320    0.064    5.004    0.000    0.320    0.317
##     pt                0.064    0.057    1.110    0.267    0.064    0.064
##     pa                0.168    0.062    2.706    0.007    0.168    0.169
##     fb                0.210    0.070    2.974    0.003    0.210    0.205
##     fs                0.190    0.068    2.785    0.005    0.190    0.194
##     ft                0.114    0.065    1.750    0.080    0.114    0.116
##     fa                0.232    0.076    3.045    0.002    0.232    0.231
#modificationindices(modfitW, sort=T, maximum.number=20)
#residuals(modfitS)
labelsfarwest=createLabels(modfitFW, cnameslag)
labelswest=createLabels(modfitW, cnameslag)
labelsnorth=createLabels(modfitN, cnameslag)
labelssouth=createLabels(modfitS, cnameslag)
#Extract model coefficients for table
coef_table<-coef_tabler(modfitFW, modfitW, modfitN, modfitS, name="Upper trophic level aggregates")
#FAR WEST
# myLavaanPlot(model=modfitFW, labels=labelsfarwest,
#                        node_options=list(shape="box", fontname="Helvetica"), 
#                        coefs=TRUE, stand=TRUE, covs=FALSE, sig=0.05, 
#                        width=c("regress","latent"),
#                        color=c("regress","latent"))
upper_plot_far_west <- createGraph(fit=modfitFW, 
                                   reference_df=cnameslag, 
                                   model_type="monthly_upper_trophic",
                                   title="San Pablo",
                                   manual_port_settings=TRUE)
upper_plot_far_west
#WEST
# myLavaanPlot(model=modfitW, labels=labelswest,
#                        node_options=list(shape="box", fontname="Helvetica"), 
#                        coefs=TRUE, stand=TRUE, covs=FALSE, sig=0.05, 
#                        width=c("regress","latent"),
#                        color=c("regress","latent"))
upper_plot_west <- createGraph(fit=modfitW, 
                               reference_df=cnameslag, 
                               model_type="monthly_upper_trophic",
                               title="Suisun",
                               manual_port_settings=TRUE)
upper_plot_west
#NORTH
# myLavaanPlot(model=modfitN, labels=labelsnorth,
#                        node_options=list(shape="box", fontname="Helvetica"), 
#                        coefs=TRUE, stand=TRUE, covs=FALSE, sig=0.05, 
#                        width=c("regress","latent"),
#                        color=c("regress","latent"))
upper_plot_north <- createGraph(fit=modfitN, 
                                reference_df=cnameslag, 
                                model_type="monthly_upper_trophic",
                                title="Sacramento",
                                manual_port_settings=TRUE)
upper_plot_north
#SOUTH
# myLavaanPlot(model=modfitS, labels=labelssouth,
#                        node_options=list(shape="box", fontname="Helvetica"), 
#                        coefs=TRUE, stand=TRUE, covs=FALSE, sig=0.05, 
#                        width=c("regress","latent"),
#                        color=c("regress","latent"))
upper_plot_south <- createGraph(fit=modfitS, 
                                reference_df=cnameslag, 
                                model_type="monthly_upper_trophic",
                                title="San Joaquin",
                                manual_port_settings=TRUE)
upper_plot_south

Save updated SEM diagrams

Total effects

ssFW=standardizedsolution(modfitFW) %>% mutate(region="San Pablo")
ssW=standardizedsolution(modfitW) %>% mutate(region="Suisun")
ssN=standardizedsolution(modfitN) %>% mutate(region="Sacramento")
ssS=standardizedsolution(modfitS) %>% mutate(region="San Joaquin")
ssut=rbind(ssFW,ssW,ssN,ssS) %>% filter(op==":=") %>% select(region,lhs,est.std:ci.upper) %>% 
  separate(lhs,c("variable","influence"), sep=1) %>% 
  mutate(variable=case_when(variable=="h" ~ "herbivorous\nzooplankton",
                            variable=="p" ~ "predatory\nzooplankton",
                            variable=="f" ~ "estuarine\nfishes"),
         influence=case_when(influence=="b" ~ "bottom-up",
                            influence=="t" ~ "top-down",
                            influence=="s" ~ "self-regulation",
                            influence=="a" ~ "environmental"),
         region=factor(region, levels=regionorder_pub),
         influence=factor(influence, levels=c("self-regulation","bottom-up","top-down","environmental")),
         variable=factor(variable,levels=c("estuarine\nfishes","predatory\nzooplankton","herbivorous\nzooplankton")),
         sig=ifelse(pvalue<0.05,"*",""))
uteffects<-ggplot(ssut,aes(x=influence,y=est.std)) +
  facet_grid(variable~region) +
  geom_errorbar(aes(ymin=ci.lower, ymax=ci.upper),width=0.5) +
  geom_point() +
  geom_text(aes(y=ci.upper+0.05, label=sig)) +
  geom_hline(yintercept = 0) +
  ggtitle("Monthly regional models: upper trophic level")+
  theme_bw() + 
  theme(axis.text.x=element_text(angle=90, vjust=0.5, hjust=1), plot.title = element_text(hjust = 0.5)) +
  labs(y="total effect (standardized)")

Phytoplankton-centered model (lower trophic level aggregates)

modFW='din~ns1*din_1+nt1*chla+nn1*hzoop_1+nn2*pzoop_1+nn3*potam_1+na1*flow+na2*temp+na3*turbid
        chla~cb1*din_1+cs1*chla_1+ct1*hzoop_1+ct2*potam_1+ca1*flow+ca2*temp+ca3*turbid
        potam~lb1*chla_1+lb2*hzoop_1+lb3*pzoop_1+ls1*potam_1+la1*flow+la2*temp+la3*turbid
        
        ns:=sqrt(ns1^2)
        nt:=sqrt(nt1^2)
        nn:=sqrt(nn1^2+nn2^2+nn3^2)
        na:=sqrt(na1^2+na2^2+na3^2)
        
        cb:=sqrt(cb1^2)
        cs:=sqrt(cs1^2)
        ct:=sqrt(ct1^2+ct2^2)
        ca:=sqrt(ca1^2+ca2^2+ca3^2)
        
        lb:=sqrt(lb1^2+lb2^2+lb3^2)
        ls:=sqrt(ls1^2)
        la:=sqrt(la1^2+la2^2+la3^2)
'
modW='din~ns1*din_1+nt1*chla+nn1*hzoop_1+nn2*pzoop_1+nn3*potam_1+na1*flow+na2*temp+na3*turbid
        chla~cb1*din_1+cs1*chla_1+ct1*hzoop_1+ct2*potam_1+ca1*flow+ca2*temp+ca3*turbid
        potam~lb1*din_1+lb2*chla_1+lb3*hzoop_1+lb4*pzoop_1+ls1*potam_1+la1*flow+la2*temp+la3*turbid
        
        ns:=sqrt(ns1^2)
        nt:=sqrt(nt1^2)
        nn:=sqrt(nn1^2+nn2^2+nn3^2)
        na:=sqrt(na1^2+na2^2+na3^2)
        
        cb:=sqrt(cb1^2)
        cs:=sqrt(cs1^2)
        ct:=sqrt(ct1^2+ct2^2)
        ca:=sqrt(ca1^2+ca2^2+ca3^2)
        
        lb:=sqrt(lb1^2+lb2^2+lb3^2+lb4^2)
        ls:=sqrt(ls1^2)
        la:=sqrt(la1^2+la2^2+la3^2)
'
modN='din~ns1*din_1+nt1*chla+nn1*hzoop_1+nn2*pzoop_1+nn3*corbic_1+na1*flow+na2*temp+na3*turbid
        chla~cb1*din_1+cs1*chla_1+ct1*hzoop_1+ct2*corbic_1+ct3*pzoop_1+ca1*flow+ca2*temp+ca3*turbid
        corbic~lb1*chla_1+lb2*hzoop_1+lb3*pzoop_1+ls1*corbic_1+la1*flow+la2*temp+la3*turbid
        
        ns:=sqrt(ns1^2)
        nt:=sqrt(nt1^2)
        nn:=sqrt(nn1^2+nn2^2+nn3^2)
        na:=sqrt(na1^2+na2^2+na3^2)
        
        cb:=sqrt(cb1^2)
        cs:=sqrt(cs1^2)
        ct:=sqrt(ct1^2+ct2^2+ct3^2)
        ca:=sqrt(ca1^2+ca2^2+ca3^2)
        
        lb:=sqrt(lb1^2+lb2^2+lb3^2)
        ls:=sqrt(ls1^2)
        la:=sqrt(la1^2+la2^2+la3^2)
'
modS='din~ns1*din_1+nt1*chla+nn1*hzoop_1+nn2*pzoop_1+nn3*corbic_1+na1*flow+na2*temp+na3*turbid
        chla~cb1*din_1+cs1*chla_1+ct1*hzoop_1+ct2*corbic_1+ca1*flow+ca2*temp+ca3*turbid
        corbic~lb1*chla_1+lb2*hzoop_1+lb3*pzoop_1+ls1*corbic_1+la1*flow+la2*temp+la3*turbid
        
        ns:=sqrt(ns1^2)
        nt:=sqrt(nt1^2)
        nn:=sqrt(nn1^2+nn2^2+nn3^2)
        na:=sqrt(na1^2+na2^2+na3^2)
        
        cb:=sqrt(cb1^2)
        cs:=sqrt(cs1^2)
        ct:=sqrt(ct1^2+ct2^2)
        ca:=sqrt(ca1^2+ca2^2+ca3^2)
        
        lb:=sqrt(lb1^2+lb2^2+lb3^2)
        ls:=sqrt(ls1^2)
        la:=sqrt(la1^2+la2^2+la3^2)
'
modfitFW=sem(modFW, data=filter(fdr_ds,region=="Far West"))
modfitW=sem(modW, data=filter(fdr_ds,region=="West"))
modfitN=sem(modN, data=filter(fdr_ds,region=="North"))
modfitS=sem(modS, data=filter(fdr_ds,region=="South"))
summary(modfitFW, standardized=T, rsq=T)
## lavaan 0.6.17 ended normally after 14 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        26
## 
##                                                   Used       Total
##   Number of observations                           234         312
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 5.455
##   Degrees of freedom                                 4
##   P-value (Chi-square)                           0.244
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   din ~                                                                 
##     din_1    (ns1)    0.399    0.055    7.254    0.000    0.399    0.401
##     chla     (nt1)   -0.217    0.060   -3.650    0.000   -0.217   -0.199
##     hzoop_1  (nn1)    0.048    0.049    0.982    0.326    0.048    0.055
##     pzoop_1  (nn2)   -0.082    0.048   -1.690    0.091   -0.082   -0.095
##     potam_1  (nn3)   -0.015    0.047   -0.317    0.751   -0.015   -0.018
##     flow     (na1)   -0.163    0.056   -2.890    0.004   -0.163   -0.176
##     temp     (na2)   -0.110    0.053   -2.086    0.037   -0.110   -0.122
##     turbid   (na3)    0.121    0.056    2.141    0.032    0.121    0.130
##   chla ~                                                                
##     din_1    (cb1)    0.012    0.061    0.199    0.842    0.012    0.013
##     chla_1   (cs1)    0.255    0.064    3.977    0.000    0.255    0.260
##     hzoop_1  (ct1)   -0.021    0.052   -0.405    0.686   -0.021   -0.026
##     potam_1  (ct2)   -0.021    0.050   -0.413    0.680   -0.021   -0.027
##     flow     (ca1)    0.059    0.058    1.015    0.310    0.059    0.070
##     temp     (ca2)    0.127    0.056    2.263    0.024    0.127    0.153
##     turbid   (ca3)   -0.045    0.059   -0.752    0.452   -0.045   -0.053
##   potam ~                                                               
##     chla_1   (lb1)    0.073    0.060    1.207    0.228    0.073    0.057
##     hzoop_1  (lb2)   -0.075    0.051   -1.472    0.141   -0.075   -0.073
##     pzoop_1  (lb3)   -0.162    0.050   -3.242    0.001   -0.162   -0.160
##     potam_1  (ls1)    0.629    0.048   13.015    0.000    0.629    0.629
##     flow     (la1)    0.113    0.057    1.973    0.049    0.113    0.103
##     temp     (la2)   -0.042    0.054   -0.774    0.439   -0.042   -0.039
##     turbid   (la3)    0.037    0.058    0.634    0.526    0.037    0.033
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .din ~~                                                                
##    .potam            -0.053    0.036   -1.460    0.144   -0.053   -0.096
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .din               0.532    0.049   10.817    0.000    0.532    0.680
##    .chla              0.596    0.055   10.817    0.000    0.596    0.911
##    .potam             0.568    0.053   10.817    0.000    0.568    0.517
## 
## R-Square:
##                    Estimate
##     din               0.320
##     chla              0.089
##     potam             0.483
## 
## Defined Parameters:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##     ns                0.399    0.055    7.254    0.000    0.399    0.401
##     nt                0.217    0.060    3.650    0.000    0.217    0.199
##     nn                0.096    0.050    1.909    0.056    0.096    0.112
##     na                0.231    0.061    3.770    0.000    0.231    0.250
##     cb                0.012    0.061    0.199    0.842    0.012    0.013
##     cs                0.255    0.064    3.977    0.000    0.255    0.260
##     ct                0.029    0.056    0.526    0.599    0.029    0.038
##     ca                0.147    0.058    2.532    0.011    0.147    0.176
##     lb                0.193    0.050    3.881    0.000    0.193    0.185
##     ls                0.629    0.048   13.015    0.000    0.629    0.629
##     la                0.126    0.049    2.567    0.010    0.126    0.115
summary(modfitW, standardized=T, rsq=T)
## lavaan 0.6.17 ended normally after 12 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        27
## 
##                                                   Used       Total
##   Number of observations                           257         312
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 5.119
##   Degrees of freedom                                 3
##   P-value (Chi-square)                           0.163
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   din ~                                                                 
##     din_1    (ns1)    0.444    0.046    9.626    0.000    0.444    0.443
##     chla     (nt1)   -0.133    0.041   -3.223    0.001   -0.133   -0.129
##     hzoop_1  (nn1)   -0.004    0.044   -0.098    0.922   -0.004   -0.004
##     pzoop_1  (nn2)    0.033    0.041    0.824    0.410    0.033    0.035
##     potam_1  (nn3)    0.037    0.043    0.857    0.391    0.037    0.038
##     flow     (na1)   -0.426    0.046   -9.197    0.000   -0.426   -0.425
##     temp     (na2)    0.036    0.039    0.932    0.351    0.036    0.037
##     turbid   (na3)    0.116    0.042    2.759    0.006    0.116    0.119
##   chla ~                                                                
##     din_1    (cb1)   -0.123    0.070   -1.754    0.080   -0.123   -0.126
##     chla_1   (cs1)    0.149    0.065    2.282    0.022    0.149    0.150
##     hzoop_1  (ct1)    0.065    0.063    1.024    0.306    0.065    0.070
##     potam_1  (ct2)    0.013    0.065    0.200    0.842    0.013    0.014
##     flow     (ca1)    0.076    0.069    1.099    0.272    0.076    0.077
##     temp     (ca2)   -0.060    0.058   -1.031    0.303   -0.060   -0.064
##     turbid   (ca3)   -0.024    0.063   -0.371    0.710   -0.024   -0.025
##   potam ~                                                               
##     din_1    (lb1)    0.014    0.047    0.301    0.763    0.014    0.014
##     chla_1   (lb2)   -0.028    0.044   -0.648    0.517   -0.028   -0.027
##     hzoop_1  (lb3)   -0.006    0.045   -0.134    0.893   -0.006   -0.006
##     pzoop_1  (lb4)    0.073    0.041    1.785    0.074    0.073    0.072
##     potam_1  (ls1)    0.724    0.044   16.557    0.000    0.724    0.719
##     flow     (la1)   -0.128    0.046   -2.778    0.005   -0.128   -0.124
##     temp     (la2)   -0.007    0.039   -0.190    0.849   -0.007   -0.007
##     turbid   (la3)   -0.077    0.042   -1.829    0.067   -0.077   -0.076
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .din ~~                                                                
##    .potam             0.010    0.023    0.441    0.660    0.010    0.027
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .din               0.362    0.032   11.336    0.000    0.362    0.380
##    .chla              0.815    0.072   11.336    0.000    0.815    0.902
##    .potam             0.363    0.032   11.336    0.000    0.363    0.355
## 
## R-Square:
##                    Estimate
##     din               0.620
##     chla              0.098
##     potam             0.645
## 
## Defined Parameters:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##     ns                0.444    0.046    9.626    0.000    0.444    0.443
##     nt                0.133    0.041    3.223    0.001    0.133    0.129
##     nn                0.050    0.044    1.150    0.250    0.050    0.052
##     na                0.443    0.048    9.175    0.000    0.443    0.443
##     cb                0.123    0.070    1.754    0.080    0.123    0.126
##     cs                0.149    0.065    2.282    0.022    0.149    0.150
##     ct                0.066    0.066    0.998    0.318    0.066    0.071
##     ca                0.099    0.067    1.478    0.139    0.099    0.103
##     lb                0.080    0.042    1.902    0.057    0.080    0.079
##     ls                0.724    0.044   16.557    0.000    0.724    0.719
##     la                0.150    0.041    3.645    0.000    0.150    0.146
summary(modfitN, standardized=T, rsq=T)
## lavaan 0.6.17 ended normally after 9 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        27
## 
##                                                   Used       Total
##   Number of observations                           255         312
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 6.897
##   Degrees of freedom                                 3
##   P-value (Chi-square)                           0.075
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   din ~                                                                 
##     din_1    (ns1)    0.408    0.045    9.160    0.000    0.408    0.412
##     chla     (nt1)   -0.160    0.036   -4.480    0.000   -0.160   -0.171
##     hzoop_1  (nn1)    0.070    0.038    1.830    0.067    0.070    0.071
##     pzoop_1  (nn2)    0.060    0.041    1.476    0.140    0.060    0.060
##     corbic_1 (nn3)   -0.035    0.038   -0.929    0.353   -0.035   -0.035
##     flow     (na1)   -0.460    0.044  -10.513    0.000   -0.460   -0.458
##     temp     (na2)    0.042    0.038    1.106    0.269    0.042    0.043
##     turbid   (na3)    0.091    0.037    2.488    0.013    0.091    0.095
##   chla ~                                                                
##     din_1    (cb1)   -0.169    0.079   -2.133    0.033   -0.169   -0.160
##     chla_1   (cs1)    0.187    0.063    2.953    0.003    0.187    0.186
##     hzoop_1  (ct1)   -0.093    0.066   -1.407    0.160   -0.093   -0.088
##     corbic_1 (ct2)   -0.018    0.065   -0.278    0.781   -0.018   -0.017
##     pzoop_1  (ct3)   -0.102    0.071   -1.437    0.151   -0.102   -0.096
##     flow     (ca1)   -0.072    0.075   -0.961    0.336   -0.072   -0.068
##     temp     (ca2)    0.141    0.064    2.208    0.027    0.141    0.136
##     turbid   (ca3)    0.131    0.063    2.087    0.037    0.131    0.128
##   corbic ~                                                              
##     chla_1   (lb1)    0.042    0.052    0.813    0.416    0.042    0.044
##     hzoop_1  (lb2)    0.010    0.056    0.175    0.861    0.010    0.010
##     pzoop_1  (lb3)   -0.015    0.058   -0.265    0.791   -0.015   -0.015
##     corbic_1 (ls1)    0.466    0.056    8.366    0.000    0.466    0.463
##     flow     (la1)    0.090    0.060    1.509    0.131    0.090    0.089
##     temp     (la2)   -0.033    0.055   -0.591    0.555   -0.033   -0.033
##     turbid   (la3)   -0.120    0.053   -2.271    0.023   -0.120   -0.124
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .din ~~                                                                
##    .corbic            0.000    0.030    0.008    0.994    0.000    0.000
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .din               0.325    0.029   11.292    0.000    0.325    0.341
##    .chla              0.962    0.085   11.292    0.000    0.962    0.888
##    .corbic            0.713    0.063   11.292    0.000    0.713    0.738
## 
## R-Square:
##                    Estimate
##     din               0.659
##     chla              0.112
##     corbic            0.262
## 
## Defined Parameters:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##     ns                0.408    0.045    9.160    0.000    0.408    0.412
##     nt                0.160    0.036    4.480    0.000    0.160    0.171
##     nn                0.099    0.034    2.880    0.004    0.099    0.100
##     na                0.470    0.044   10.660    0.000    0.470    0.469
##     cb                0.169    0.079    2.133    0.033    0.169    0.160
##     cs                0.187    0.063    2.953    0.003    0.187    0.186
##     ct                0.139    0.061    2.277    0.023    0.139    0.131
##     ca                0.206    0.065    3.153    0.002    0.206    0.198
##     lb                0.046    0.055    0.831    0.406    0.046    0.048
##     ls                0.466    0.056    8.366    0.000    0.466    0.463
##     la                0.154    0.057    2.707    0.007    0.154    0.156
summary(modfitS, standardized=T, rsq=T)
## lavaan 0.6.17 ended normally after 9 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        26
## 
##                                                   Used       Total
##   Number of observations                           256         312
## 
## Model Test User Model:
##                                                       
##   Test statistic                                23.734
##   Degrees of freedom                                 4
##   P-value (Chi-square)                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   din ~                                                                 
##     din_1    (ns1)    0.406    0.056    7.270    0.000    0.406    0.407
##     chla     (nt1)   -0.144    0.052   -2.768    0.006   -0.144   -0.143
##     hzoop_1  (nn1)   -0.016    0.056   -0.284    0.776   -0.016   -0.015
##     pzoop_1  (nn2)    0.126    0.057    2.210    0.027    0.126    0.116
##     corbic_1 (nn3)    0.048    0.053    0.901    0.368    0.048    0.047
##     flow     (na1)   -0.052    0.054   -0.956    0.339   -0.052   -0.050
##     temp     (na2)    0.054    0.053    1.029    0.303    0.054    0.053
##     turbid   (na3)    0.252    0.058    4.329    0.000    0.252    0.248
##   chla ~                                                                
##     din_1    (cb1)    0.102    0.064    1.598    0.110    0.102    0.103
##     chla_1   (cs1)    0.332    0.060    5.520    0.000    0.332    0.331
##     hzoop_1  (ct1)    0.057    0.063    0.907    0.364    0.057    0.054
##     corbic_1 (ct2)    0.098    0.060    1.632    0.103    0.098    0.097
##     flow     (ca1)   -0.103    0.061   -1.686    0.092   -0.103   -0.100
##     temp     (ca2)    0.018    0.059    0.309    0.757    0.018    0.018
##     turbid   (ca3)   -0.026    0.067   -0.394    0.694   -0.026   -0.026
##   corbic ~                                                              
##     chla_1   (lb1)    0.061    0.058    1.041    0.298    0.061    0.061
##     hzoop_1  (lb2)   -0.025    0.061   -0.403    0.687   -0.025   -0.024
##     pzoop_1  (lb3)   -0.044    0.063   -0.696    0.487   -0.044   -0.041
##     corbic_1 (ls1)    0.315    0.058    5.473    0.000    0.315    0.318
##     flow     (la1)    0.082    0.058    1.407    0.160    0.082    0.081
##     temp     (la2)   -0.078    0.058   -1.355    0.176   -0.078   -0.078
##     turbid   (la3)    0.184    0.058    3.184    0.001    0.184    0.185
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .din ~~                                                                
##    .corbic           -0.019    0.046   -0.402    0.688   -0.019   -0.025
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .din               0.680    0.060   11.314    0.000    0.680    0.650
##    .chla              0.880    0.078   11.314    0.000    0.880    0.852
##    .corbic            0.811    0.072   11.314    0.000    0.811    0.808
## 
## R-Square:
##                    Estimate
##     din               0.350
##     chla              0.148
##     corbic            0.192
## 
## Defined Parameters:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##     ns                0.406    0.056    7.270    0.000    0.406    0.407
##     nt                0.144    0.052    2.768    0.006    0.144    0.143
##     nn                0.136    0.058    2.338    0.019    0.136    0.126
##     na                0.263    0.060    4.414    0.000    0.263    0.258
##     cb                0.102    0.064    1.598    0.110    0.102    0.103
##     cs                0.332    0.060    5.520    0.000    0.332    0.331
##     ct                0.113    0.059    1.931    0.053    0.113    0.111
##     ca                0.108    0.059    1.821    0.069    0.108    0.105
##     lb                0.079    0.065    1.206    0.228    0.079    0.078
##     ls                0.315    0.058    5.473    0.000    0.315    0.318
##     la                0.216    0.055    3.911    0.000    0.216    0.216
#modificationindices(modfitW, sort=T, maximum.number=20)
#residuals(modfitW)
labelsfarwest=createLabels(modfitFW, cnameslag)
labelswest=createLabels(modfitW, cnameslag)
labelsnorth=createLabels(modfitN, cnameslag)
labelssouth=createLabels(modfitS, cnameslag)
#Extract model coefficients for table
coef_table<-bind_rows(coef_table, coef_tabler(modfitFW, modfitW, modfitN, modfitS, name="Lower trophic level aggregates"))
#FAR WEST
# myLavaanPlot(model=modfitFW, labels=labelsfarwest,
#                        node_options=list(shape="box", fontname="Helvetica"), 
#                        coefs=TRUE, stand=TRUE, covs=FALSE, sig=0.05, 
#                        width=c("regress","latent"),
#                        color=c("regress","latent"))
lower_plot_far_west <- createGraph(fit=modfitFW, 
                                   reference_df=cnameslag, 
                                   model_type="monthly_lower_trophic",
                                   title="San Pablo",
                                   manual_port_settings=TRUE)
lower_plot_far_west
#WEST
# myLavaanPlot(model=modfitW, labels=labelswest,
#                        node_options=list(shape="box", fontname="Helvetica"), 
#                        coefs=TRUE, stand=TRUE, covs=FALSE, sig=0.05, 
#                        width=c("regress","latent"),
#                        color=c("regress","latent"))
lower_plot_west <- createGraph(fit=modfitW, 
                               reference_df=cnameslag, 
                               model_type="monthly_lower_trophic",
                               title="Suisun",
                               manual_port_settings=TRUE)
lower_plot_west
#NORTH
# myLavaanPlot(model=modfitN, labels=labelsnorth,
#                        node_options=list(shape="box", fontname="Helvetica"), 
#                        coefs=TRUE, stand=TRUE, covs=FALSE, sig=0.05, 
#                        width=c("regress","latent"),
#                        color=c("regress","latent"))
lower_plot_north <- createGraph(fit=modfitN, 
                                reference_df=cnameslag, 
                                model_type="monthly_lower_trophic",
                                title="Sacramento",
                                manual_port_settings=TRUE)
lower_plot_north
#SOUTH
# myLavaanPlot(model=modfitS, labels=labelssouth,
#                        node_options=list(shape="box", fontname="Helvetica"), 
#                        coefs=TRUE, stand=TRUE, covs=FALSE, sig=0.05, 
#                        width=c("regress","latent"),
#                        color=c("regress","latent"))
lower_plot_south <- createGraph(fit=modfitS, 
                                reference_df=cnameslag, 
                                model_type="monthly_lower_trophic",
                                title="San Joaquin",
                                manual_port_settings=TRUE)
lower_plot_south

Save updated SEM diagrams

Combine upper and lower SEM diagrams

monthly_theme <- theme(plot.margin=unit(c(0,0.1,0.5,0), "lines"))

## Convert the grobs to ggplots, then add extra spacing between the two rows:
upper_ggplots <- lapply(upper_grobs, ggarrange)
upper_ggplots[[1]] <- upper_ggplots[[1]] + monthly_theme
upper_ggplots[[2]] <- upper_ggplots[[2]] + monthly_theme
upper_figure_1 <- ggarrange(plotlist=upper_ggplots, labels=c("(a)","(b)","(c)","(d)"),
                            font.label=list(size=11)) %>%
  annotate_figure(top = text_grob("Monthly regional models: upper trophic level",
                                  color = "black",
                                  face = "bold",
                                  size = 11)) + 
  theme(plot.margin=unit(c(0,0.1,1,0), "lines"))

lower_ggplots <- lapply(lower_grobs, ggarrange)
lower_ggplots[[1]] <- lower_ggplots[[1]] + monthly_theme
lower_ggplots[[2]] <- lower_ggplots[[2]] + monthly_theme
lower_figure_1 <- ggarrange(plotlist=lower_ggplots, labels=c("(e)","(f)","(g)","(h)"),
                            font.label=list(size=11)) %>%
  annotate_figure(top = text_grob("Monthly regional models: lower trophic level",
                                  color = "black",
                                  face = "bold",
                                  size = 11))

combined <- ggarrange(plotlist=list(upper_figure_1, lower_figure_1), ncol=1)
combined

ggsave('./fig_output/sem_upper_and_lower.png', combined, 
       width=15, height=22, dpi=300, bg="white", units="cm")

Total effects

ssFW=standardizedsolution(modfitFW) %>% mutate(region="San Pablo")
ssW=standardizedsolution(modfitW) %>% mutate(region="Suisun")
ssN=standardizedsolution(modfitN) %>% mutate(region="Sacramento")
ssS=standardizedsolution(modfitS) %>% mutate(region="San Joaquin")
sslt=rbind(ssFW,ssW,ssN,ssS) %>% filter(op==":=") %>% select(region,lhs,est.std:ci.upper) %>% 
  separate(lhs,c("variable","influence"), sep=1) %>% 
  mutate(variable=case_when(variable=="n" ~ "DIN",
                            variable=="c" ~ "phytoplankton",
                            variable=="l" ~ "clams"),
         influence=case_when(influence=="b" ~ "bottom-up",
                            influence=="t" ~ "top-down",
                            influence=="s" ~ "self-regulation",
                            influence=="a" ~ "environmental",
                            influence=="n" ~ "nutrient cycling"),
         region=factor(region, levels=regionorder_pub),
         influence=factor(influence, levels=c("self-regulation","bottom-up","top-down","environmental","nutrient cycling")),
         variable=factor(variable,levels=c("clams","phytoplankton","DIN")),
         sig=ifelse(pvalue<0.05,"*",""))
lteffects<-ggplot(sslt,aes(x=influence,y=est.std)) +
  facet_grid(variable~region) +
  geom_errorbar(aes(ymin=ci.lower, ymax=ci.upper),width=0.5) +
  geom_point() +
  geom_text(aes(y=ci.upper+0.05, label=sig)) +
  geom_hline(yintercept = 0) +
  ggtitle("Monthly regional models: lower trophic level")+
  theme_bw() + 
  theme(axis.text.x=element_text(angle=90, vjust=0.5, hjust=1), plot.title = element_text(hjust = 0.5)) +
  labs(y="total effect (standardized)")

teffects<-uteffects/lteffects + plot_annotation(tag_levels="a", tag_prefix="(", tag_suffix=")")
ggsave(plot=teffects, filename="./fig_output/teffects.png",width = 6,height=10)

Zooplankton-centered model (individual groups)

#1
# modFW='chla~chla_1+hcope_1+amphi_m_1+potam_1+flow+turbid+temp
#        hcope~chla_1+hcope_1+pcope_1+potam_1+flow+turbid+temp+estfish_bsmt_1
#        amphi_m~chla_1+amphi_m_1+flow+turbid+temp+estfish_bsmt_1
#        pcope~hcope_1+pcope_1+potam_1+flow+turbid+temp+estfish_bsmt_1
# '
# modW='chla~chla_1+hcope_1+amphi_m_1+potam_1+flow+turbid+temp+mysid_1
#        hcope~chla_1+hcope_1+pcope_1+mysid_1+potam_1+flow+turbid+temp+estfish_bsmt_1
#        amphi_m~chla_1+amphi_m_1+mysid_1+flow+turbid+temp+estfish_bsmt_1
#        pcope~hcope_1+pcope_1+mysid_1+potam_1+flow+turbid+temp+estfish_bsmt_1
#        mysid~chla_1+hcope_1+pcope_1+amphi_m_1+mysid_1+flow+turbid+temp+estfish_bsmt_1
# '
# modN='chla~chla_1+hcope_1+amphi_m_1+corbic_1+flow+turbid+temp
#        hcope~chla_1+hcope_1+pcope_1+mysid_1+corbic_1+flow+turbid+temp+estfish_bsmt_1
#        amphi_m~chla_1+amphi_m_1+flow+turbid+temp+estfish_bsmt_1
#        pcope~hcope_1+pcope_1+mysid_1+corbic_1+flow+turbid+temp+estfish_bsmt_1
#        mysid~hcope_1+pcope_1+mysid_1+amphi_m_1+flow+turbid+temp+estfish_bsmt_1
# '
# modS='chla~chla_1+hcope_1+clad_1+corbic_1+flow+turbid+temp
#        hcope~chla_1+hcope_1+pcope_1+corbic_1+flow+turbid+temp+estfish_bsmt_1
#        clad~chla_1+clad_1+pcope_1+flow+turbid+temp+estfish_bsmt_1
#        amphi_m~chla_1+amphi_m_1+flow+turbid+temp+estfish_bsmt_1
#        pcope~chla_1+hcope_1+clad_1+pcope_1+corbic_1+flow+turbid+temp+estfish_bsmt_1
# '
#2
modFW='chla~chla_1+hcope_1+amphi_m_1+rotif_m_1+potam_1+flow+turbid+temp
       hcope~chla_1+hcope_1+pcope_1+potam_1+flow+turbid+temp+estfish_bsmt_1
       amphi_m~chla_1+amphi_m_1+flow+turbid+temp+estfish_bsmt_1
       rotif_m~chla_1+rotif_m_1+flow+turbid+temp+estfish_bsmt_1
       pcope~hcope_1+pcope_1+potam_1+flow+turbid+temp+estfish_bsmt_1
'
modW='chla~chla_1+hcope_1+amphi_m_1+rotif_m_1+potam_1+flow+turbid+temp+mysid_1
       hcope~chla_1+hcope_1+pcope_1+mysid_1+potam_1+flow+turbid+temp+estfish_bsmt_1+rotif_m_1
       amphi_m~chla_1+amphi_m_1+mysid_1+flow+turbid+temp+estfish_bsmt_1
       rotif_m~chla_1+rotif_m_1+flow+turbid+temp+estfish_bsmt_1
       pcope~hcope_1+pcope_1+mysid_1+potam_1+flow+turbid+temp+estfish_bsmt_1+rotif_m_1
       mysid~chla_1+hcope_1+pcope_1+amphi_m_1+mysid_1+flow+turbid+temp+estfish_bsmt_1
'
modN='chla~chla_1+hcope_1+clad_1+amphi_m_1+rotif_m_1+corbic_1+flow+turbid+temp
       hcope~chla_1+hcope_1+pcope_1+mysid_1+corbic_1+flow+turbid+temp+estfish_bsmt_1
       clad~chla_1+clad_1+pcope_1+flow+turbid+temp+estfish_bsmt_1
       amphi_m~chla_1+amphi_m_1+flow+turbid+temp+estfish_bsmt_1
       rotif_m~chla_1+rotif_m_1+flow+turbid+temp+estfish_bsmt_1
       pcope~hcope_1+pcope_1+clad_1+mysid_1+corbic_1+flow+turbid+temp+estfish_bsmt_1+chla_1
       mysid~hcope_1+pcope_1+mysid_1+amphi_m_1+flow+turbid+temp+estfish_bsmt_1
'
modS='chla~chla_1+hcope_1+clad_1+rotif_m_1+corbic_1+flow+turbid+temp
       hcope~chla_1+hcope_1+pcope_1+corbic_1+flow+turbid+temp+estfish_bsmt_1
       clad~chla_1+clad_1+pcope_1+flow+turbid+temp+estfish_bsmt_1
       amphi_m~chla_1+amphi_m_1+flow+turbid+temp+estfish_bsmt_1
       rotif_m~chla_1+rotif_m_1+flow+turbid+temp+estfish_bsmt_1
       pcope~chla_1+hcope_1+clad_1+pcope_1+corbic_1+flow+turbid+temp+estfish_bsmt_1
'
modfitFW=sem(modFW, data=filter(fdr_ds,region=="Far West"))
modfitW=sem(modW, data=filter(fdr_ds,region=="West"))
modfitN=sem(modN, data=filter(fdr_ds,region=="North"))
modfitS=sem(modS, data=filter(fdr_ds,region=="South"))
summary(modfitFW, standardized=T, rsq=T)
## lavaan 0.6.17 ended normally after 26 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        50
## 
##                                                   Used       Total
##   Number of observations                           192         312
## 
## Model Test User Model:
##                                                       
##   Test statistic                                17.700
##   Degrees of freedom                                15
##   P-value (Chi-square)                           0.279
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   chla ~                                                                
##     chla_1            0.200    0.068    2.934    0.003    0.200    0.204
##     hcope_1           0.059    0.055    1.082    0.279    0.059    0.076
##     amphi_m_1         0.023    0.067    0.345    0.730    0.023    0.029
##     rotif_m_1        -0.067    0.063   -1.066    0.286   -0.067   -0.078
##     potam_1          -0.005    0.050   -0.091    0.928   -0.005   -0.006
##     flow              0.119    0.072    1.641    0.101    0.119    0.141
##     turbid           -0.079    0.069   -1.150    0.250   -0.079   -0.090
##     temp              0.135    0.062    2.195    0.028    0.135    0.158
##   hcope ~                                                               
##     chla_1            0.090    0.082    1.090    0.276    0.090    0.072
##     hcope_1           0.235    0.071    3.328    0.001    0.235    0.236
##     pcope_1           0.069    0.072    0.950    0.342    0.069    0.066
##     potam_1          -0.145    0.063   -2.283    0.022   -0.145   -0.157
##     flow             -0.072    0.083   -0.867    0.386   -0.072   -0.067
##     turbid           -0.018    0.084   -0.214    0.830   -0.018   -0.016
##     temp             -0.055    0.078   -0.713    0.476   -0.055   -0.050
##     estfish_bsmt_1   -0.133    0.076   -1.747    0.081   -0.133   -0.130
##   amphi_m ~                                                             
##     chla_1            0.054    0.040    1.378    0.168    0.054    0.044
##     amphi_m_1         0.729    0.038   19.393    0.000    0.729    0.744
##     flow             -0.262    0.042   -6.206    0.000   -0.262   -0.249
##     turbid           -0.012    0.040   -0.296    0.767   -0.012   -0.011
##     temp              0.014    0.036    0.380    0.704    0.014    0.013
##     estfish_bsmt_1    0.042    0.034    1.223    0.221    0.042    0.042
##   rotif_m ~                                                             
##     chla_1           -0.199    0.075   -2.633    0.008   -0.199   -0.172
##     rotif_m_1         0.380    0.066    5.738    0.000    0.380    0.377
##     flow              0.102    0.074    1.375    0.169    0.102    0.103
##     turbid            0.009    0.076    0.116    0.908    0.009    0.008
##     temp              0.055    0.069    0.803    0.422    0.055    0.055
##     estfish_bsmt_1    0.008    0.065    0.124    0.901    0.008    0.009
##   pcope ~                                                               
##     hcope_1           0.044    0.065    0.670    0.503    0.044    0.046
##     pcope_1           0.298    0.067    4.444    0.000    0.298    0.301
##     potam_1          -0.092    0.059   -1.578    0.114   -0.092   -0.105
##     flow              0.206    0.076    2.708    0.007    0.206    0.201
##     turbid            0.087    0.078    1.114    0.265    0.087    0.081
##     temp              0.159    0.072    2.214    0.027    0.159    0.152
##     estfish_bsmt_1   -0.007    0.070   -0.105    0.916   -0.007   -0.008
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .chla ~~                                                               
##    .hcope             0.042    0.054    0.785    0.432    0.042    0.057
##    .amphi_m           0.018    0.025    0.705    0.481    0.018    0.051
##    .rotif_m           0.069    0.048    1.425    0.154    0.069    0.103
##    .pcope            -0.013    0.050   -0.263    0.793   -0.013   -0.019
##  .hcope ~~                                                              
##    .amphi_m          -0.011    0.031   -0.363    0.716   -0.011   -0.026
##    .rotif_m           0.033    0.060    0.559    0.576    0.033    0.040
##    .pcope            -0.204    0.064   -3.215    0.001   -0.204   -0.239
##  .amphi_m ~~                                                            
##    .rotif_m          -0.031    0.028   -1.122    0.262   -0.031   -0.081
##    .pcope            -0.009    0.029   -0.298    0.766   -0.009   -0.022
##  .rotif_m ~~                                                            
##    .pcope             0.052    0.055    0.936    0.349    0.052    0.068
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .chla              0.596    0.061    9.798    0.000    0.596    0.899
##    .hcope             0.926    0.095    9.798    0.000    0.926    0.852
##    .amphi_m           0.201    0.021    9.798    0.000    0.201    0.193
##    .rotif_m           0.742    0.076    9.798    0.000    0.742    0.807
##    .pcope             0.792    0.081    9.798    0.000    0.792    0.802
## 
## R-Square:
##                    Estimate
##     chla              0.101
##     hcope             0.148
##     amphi_m           0.807
##     rotif_m           0.193
##     pcope             0.198
summary(modfitW, standardized=T, rsq=T)
## lavaan 0.6.17 ended normally after 28 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        71
## 
##                                                   Used       Total
##   Number of observations                           215         312
## 
## Model Test User Model:
##                                                       
##   Test statistic                                27.661
##   Degrees of freedom                                16
##   P-value (Chi-square)                           0.035
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   chla ~                                                                
##     chla_1            0.145    0.068    2.126    0.034    0.145    0.147
##     hcope_1           0.071    0.070    1.016    0.310    0.071    0.071
##     amphi_m_1         0.129    0.066    1.958    0.050    0.129    0.138
##     rotif_m_1         0.101    0.062    1.621    0.105    0.101    0.111
##     potam_1          -0.049    0.071   -0.684    0.494   -0.049   -0.051
##     flow              0.084    0.073    1.145    0.252    0.084    0.083
##     turbid            0.069    0.074    0.935    0.350    0.069    0.069
##     temp             -0.101    0.064   -1.588    0.112   -0.101   -0.105
##     mysid_1          -0.167    0.070   -2.392    0.017   -0.167   -0.169
##   hcope ~                                                               
##     chla_1            0.040    0.065    0.621    0.534    0.040    0.041
##     hcope_1           0.307    0.068    4.485    0.000    0.307    0.308
##     pcope_1          -0.098    0.060   -1.626    0.104   -0.098   -0.105
##     mysid_1           0.049    0.070    0.696    0.486    0.049    0.049
##     potam_1          -0.165    0.065   -2.516    0.012   -0.165   -0.171
##     flow             -0.137    0.071   -1.928    0.054   -0.137   -0.135
##     turbid           -0.119    0.071   -1.670    0.095   -0.119   -0.119
##     temp              0.063    0.062    1.011    0.312    0.063    0.065
##     estfish_bsmt_1    0.048    0.060    0.792    0.428    0.048    0.050
##     rotif_m_1         0.175    0.059    2.964    0.003    0.175    0.192
##   amphi_m ~                                                             
##     chla_1           -0.045    0.038   -1.197    0.231   -0.045   -0.043
##     amphi_m_1         0.783    0.038   20.645    0.000    0.783    0.787
##     mysid_1           0.081    0.039    2.085    0.037    0.081    0.077
##     flow              0.008    0.040    0.206    0.837    0.008    0.008
##     turbid           -0.110    0.042   -2.646    0.008   -0.110   -0.103
##     temp             -0.103    0.037   -2.800    0.005   -0.103   -0.100
##     estfish_bsmt_1   -0.177    0.037   -4.775    0.000   -0.177   -0.176
##   rotif_m ~                                                             
##     chla_1            0.021    0.067    0.311    0.755    0.021    0.019
##     rotif_m_1         0.336    0.063    5.333    0.000    0.336    0.335
##     flow              0.241    0.072    3.329    0.001    0.241    0.216
##     turbid           -0.106    0.070   -1.501    0.133   -0.106   -0.096
##     temp              0.029    0.065    0.451    0.652    0.029    0.028
##     estfish_bsmt_1   -0.188    0.062   -3.051    0.002   -0.188   -0.181
##   pcope ~                                                               
##     hcope_1          -0.130    0.060   -2.172    0.030   -0.130   -0.125
##     pcope_1           0.393    0.055    7.136    0.000    0.393    0.404
##     mysid_1           0.118    0.063    1.866    0.062    0.118    0.115
##     potam_1           0.046    0.061    0.760    0.447    0.046    0.046
##     flow              0.138    0.064    2.163    0.031    0.138    0.131
##     turbid           -0.144    0.065   -2.223    0.026   -0.144   -0.138
##     temp              0.229    0.055    4.137    0.000    0.229    0.228
##     estfish_bsmt_1    0.026    0.056    0.465    0.642    0.026    0.026
##     rotif_m_1         0.161    0.054    2.990    0.003    0.161    0.169
##   mysid ~                                                               
##     chla_1            0.179    0.058    3.099    0.002    0.179    0.180
##     hcope_1           0.070    0.060    1.166    0.243    0.070    0.069
##     pcope_1           0.107    0.053    2.012    0.044    0.107    0.114
##     amphi_m_1        -0.124    0.056   -2.224    0.026   -0.124   -0.132
##     mysid_1           0.372    0.063    5.941    0.000    0.372    0.372
##     flow             -0.171    0.060   -2.840    0.005   -0.171   -0.168
##     turbid            0.260    0.064    4.076    0.000    0.260    0.258
##     temp              0.100    0.055    1.799    0.072    0.100    0.102
##     estfish_bsmt_1   -0.025    0.055   -0.456    0.649   -0.025   -0.026
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .chla ~~                                                               
##    .hcope             0.168    0.054    3.118    0.002    0.168    0.218
##    .amphi_m          -0.007    0.031   -0.219    0.827   -0.007   -0.015
##    .rotif_m           0.150    0.057    2.644    0.008    0.150    0.183
##    .pcope             0.015    0.048    0.323    0.747    0.015    0.022
##    .mysid             0.091    0.047    1.928    0.054    0.091    0.133
##  .hcope ~~                                                              
##    .amphi_m          -0.036    0.030   -1.195    0.232   -0.036   -0.082
##    .rotif_m          -0.014    0.054   -0.258    0.796   -0.014   -0.018
##    .pcope             0.080    0.046    1.716    0.086    0.080    0.118
##    .mysid             0.204    0.048    4.299    0.000    0.204    0.307
##  .amphi_m ~~                                                            
##    .rotif_m           0.042    0.032    1.313    0.189    0.042    0.090
##    .pcope             0.068    0.028    2.444    0.015    0.068    0.169
##    .mysid            -0.038    0.027   -1.405    0.160   -0.038   -0.096
##  .rotif_m ~~                                                            
##    .pcope             0.068    0.049    1.385    0.166    0.068    0.095
##    .mysid             0.031    0.048    0.647    0.518    0.031    0.044
##  .pcope ~~                                                              
##    .mysid             0.055    0.041    1.336    0.182    0.055    0.091
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .chla              0.799    0.077   10.368    0.000    0.799    0.852
##    .hcope             0.747    0.072   10.368    0.000    0.747    0.791
##    .amphi_m           0.266    0.026   10.368    0.000    0.266    0.249
##    .rotif_m           0.838    0.081   10.368    0.000    0.838    0.736
##    .pcope             0.613    0.059   10.368    0.000    0.613    0.599
##    .mysid             0.595    0.057   10.368    0.000    0.595    0.622
## 
## R-Square:
##                    Estimate
##     chla              0.148
##     hcope             0.209
##     amphi_m           0.751
##     rotif_m           0.264
##     pcope             0.401
##     mysid             0.378
summary(modfitN, standardized=T, rsq=T)
## lavaan 0.6.17 ended normally after 33 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        83
## 
##                                                   Used       Total
##   Number of observations                           205         312
## 
## Model Test User Model:
##                                                       
##   Test statistic                                35.521
##   Degrees of freedom                                29
##   P-value (Chi-square)                           0.188
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   chla ~                                                                
##     chla_1            0.162    0.074    2.173    0.030    0.162    0.149
##     hcope_1          -0.033    0.101   -0.326    0.744   -0.033   -0.024
##     clad_1            0.207    0.085    2.437    0.015    0.207    0.186
##     amphi_m_1         0.065    0.079    0.819    0.413    0.065    0.056
##     rotif_m_1        -0.047    0.077   -0.610    0.542   -0.047   -0.044
##     corbic_1         -0.028    0.078   -0.357    0.721   -0.028   -0.024
##     flow             -0.033    0.086   -0.387    0.699   -0.033   -0.030
##     turbid            0.109    0.078    1.399    0.162    0.109    0.099
##     temp              0.134    0.076    1.763    0.078    0.134    0.125
##   hcope ~                                                               
##     chla_1           -0.009    0.039   -0.232    0.816   -0.009   -0.012
##     hcope_1           0.121    0.068    1.778    0.075    0.121    0.128
##     pcope_1          -0.096    0.043   -2.201    0.028   -0.096   -0.131
##     mysid_1           0.046    0.060    0.766    0.443    0.046    0.058
##     corbic_1          0.101    0.042    2.431    0.015    0.101    0.125
##     flow             -0.394    0.049   -8.050    0.000   -0.394   -0.498
##     turbid            0.089    0.047    1.891    0.059    0.089    0.115
##     temp              0.097    0.043    2.224    0.026    0.097    0.127
##     estfish_bsmt_1    0.007    0.044    0.161    0.872    0.007    0.010
##   clad ~                                                                
##     chla_1           -0.036    0.057   -0.631    0.528   -0.036   -0.035
##     clad_1            0.377    0.063    6.026    0.000    0.377    0.356
##     pcope_1           0.015    0.057    0.272    0.786    0.015    0.016
##     flow              0.457    0.067    6.796    0.000    0.457    0.428
##     turbid            0.004    0.062    0.061    0.951    0.004    0.004
##     temp              0.051    0.058    0.888    0.374    0.051    0.050
##     estfish_bsmt_1    0.019    0.058    0.322    0.747    0.019    0.019
##   amphi_m ~                                                             
##     chla_1            0.052    0.054    0.974    0.330    0.052    0.058
##     amphi_m_1         0.499    0.057    8.740    0.000    0.499    0.514
##     flow              0.052    0.061    0.858    0.391    0.052    0.056
##     turbid           -0.019    0.056   -0.341    0.733   -0.019   -0.021
##     temp             -0.039    0.055   -0.716    0.474   -0.039   -0.044
##     estfish_bsmt_1   -0.068    0.055   -1.231    0.218   -0.068   -0.079
##   rotif_m ~                                                             
##     chla_1           -0.083    0.064   -1.304    0.192   -0.083   -0.081
##     rotif_m_1         0.155    0.064    2.422    0.015    0.155    0.151
##     flow              0.405    0.073    5.537    0.000    0.405    0.382
##     turbid           -0.052    0.067   -0.776    0.438   -0.052   -0.050
##     temp             -0.075    0.065   -1.158    0.247   -0.075   -0.073
##     estfish_bsmt_1   -0.015    0.065   -0.230    0.818   -0.015   -0.015
##   pcope ~                                                               
##     hcope_1          -0.144    0.102   -1.418    0.156   -0.144   -0.114
##     pcope_1           0.251    0.065    3.896    0.000    0.251    0.257
##     clad_1           -0.135    0.070   -1.920    0.055   -0.135   -0.128
##     mysid_1           0.063    0.090    0.705    0.481    0.063    0.059
##     corbic_1          0.064    0.066    0.980    0.327    0.064    0.059
##     flow             -0.193    0.076   -2.554    0.011   -0.193   -0.182
##     turbid           -0.245    0.071   -3.446    0.001   -0.245   -0.235
##     temp              0.072    0.066    1.087    0.277    0.072    0.070
##     estfish_bsmt_1   -0.063    0.067   -0.952    0.341   -0.063   -0.065
##     chla_1            0.145    0.064    2.262    0.024    0.145    0.141
##   mysid ~                                                               
##     hcope_1          -0.021    0.084   -0.253    0.800   -0.021   -0.018
##     pcope_1          -0.061    0.054   -1.132    0.258   -0.061   -0.067
##     mysid_1           0.173    0.073    2.361    0.018    0.173    0.175
##     amphi_m_1        -0.082    0.052   -1.567    0.117   -0.082   -0.080
##     flow             -0.420    0.062   -6.787    0.000   -0.420   -0.428
##     turbid            0.228    0.060    3.810    0.000    0.228    0.236
##     temp              0.080    0.054    1.480    0.139    0.080    0.085
##     estfish_bsmt_1    0.056    0.056    1.007    0.314    0.056    0.062
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .chla ~~                                                               
##    .hcope             0.021    0.044    0.485    0.628    0.021    0.034
##    .clad              0.150    0.061    2.474    0.013    0.150    0.175
##    .amphi_m           0.021    0.057    0.365    0.715    0.021    0.025
##    .rotif_m           0.104    0.068    1.536    0.125    0.104    0.108
##    .pcope            -0.062    0.066   -0.940    0.347   -0.062   -0.066
##    .mysid             0.092    0.056    1.640    0.101    0.092    0.115
##  .hcope ~~                                                              
##    .clad             -0.059    0.034   -1.722    0.085   -0.059   -0.121
##    .amphi_m           0.039    0.033    1.186    0.236    0.039    0.083
##    .rotif_m          -0.007    0.038   -0.191    0.848   -0.007   -0.013
##    .pcope             0.060    0.038    1.564    0.118    0.060    0.110
##    .mysid             0.180    0.034    5.259    0.000    0.180    0.395
##  .clad ~~                                                               
##    .amphi_m           0.004    0.044    0.088    0.930    0.004    0.006
##    .rotif_m           0.107    0.053    2.013    0.044    0.107    0.142
##    .pcope            -0.051    0.052   -0.981    0.326   -0.051   -0.069
##    .mysid            -0.083    0.044   -1.895    0.058   -0.083   -0.134
##  .amphi_m ~~                                                            
##    .rotif_m          -0.128    0.051   -2.530    0.011   -0.128   -0.180
##    .pcope            -0.088    0.049   -1.778    0.075   -0.088   -0.125
##    .mysid             0.088    0.042    2.108    0.035    0.088    0.149
##  .rotif_m ~~                                                            
##    .pcope             0.151    0.059    2.562    0.010    0.151    0.182
##    .mysid             0.002    0.049    0.048    0.962    0.002    0.003
##  .pcope ~~                                                              
##    .mysid             0.134    0.049    2.750    0.006    0.134    0.196
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .chla              1.100    0.109   10.124    0.000    1.100    0.907
##    .hcope             0.360    0.036   10.124    0.000    0.360    0.595
##    .clad              0.669    0.066   10.124    0.000    0.669    0.608
##    .amphi_m           0.603    0.060   10.124    0.000    0.603    0.713
##    .rotif_m           0.842    0.083   10.124    0.000    0.842    0.773
##    .pcope             0.818    0.081   10.124    0.000    0.818    0.754
##    .mysid             0.577    0.057   10.124    0.000    0.577    0.619
## 
## R-Square:
##                    Estimate
##     chla              0.093
##     hcope             0.405
##     clad              0.392
##     amphi_m           0.287
##     rotif_m           0.227
##     pcope             0.246
##     mysid             0.381
summary(modfitS, standardized=T, rsq=T)
## lavaan 0.6.17 ended normally after 20 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        65
## 
##                                                   Used       Total
##   Number of observations                           210         312
## 
## Model Test User Model:
##                                                       
##   Test statistic                                25.378
##   Degrees of freedom                                22
##   P-value (Chi-square)                           0.279
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   chla ~                                                                
##     chla_1            0.276    0.069    3.996    0.000    0.276    0.267
##     hcope_1           0.121    0.068    1.771    0.077    0.121    0.113
##     clad_1            0.157    0.067    2.342    0.019    0.157    0.158
##     rotif_m_1        -0.106    0.068   -1.563    0.118   -0.106   -0.098
##     corbic_1          0.013    0.065    0.204    0.838    0.013    0.013
##     flow             -0.065    0.074   -0.876    0.381   -0.065   -0.059
##     turbid            0.011    0.067    0.170    0.865    0.011    0.011
##     temp              0.082    0.065    1.255    0.210    0.082    0.080
##   hcope ~                                                               
##     chla_1            0.177    0.057    3.113    0.002    0.177    0.183
##     hcope_1           0.353    0.061    5.796    0.000    0.353    0.352
##     pcope_1          -0.000    0.055   -0.006    0.995   -0.000   -0.000
##     corbic_1          0.116    0.058    2.019    0.043    0.116    0.120
##     flow             -0.144    0.062   -2.306    0.021   -0.144   -0.140
##     turbid           -0.095    0.058   -1.648    0.099   -0.095   -0.100
##     temp              0.178    0.057    3.125    0.002    0.178    0.186
##     estfish_bsmt_1   -0.185    0.058   -3.198    0.001   -0.185   -0.192
##   clad ~                                                                
##     chla_1            0.126    0.058    2.166    0.030    0.126    0.121
##     clad_1            0.524    0.058    9.073    0.000    0.524    0.526
##     pcope_1          -0.038    0.054   -0.702    0.483   -0.038   -0.038
##     flow              0.197    0.061    3.237    0.001    0.197    0.178
##     turbid           -0.049    0.057   -0.852    0.394   -0.049   -0.047
##     temp              0.112    0.056    1.979    0.048    0.112    0.109
##     estfish_bsmt_1   -0.094    0.055   -1.698    0.090   -0.094   -0.091
##   amphi_m ~                                                             
##     chla_1           -0.033    0.070   -0.469    0.639   -0.033   -0.031
##     amphi_m_1         0.218    0.068    3.202    0.001    0.218    0.214
##     flow             -0.006    0.076   -0.079    0.937   -0.006   -0.005
##     turbid            0.167    0.072    2.337    0.019    0.167    0.160
##     temp              0.089    0.070    1.265    0.206    0.089    0.085
##     estfish_bsmt_1    0.051    0.072    0.715    0.474    0.051    0.049
##   rotif_m ~                                                             
##     chla_1            0.034    0.065    0.525    0.599    0.034    0.034
##     rotif_m_1         0.119    0.066    1.793    0.073    0.119    0.114
##     flow              0.322    0.070    4.610    0.000    0.322    0.304
##     turbid           -0.071    0.064   -1.101    0.271   -0.071   -0.072
##     temp              0.001    0.065    0.022    0.982    0.001    0.001
##     estfish_bsmt_1    0.171    0.065    2.609    0.009    0.171    0.173
##   pcope ~                                                               
##     chla_1            0.211    0.065    3.265    0.001    0.211    0.202
##     hcope_1          -0.058    0.065   -0.903    0.367   -0.058   -0.054
##     clad_1            0.082    0.063    1.303    0.193    0.082    0.082
##     pcope_1           0.445    0.061    7.359    0.000    0.445    0.446
##     corbic_1         -0.055    0.061   -0.903    0.367   -0.055   -0.052
##     flow              0.029    0.069    0.415    0.678    0.029    0.026
##     turbid           -0.076    0.064   -1.192    0.233   -0.076   -0.074
##     temp              0.011    0.062    0.183    0.855    0.011    0.011
##     estfish_bsmt_1   -0.048    0.063   -0.755    0.450   -0.048   -0.046
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .chla ~~                                                               
##    .hcope             0.081    0.052    1.561    0.118    0.081    0.108
##    .clad              0.203    0.053    3.831    0.000    0.203    0.274
##    .amphi_m          -0.008    0.064   -0.123    0.902   -0.008   -0.009
##    .rotif_m           0.113    0.060    1.891    0.059    0.113    0.132
##    .pcope            -0.044    0.056   -0.772    0.440   -0.044   -0.053
##  .hcope ~~                                                              
##    .clad              0.046    0.044    1.063    0.288    0.046    0.074
##    .amphi_m           0.023    0.055    0.422    0.673    0.023    0.029
##    .rotif_m           0.014    0.050    0.281    0.778    0.014    0.019
##    .pcope             0.026    0.048    0.550    0.582    0.026    0.038
##  .clad ~~                                                               
##    .amphi_m          -0.098    0.055   -1.783    0.075   -0.098   -0.124
##    .rotif_m           0.032    0.050    0.641    0.521    0.032    0.044
##    .pcope             0.088    0.048    1.822    0.069    0.088    0.127
##  .amphi_m ~~                                                            
##    .rotif_m           0.058    0.063    0.926    0.354    0.058    0.064
##    .pcope             0.030    0.060    0.506    0.613    0.030    0.035
##  .rotif_m ~~                                                            
##    .pcope             0.200    0.057    3.512    0.000    0.200    0.250
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .chla              0.875    0.085   10.247    0.000    0.875    0.840
##    .hcope             0.636    0.062   10.247    0.000    0.636    0.696
##    .clad              0.628    0.061   10.247    0.000    0.628    0.596
##    .amphi_m           0.991    0.097   10.247    0.000    0.991    0.904
##    .rotif_m           0.839    0.082   10.247    0.000    0.839    0.866
##    .pcope             0.763    0.074   10.247    0.000    0.763    0.718
## 
## R-Square:
##                    Estimate
##     chla              0.160
##     hcope             0.304
##     clad              0.404
##     amphi_m           0.096
##     rotif_m           0.134
##     pcope             0.282
#modificationindices(modfitW, sort=T, maximum.number=20)
#residuals(modfitW)
labelsfarwest=createLabels(modfitFW, cnameslag)
labelswest=createLabels(modfitW, cnameslag)
labelsnorth=createLabels(modfitN, cnameslag)
labelssouth=createLabels(modfitS, cnameslag)
#Extract model coefficients for table
coef_table<-bind_rows(coef_table, coef_tabler(modfitFW, modfitW, modfitN, modfitS, name="Individual zooplankton groups"))%>%
  mutate(Model=case_when(
    Model == "Individual zooplankton groups" ~ "Zooplankton",
    Model == "Lower trophic level aggregates" ~ "Lower trophic",
    Model == "Upper trophic level aggregates" ~ "Upper trophic"),
    across(c(Response, Predictor),
           ~recode(.x, amphi_m="amphi", amphi_m_1="amphi_1", rotif_m="rotif", rotif_m_1="rotif_1")))
write.csv(coef_table, "fig_output/monthly coefficients.csv", row.names = FALSE)
#FAR WEST
# myLavaanPlot(model=modfitFW, labels=labelsfarwest,
#                        node_options=list(shape="box", fontname="Helvetica"), 
#                        coefs=TRUE, stand=TRUE, covs=FALSE, sig=0.05, 
#                        width=c("regress","latent"),
#                        color=c("regress","latent"))
zoop_plot_far_west <- createGraph(fit=modfitFW, 
                                  reference_df=cnameslag, 
                                  model_type="monthly_zoop",
                                  region="Far West",
                                  title="San Pablo",
                                  manual_port_settings=TRUE,
                    font_size=12)
zoop_plot_far_west
#WEST
# myLavaanPlot(model=modfitW, labels=labelswest,
#                        node_options=list(shape="box", fontname="Helvetica"), 
#                        coefs=TRUE, stand=TRUE, covs=FALSE, sig=0.05, 
#                        width=c("regress","latent"),
#                        color=c("regress","latent"))
zoop_plot_west <- createGraph(fit=modfitW, 
                              reference_df=cnameslag, 
                              model_type="monthly_zoop",
                              region="West",
                              title="Suisun",
                              manual_port_settings=TRUE,
                    font_size=12)
zoop_plot_west
#NORTH
# myLavaanPlot(model=modfitN, labels=labelsnorth,
#                        node_options=list(shape="box", fontname="Helvetica"), 
#                        coefs=TRUE, stand=TRUE, covs=FALSE, sig=0.05, 
#                        width=c("regress","latent"),
#                        color=c("regress","latent"))
zoop_plot_north <- createGraph(fit=modfitN, 
                               reference_df=cnameslag, 
                               model_type="monthly_zoop",
                               region="North",
                               title="Sacramento",
                               manual_port_settings=TRUE,
                    font_size=12)
zoop_plot_north
#SOUTH
# myLavaanPlot(model=modfitS, labels=labelssouth,
#                        node_options=list(shape="box", fontname="Helvetica"), 
#                        coefs=TRUE, stand=TRUE, covs=FALSE, sig=0.05, 
#                        width=c("regress","latent"),
#                        color=c("regress","latent"))
zoop_plot_south <- createGraph(fit=modfitS, 
                               reference_df=cnameslag, 
                               model_type="monthly_zoop",
                               region="South",
                               title="San Joaquin",
                               manual_port_settings=TRUE,
                    font_size=12)
zoop_plot_south

Save updated SEM diagrams

zoop_grobs <-  map(list(zoop_plot_far_west,
                        zoop_plot_north,
                        zoop_plot_west,
                        zoop_plot_south), ~convert_html_to_grob(.x, 2000))
zoop_figure <- ggarrange(plotlist=zoop_grobs, labels=c("(a)", "(b)", "(c)", "(d)"),
                         font.label=list(size=11)) %>%
  annotate_figure(top = text_grob("Monthly Regional Models (zooplankton groups)",
                                  color = "black",
                                  face = "bold",
                                  size = 11))
ggsave('./fig_output/sem_zoop.png',zoop_figure, width=8, height=7, dpi=300, bg = "white")

Total effects

Haven’t done yet.

Growth rates

Upper trophic

modFW='hzoop_gr~hb1*chla_1+hs1*hzoop_1+ht1*pzoop_1+ht2*potam_1+ht3*estfish_bsmt_1+ha1*flow+ha2*temp+ha3*turbid
        pzoop_gr~pb1*hzoop_1+ps1*pzoop_1+pt1*potam_1+pt2*estfish_bsmt_1+pa1*flow+pa2*temp+pa3*turbid
        estfish_bsmt_gr~fb1*hzoop_1+fb2*pzoop_1+fs1*estfish_bsmt_1+fa1*flow+fa2*temp+fa3*turbid+ft1*marfish_bsmt_1+ft2*sbass1_bsmt_1
        
        hb:=sqrt(hb1^2)
        hs:=sqrt(hs1^2)
        ht:=sqrt(ht1^2+ht2^2+ht3^2)
        ha:=sqrt(ha1^2+ha2^2+ha3^2)
        
        pb:=sqrt(pb1^2)
        ps:=sqrt(ps1^2)
        pt:=sqrt(pt1^2+pt2^2)
        pa:=sqrt(pa1^2+pa2^2+pa3^2)
        
        fb:=sqrt(fb1^2+fb2^2)
        fs:=sqrt(fs1^2)
        ft:=sqrt(ft1^2+ft2^2)
        fa:=sqrt(fa1^2+fa2^2+fa3^2)
'
modW='hzoop_gr~hb1*chla_1+hs1*hzoop_1+ht1*pzoop_1+ht2*potam_1+ht3*estfish_bsmt_1+ha1*flow+ha2*temp+ha3*turbid
        pzoop_gr~pb1*chla_1+pb2*hzoop_1+ps1*pzoop_1+pt1*potam_1+pt2*estfish_bsmt_1+pa1*flow+pa2*temp+pa3*turbid
        estfish_bsmt_gr~fb1*hzoop_1+fb2*pzoop_1+fs1*estfish_bsmt_1+fa1*flow+fa2*temp+fa3*turbid+ft1*sbass1_bsmt_1
        
        hb:=sqrt(hb1^2)
        hs:=sqrt(hs1^2)
        ht:=sqrt(ht1^2+ht2^2+ht3^2)
        ha:=sqrt(ha1^2+ha2^2+ha3^2)
        
        pb:=sqrt(pb1^2+pb2^2)
        ps:=sqrt(ps1^2)
        pt:=sqrt(pt1^2+pt2^2)
        pa:=sqrt(pa1^2+pa2^2+pa3^2)
        
        fb:=sqrt(fb1^2+fb2^2)
        fs:=sqrt(fs1^2)
        ft:=sqrt(ft1^2)
        fa:=sqrt(fa1^2+fa2^2+fa3^2)
'
modN='hzoop_gr~hb1*chla_1+hs1*hzoop_1+ht1*pzoop_1+ht2*corbic_1+ht3*estfish_bsmt_1+ha1*flow+ha2*temp+ha3*turbid
        pzoop_gr~pb1*chla_1+pb2*hzoop_1+ps1*pzoop_1+pt1*corbic_1+pt2*estfish_bsmt_1+pa1*flow+pa2*temp+pa3*turbid
        estfish_bsmt_gr~fb1*hzoop_1+fb2*pzoop_1+fs1*estfish_bsmt_1+fa1*flow+fa2*temp+fa3*turbid+ft1*sside_1+ft2*cent_1+ft3*sbass1_bsmt_1
        
        hb:=sqrt(hb1^2)
        hs:=sqrt(hs1^2)
        ht:=sqrt(ht1^2+ht2^2+ht3^2)
        ha:=sqrt(ha1^2+ha2^2+ha3^2)
        
        pb:=sqrt(pb1^2+pb2^2)
        ps:=sqrt(ps1^2)
        pt:=sqrt(pt1^2+pt2^2)
        pa:=sqrt(pa1^2+pa2^2+pa3^2)
        
        fb:=sqrt(fb1^2+fb2^2)
        fs:=sqrt(fs1^2)
        ft:=sqrt(ft1^2+ft2^2+ft3^2)
        fa:=sqrt(fa1^2+fa2^2+fa3^2)
'
modS='hzoop_gr~hb1*chla_1+hs1*hzoop_1+ht1*pzoop_1+ht2*corbic_1+ht3*estfish_bsmt_1+ha1*flow+ha2*temp+ha3*turbid
        pzoop_gr~pb1*chla_1+pb2*hzoop_1+ps1*pzoop_1+pt1*corbic_1+pt2*estfish_bsmt_1+pa1*flow+pa2*temp+pa3*turbid
        estfish_bsmt_gr~fb1*chla_1+fb2*hzoop_1+fb3*pzoop_1+fs1*estfish_bsmt_1+fa1*flow+fa2*temp+fa3*turbid+ft1*sside_1+ft2*cent_1+ft3*sbass1_bsmt_1
        
        hb:=sqrt(hb1^2)
        hs:=sqrt(hs1^2)
        ht:=sqrt(ht1^2+ht2^2+ht3^2)
        ha:=sqrt(ha1^2+ha2^2+ha3^2)
        
        pb:=sqrt(pb1^2+pb2^2)
        ps:=sqrt(ps1^2)
        pt:=sqrt(pt1^2+pt2^2)
        pa:=sqrt(pa1^2+pa2^2+pa3^2)
        
        fb:=sqrt(fb1^2+fb2^2+fb3^2)
        fs:=sqrt(fs1^2)
        ft:=sqrt(ft1^2+ft2^2+ft3^2)
        fa:=sqrt(fa1^2+fa2^2+fa3^2)
'
modfitFW=sem(modFW, data=filter(fdr_ds,region=="Far West"))
modfitW=sem(modW, data=filter(fdr_ds,region=="West"))
modfitN=sem(modN, data=filter(fdr_ds,region=="North"))
modfitS=sem(modS, data=filter(fdr_ds,region=="South"))
summary(modfitFW, standardized=T, rsq=T)
## lavaan 0.6.17 ended normally after 25 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        29
## 
##                                                   Used       Total
##   Number of observations                           191         312
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 6.836
##   Degrees of freedom                                 7
##   P-value (Chi-square)                           0.446
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                     Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   hzoop_gr ~                                                             
##     chla_1   (hb1)     0.023    0.058    0.396    0.692    0.023    0.023
##     hzoop_1  (hs1)    -0.500    0.050  -10.079    0.000   -0.500   -0.618
##     pzoop_1  (ht1)     0.064    0.048    1.351    0.177    0.064    0.081
##     potam_1  (ht2)    -0.134    0.044   -3.008    0.003   -0.134   -0.179
##     estfs__1 (ht3)    -0.127    0.053   -2.405    0.016   -0.127   -0.151
##     flow     (ha1)    -0.039    0.058   -0.670    0.503   -0.039   -0.044
##     temp     (ha2)    -0.048    0.055   -0.868    0.385   -0.048   -0.054
##     turbid   (ha3)     0.045    0.061    0.736    0.462    0.045    0.048
##   pzoop_gr ~                                                             
##     hzoop_1  (pb1)     0.072    0.103    0.701    0.484    0.072    0.045
##     pzoop_1  (ps1)    -0.898    0.100   -9.018    0.000   -0.898   -0.568
##     potam_1  (pt1)    -0.180    0.092   -1.966    0.049   -0.180   -0.121
##     estfs__1 (pt2)     0.017    0.110    0.150    0.881    0.017    0.010
##     flow     (pa1)     0.118    0.120    0.984    0.325    0.118    0.068
##     temp     (pa2)    -0.015    0.115   -0.134    0.894   -0.015   -0.009
##     turbid   (pa3)     0.329    0.128    2.571    0.010    0.329    0.176
##   estfish_bsmt_gr ~                                                      
##     hzoop_1  (fb1)    -0.409    0.133   -3.073    0.002   -0.409   -0.187
##     pzoop_1  (fb2)     0.240    0.132    1.822    0.068    0.240    0.112
##     estfs__1 (fs1)    -1.365    0.151   -9.059    0.000   -1.365   -0.599
##     flow     (fa1)     0.176    0.161    1.093    0.274    0.176    0.075
##     temp     (fa2)    -0.027    0.153   -0.178    0.858   -0.027   -0.011
##     turbid   (fa3)     0.475    0.172    2.765    0.006    0.475    0.188
##     mrfsh__1 (ft1)    -0.033    0.150   -0.218    0.828   -0.033   -0.013
##     sbss1__1 (ft2)    -0.043    0.152   -0.281    0.779   -0.043   -0.018
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .hzoop_gr ~~                                                           
##    .pzoop_gr         -0.080    0.069   -1.164    0.244   -0.080   -0.085
##    .estfsh_bsmt_gr   -0.048    0.089   -0.541    0.589   -0.048   -0.039
##  .pzoop_gr ~~                                                           
##    .estfsh_bsmt_gr   -0.401    0.189   -2.120    0.034   -0.401   -0.155
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .hzoop_gr          0.451    0.046    9.772    0.000    0.451    0.626
##    .pzoop_gr          1.973    0.202    9.772    0.000    1.973    0.685
##    .estfsh_bsmt_gr    3.377    0.346    9.772    0.000    3.377    0.643
## 
## R-Square:
##                    Estimate
##     hzoop_gr          0.374
##     pzoop_gr          0.315
##     estfsh_bsmt_gr    0.357
## 
## Defined Parameters:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##     hb                0.023    0.058    0.396    0.692    0.023    0.023
##     hs                0.500    0.050   10.079    0.000    0.500    0.618
##     ht                0.195    0.044    4.445    0.000    0.195    0.248
##     ha                0.076    0.061    1.251    0.211    0.076    0.085
##     pb                0.072    0.103    0.701    0.484    0.072    0.045
##     ps                0.898    0.100    9.018    0.000    0.898    0.568
##     pt                0.181    0.093    1.938    0.053    0.181    0.121
##     pa                0.350    0.112    3.139    0.002    0.350    0.189
##     fb                0.475    0.138    3.432    0.001    0.475    0.218
##     fs                1.365    0.151    9.059    0.000    1.365    0.599
##     ft                0.054    0.156    0.344    0.731    0.054    0.023
##     fa                0.507    0.149    3.410    0.001    0.507    0.202
summary(modfitW, standardized=T, rsq=T)
## lavaan 0.6.17 ended normally after 30 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        29
## 
##                                                   Used       Total
##   Number of observations                           210         312
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 2.096
##   Degrees of freedom                                 4
##   P-value (Chi-square)                           0.718
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                     Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   hzoop_gr ~                                                             
##     chla_1   (hb1)     0.043    0.034    1.272    0.204    0.043    0.081
##     hzoop_1  (hs1)    -0.299    0.039   -7.714    0.000   -0.299   -0.565
##     pzoop_1  (ht1)     0.024    0.035    0.690    0.490    0.024    0.045
##     potam_1  (ht2)    -0.120    0.037   -3.275    0.001   -0.120   -0.218
##     estfs__1 (ht3)    -0.011    0.034   -0.324    0.746   -0.011   -0.020
##     flow     (ha1)     0.076    0.038    2.008    0.045    0.076    0.138
##     temp     (ha2)    -0.001    0.033   -0.017    0.987   -0.001   -0.001
##     turbid   (ha3)    -0.110    0.037   -2.978    0.003   -0.110   -0.198
##   pzoop_gr ~                                                             
##     chla_1   (pb1)     0.162    0.050    3.224    0.001    0.162    0.207
##     hzoop_1  (pb2)     0.075    0.057    1.323    0.186    0.075    0.096
##     pzoop_1  (ps1)    -0.418    0.051   -8.226    0.000   -0.418   -0.527
##     potam_1  (pt1)    -0.072    0.055   -1.323    0.186   -0.072   -0.089
##     estfs__1 (pt2)     0.022    0.050    0.441    0.659    0.022    0.027
##     flow     (pa1)    -0.087    0.055   -1.568    0.117   -0.087   -0.106
##     temp     (pa2)     0.143    0.048    2.978    0.003    0.143    0.185
##     turbid   (pa3)     0.071    0.054    1.314    0.189    0.071    0.086
##   estfish_bsmt_gr ~                                                      
##     hzoop_1  (fb1)     0.134    0.105    1.275    0.202    0.134    0.082
##     pzoop_1  (fb2)    -0.120    0.102   -1.185    0.236   -0.120   -0.073
##     estfs__1 (fs1)    -1.007    0.107   -9.450    0.000   -1.007   -0.606
##     flow     (fa1)    -0.244    0.110   -2.225    0.026   -0.244   -0.144
##     temp     (fa2)     0.052    0.095    0.542    0.588    0.052    0.032
##     turbid   (fa3)     0.310    0.105    2.964    0.003    0.310    0.181
##     sbss1__1 (ft1)     0.262    0.103    2.538    0.011    0.262    0.156
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .hzoop_gr ~~                                                           
##    .pzoop_gr          0.077    0.022    3.560    0.000    0.077    0.253
##    .estfsh_bsmt_gr   -0.119    0.043   -2.797    0.005   -0.119   -0.197
##  .pzoop_gr ~~                                                           
##    .estfsh_bsmt_gr   -0.038    0.061   -0.622    0.534   -0.038   -0.043
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .hzoop_gr          0.207    0.020   10.247    0.000    0.207    0.745
##    .pzoop_gr          0.445    0.043   10.247    0.000    0.445    0.723
##    .estfsh_bsmt_gr    1.777    0.173   10.247    0.000    1.777    0.667
## 
## R-Square:
##                    Estimate
##     hzoop_gr          0.255
##     pzoop_gr          0.277
##     estfsh_bsmt_gr    0.333
## 
## Defined Parameters:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##     hb                0.043    0.034    1.272    0.204    0.043    0.081
##     hs                0.299    0.039    7.714    0.000    0.299    0.565
##     ht                0.123    0.037    3.337    0.001    0.123    0.224
##     ha                0.133    0.041    3.255    0.001    0.133    0.241
##     pb                0.179    0.045    3.994    0.000    0.179    0.228
##     ps                0.418    0.051    8.226    0.000    0.418    0.527
##     pt                0.076    0.053    1.437    0.151    0.076    0.093
##     pa                0.182    0.055    3.310    0.001    0.182    0.230
##     fb                0.180    0.119    1.510    0.131    0.180    0.110
##     fs                1.007    0.107    9.450    0.000    1.007    0.606
##     ft                0.262    0.103    2.538    0.011    0.262    0.156
##     fa                0.398    0.121    3.286    0.001    0.398    0.233
summary(modfitN, standardized=T, rsq=T)
## lavaan 0.6.17 ended normally after 27 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        31
## 
##                                                   Used       Total
##   Number of observations                           193         312
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 8.379
##   Degrees of freedom                                 8
##   P-value (Chi-square)                           0.397
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                     Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   hzoop_gr ~                                                             
##     chla_1   (hb1)     0.029    0.049    0.598    0.550    0.029    0.034
##     hzoop_1  (hs1)    -0.536    0.053  -10.202    0.000   -0.536   -0.610
##     pzoop_1  (ht1)     0.003    0.054    0.058    0.954    0.003    0.004
##     corbic_1 (ht2)     0.027    0.050    0.540    0.589    0.027    0.031
##     estfs__1 (ht3)    -0.058    0.051   -1.138    0.255   -0.058   -0.072
##     flow     (ha1)     0.135    0.056    2.393    0.017    0.135    0.156
##     temp     (ha2)     0.034    0.049    0.690    0.490    0.034    0.041
##     turbid   (ha3)     0.149    0.052    2.865    0.004    0.149    0.168
##   pzoop_gr ~                                                             
##     chla_1   (pb1)     0.338    0.092    3.683    0.000    0.338    0.210
##     hzoop_1  (pb2)     0.196    0.097    2.017    0.044    0.196    0.119
##     pzoop_1  (ps1)    -1.032    0.101  -10.240    0.000   -1.032   -0.631
##     corbic_1 (pt1)     0.087    0.094    0.930    0.353    0.087    0.053
##     estfs__1 (pt2)    -0.093    0.094   -0.991    0.322   -0.093   -0.062
##     flow     (pa1)    -0.543    0.104   -5.214    0.000   -0.543   -0.337
##     temp     (pa2)     0.059    0.091    0.651    0.515    0.059    0.038
##     turbid   (pa3)     0.105    0.096    1.095    0.274    0.105    0.064
##   estfish_bsmt_gr ~                                                      
##     hzoop_1  (fb1)     0.324    0.178    1.825    0.068    0.324    0.122
##     pzoop_1  (fb2)     0.084    0.179    0.469    0.639    0.084    0.032
##     estfs__1 (fs1)    -1.431    0.171   -8.373    0.000   -1.431   -0.587
##     flow     (fa1)    -0.646    0.188   -3.443    0.001   -0.646   -0.247
##     temp     (fa2)     0.048    0.162    0.298    0.766    0.048    0.019
##     turbid   (fa3)     0.107    0.175    0.612    0.541    0.107    0.040
##     sside_1  (ft1)    -0.024    0.162   -0.147    0.883   -0.024   -0.009
##     cent_1   (ft2)    -0.270    0.165   -1.642    0.101   -0.270   -0.106
##     sbss1__1 (ft3)     0.193    0.170    1.139    0.255    0.193    0.076
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .hzoop_gr ~~                                                           
##    .pzoop_gr          0.266    0.063    4.251    0.000    0.266    0.321
##    .estfsh_bsmt_gr   -0.200    0.107   -1.876    0.061   -0.200   -0.136
##  .pzoop_gr ~~                                                           
##    .estfsh_bsmt_gr    0.064    0.195    0.329    0.742    0.064    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .hzoop_gr          0.447    0.045    9.823    0.000    0.447    0.610
##    .pzoop_gr          1.530    0.156    9.823    0.000    1.530    0.598
##    .estfsh_bsmt_gr    4.814    0.490    9.823    0.000    4.814    0.717
## 
## R-Square:
##                    Estimate
##     hzoop_gr          0.390
##     pzoop_gr          0.402
##     estfsh_bsmt_gr    0.283
## 
## Defined Parameters:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##     hb                0.029    0.049    0.598    0.550    0.029    0.034
##     hs                0.536    0.053   10.202    0.000    0.536    0.610
##     ht                0.064    0.053    1.204    0.229    0.064    0.078
##     ha                0.203    0.051    4.018    0.000    0.203    0.233
##     pb                0.391    0.090    4.323    0.000    0.391    0.242
##     ps                1.032    0.101   10.240    0.000    1.032    0.631
##     pt                0.127    0.098    1.298    0.194    0.127    0.081
##     pa                0.557    0.104    5.327    0.000    0.557    0.345
##     fb                0.335    0.166    2.016    0.044    0.335    0.126
##     fs                1.431    0.171    8.373    0.000    1.431    0.587
##     ft                0.333    0.151    2.204    0.028    0.333    0.130
##     fa                0.657    0.189    3.469    0.001    0.657    0.251
summary(modfitS, standardized=T, rsq=T)
## lavaan 0.6.17 ended normally after 33 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        32
## 
##                                                   Used       Total
##   Number of observations                           199         312
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 3.419
##   Degrees of freedom                                 7
##   P-value (Chi-square)                           0.844
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                     Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   hzoop_gr ~                                                             
##     chla_1   (hb1)     0.139    0.046    2.990    0.003    0.139    0.185
##     hzoop_1  (hs1)    -0.402    0.044   -9.058    0.000   -0.402   -0.551
##     pzoop_1  (ht1)    -0.030    0.049   -0.613    0.540   -0.030   -0.039
##     corbic_1 (ht2)     0.030    0.045    0.679    0.497    0.030    0.041
##     estfs__1 (ht3)     0.005    0.044    0.105    0.916    0.005    0.007
##     flow     (ha1)     0.103    0.046    2.237    0.025    0.103    0.134
##     temp     (ha2)     0.049    0.043    1.151    0.250    0.049    0.069
##     turbid   (ha3)    -0.044    0.043   -1.002    0.316   -0.044   -0.061
##   pzoop_gr ~                                                             
##     chla_1   (pb1)     0.327    0.077    4.258    0.000    0.327    0.259
##     hzoop_1  (pb2)     0.133    0.073    1.806    0.071    0.133    0.108
##     pzoop_1  (ps1)    -0.775    0.081   -9.594    0.000   -0.775   -0.606
##     corbic_1 (pt1)    -0.019    0.073   -0.262    0.793   -0.019   -0.015
##     estfs__1 (pt2)     0.031    0.073    0.425    0.671    0.031    0.026
##     flow     (pa1)    -0.142    0.076   -1.869    0.062   -0.142   -0.110
##     temp     (pa2)    -0.043    0.071   -0.608    0.543   -0.043   -0.036
##     turbid   (pa3)     0.106    0.072    1.471    0.141    0.106    0.087
##   estfish_bsmt_gr ~                                                      
##     chla_1   (fb1)     0.239    0.184    1.299    0.194    0.239    0.081
##     hzoop_1  (fb2)     0.340    0.178    1.917    0.055    0.340    0.118
##     pzoop_1  (fb3)    -0.016    0.192   -0.083    0.934   -0.016   -0.005
##     estfs__1 (fs1)    -1.578    0.178   -8.887    0.000   -1.578   -0.562
##     flow     (fa1)    -0.152    0.184   -0.828    0.408   -0.152   -0.050
##     temp     (fa2)    -0.052    0.168   -0.311    0.756   -0.052   -0.019
##     turbid   (fa3)     0.466    0.186    2.514    0.012    0.466    0.164
##     sside_1  (ft1)    -0.028    0.166   -0.171    0.864   -0.028   -0.010
##     cent_1   (ft2)    -0.233    0.173   -1.344    0.179   -0.233   -0.084
##     sbss1__1 (ft3)     0.143    0.176    0.811    0.417    0.143    0.051
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .hzoop_gr ~~                                                           
##    .pzoop_gr          0.182    0.043    4.256    0.000    0.182    0.316
##    .estfsh_bsmt_gr   -0.163    0.097   -1.684    0.092   -0.163   -0.120
##  .pzoop_gr ~~                                                           
##    .estfsh_bsmt_gr    0.379    0.162    2.345    0.019    0.379    0.169
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .hzoop_gr          0.347    0.035    9.975    0.000    0.347    0.685
##    .pzoop_gr          0.951    0.095    9.975    0.000    0.951    0.659
##    .estfsh_bsmt_gr    5.321    0.533    9.975    0.000    5.321    0.671
## 
## R-Square:
##                    Estimate
##     hzoop_gr          0.315
##     pzoop_gr          0.341
##     estfsh_bsmt_gr    0.329
## 
## Defined Parameters:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##     hb                0.139    0.046    2.990    0.003    0.139    0.185
##     hs                0.402    0.044    9.058    0.000    0.402    0.551
##     ht                0.043    0.048    0.884    0.377    0.043    0.057
##     ha                0.122    0.047    2.616    0.009    0.122    0.163
##     pb                0.353    0.073    4.816    0.000    0.353    0.281
##     ps                0.775    0.081    9.594    0.000    0.775    0.606
##     pt                0.037    0.072    0.508    0.611    0.037    0.030
##     pa                0.182    0.078    2.338    0.019    0.182    0.145
##     fb                0.416    0.170    2.443    0.015    0.416    0.143
##     fs                1.578    0.178    8.887    0.000    1.578    0.562
##     ft                0.275    0.184    1.493    0.136    0.275    0.099
##     fa                0.493    0.195    2.525    0.012    0.493    0.173
#modificationindices(modfitW, sort=T, maximum.number=20)
#residuals(modfitS)
labelsfarwest=createLabels(modfitFW, cnameslag)
labelswest=createLabels(modfitW, cnameslag)
labelsnorth=createLabels(modfitN, cnameslag)
labelssouth=createLabels(modfitS, cnameslag)
#FAR WEST
upper_plot_far_west <- createGraph(fit=modfitFW, 
                                   reference_df=cnameslag, 
                                   model_type="monthly_upper_trophic",
                                   title="Far West",
                                   manual_port_settings=TRUE)
upper_plot_far_west
#WEST
upper_plot_west <- createGraph(fit=modfitW, 
                               reference_df=cnameslag, 
                               model_type="monthly_upper_trophic",
                               title="West",
                               manual_port_settings=TRUE)
upper_plot_west
#NORTH
upper_plot_north <- createGraph(fit=modfitN, 
                                reference_df=cnameslag, 
                                model_type="monthly_upper_trophic",
                                title="North",
                                manual_port_settings=TRUE)
upper_plot_north
#SOUTH
upper_plot_south <- createGraph(fit=modfitS, 
                                reference_df=cnameslag, 
                                model_type="monthly_upper_trophic",
                                title="South",
                                manual_port_settings=TRUE)
upper_plot_south

Lower trophic

modFW='din_gr~ns1*din_1+nt1*chla_gr+nn1*hzoop_1+nn2*pzoop_1+nn3*potam_1+na1*flow+na2*temp+na3*turbid
        chla_gr~cb1*din_1+cs1*chla_1+ct1*hzoop_1+ct2*potam_1+ca1*flow+ca2*temp+ca3*turbid
        potam~lb1*chla_1+lb2*hzoop_1+lb3*pzoop_1+ls1*potam_1+la1*flow+la2*temp+la3*turbid
        
        ns:=sqrt(ns1^2)
        nt:=sqrt(nt1^2)
        nn:=sqrt(nn1^2+nn2^2+nn3^2)
        na:=sqrt(na1^2+na2^2+na3^2)
        
        cb:=sqrt(cb1^2)
        cs:=sqrt(cs1^2)
        ct:=sqrt(ct1^2+ct2^2)
        ca:=sqrt(ca1^2+ca2^2+ca3^2)
        
        lb:=sqrt(lb1^2+lb2^2+lb3^2)
        ls:=sqrt(ls1^2)
        la:=sqrt(la1^2+la2^2+la3^2)
'
modW='din_gr~ns1*din_1+nt1*chla_gr+nn1*hzoop_1+nn2*pzoop_1+nn3*potam_1+na1*flow+na2*temp+na3*turbid
        chla_gr~cb1*din_1+cs1*chla_1+ct1*hzoop_1+ct2*potam_1+ca1*flow+ca2*temp+ca3*turbid
        potam~lb1*din_1+lb2*chla_1+lb3*hzoop_1+lb4*pzoop_1+ls1*potam_1+la1*flow+la2*temp+la3*turbid
        
        ns:=sqrt(ns1^2)
        nt:=sqrt(nt1^2)
        nn:=sqrt(nn1^2+nn2^2+nn3^2)
        na:=sqrt(na1^2+na2^2+na3^2)
        
        cb:=sqrt(cb1^2)
        cs:=sqrt(cs1^2)
        ct:=sqrt(ct1^2+ct2^2)
        ca:=sqrt(ca1^2+ca2^2+ca3^2)
        
        lb:=sqrt(lb1^2+lb2^2+lb3^2+lb4^2)
        ls:=sqrt(ls1^2)
        la:=sqrt(la1^2+la2^2+la3^2)
'
modN='din_gr~ns1*din_1+nt1*chla_gr+nn1*hzoop_1+nn2*pzoop_1+nn3*corbic_1+na1*flow+na2*temp+na3*turbid
        chla_gr~cb1*din_1+cs1*chla_1+ct1*hzoop_1+ct2*corbic_1+ct3*pzoop_1+ca1*flow+ca2*temp+ca3*turbid
        corbic~lb1*chla_1+lb2*hzoop_1+lb3*pzoop_1+ls1*corbic_1+la1*flow+la2*temp+la3*turbid
        
        ns:=sqrt(ns1^2)
        nt:=sqrt(nt1^2)
        nn:=sqrt(nn1^2+nn2^2+nn3^2)
        na:=sqrt(na1^2+na2^2+na3^2)
        
        cb:=sqrt(cb1^2)
        cs:=sqrt(cs1^2)
        ct:=sqrt(ct1^2+ct2^2+ct3^2)
        ca:=sqrt(ca1^2+ca2^2+ca3^2)
        
        lb:=sqrt(lb1^2+lb2^2+lb3^2)
        ls:=sqrt(ls1^2)
        la:=sqrt(la1^2+la2^2+la3^2)
'
modS='din_gr~ns1*din_1+nt1*chla_gr+nn1*hzoop_1+nn2*pzoop_1+nn3*corbic_1+na1*flow+na2*temp+na3*turbid
        chla_gr~cb1*din_1+cs1*chla_1+ct1*hzoop_1+ct2*corbic_1+ca1*flow+ca2*temp+ca3*turbid
        corbic~lb1*chla_1+lb2*hzoop_1+lb3*pzoop_1+ls1*corbic_1+la1*flow+la2*temp+la3*turbid
        
        ns:=sqrt(ns1^2)
        nt:=sqrt(nt1^2)
        nn:=sqrt(nn1^2+nn2^2+nn3^2)
        na:=sqrt(na1^2+na2^2+na3^2)
        
        cb:=sqrt(cb1^2)
        cs:=sqrt(cs1^2)
        ct:=sqrt(ct1^2+ct2^2)
        ca:=sqrt(ca1^2+ca2^2+ca3^2)
        
        lb:=sqrt(lb1^2+lb2^2+lb3^2)
        ls:=sqrt(ls1^2)
        la:=sqrt(la1^2+la2^2+la3^2)
'
modfitFW=sem(modFW, data=filter(fdr_ds,region=="Far West"))
modfitW=sem(modW, data=filter(fdr_ds,region=="West"))
modfitN=sem(modN, data=filter(fdr_ds,region=="North"))
modfitS=sem(modS, data=filter(fdr_ds,region=="South"))
summary(modfitFW, standardized=T, rsq=T)
## lavaan 0.6.17 ended normally after 30 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        26
## 
##                                                   Used       Total
##   Number of observations                           234         312
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 6.797
##   Degrees of freedom                                 4
##   P-value (Chi-square)                           0.147
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   din_gr ~                                                              
##     din_1    (ns1)   -0.145    0.017   -8.372    0.000   -0.145   -0.462
##     chla_gr  (nt1)   -0.163    0.030   -5.358    0.000   -0.163   -0.291
##     hzoop_1  (nn1)    0.001    0.015    0.070    0.944    0.001    0.004
##     pzoop_1  (nn2)   -0.021    0.015   -1.420    0.156   -0.021   -0.079
##     potam_1  (nn3)   -0.003    0.015   -0.216    0.829   -0.003   -0.012
##     flow     (na1)   -0.039    0.017   -2.224    0.026   -0.039   -0.133
##     temp     (na2)   -0.016    0.017   -0.996    0.319   -0.016   -0.058
##     turbid   (na3)    0.034    0.017    1.954    0.051    0.034    0.117
##   chla_gr ~                                                             
##     din_1    (cb1)    0.005    0.032    0.163    0.871    0.005    0.009
##     chla_1   (cs1)   -0.326    0.034   -9.482    0.000   -0.326   -0.539
##     hzoop_1  (ct1)   -0.006    0.028   -0.221    0.825   -0.006   -0.013
##     potam_1  (ct2)   -0.015    0.027   -0.575    0.565   -0.015   -0.032
##     flow     (ca1)    0.014    0.031    0.450    0.653    0.014    0.027
##     temp     (ca2)    0.045    0.030    1.510    0.131    0.045    0.089
##     turbid   (ca3)   -0.024    0.032   -0.745    0.456   -0.024   -0.046
##   potam ~                                                               
##     chla_1   (lb1)    0.054    0.060    0.886    0.376    0.054    0.042
##     hzoop_1  (lb2)   -0.073    0.051   -1.432    0.152   -0.073   -0.071
##     pzoop_1  (lb3)   -0.163    0.050   -3.263    0.001   -0.163   -0.161
##     potam_1  (ls1)    0.630    0.048   13.023    0.000    0.630    0.630
##     flow     (la1)    0.113    0.057    1.980    0.048    0.113    0.103
##     temp     (la2)   -0.044    0.054   -0.807    0.420   -0.044   -0.041
##     turbid   (la3)    0.036    0.058    0.616    0.538    0.036    0.033
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .din_gr ~~                                                             
##    .potam            -0.014    0.011   -1.214    0.225   -0.014   -0.080
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .din_gr            0.051    0.005   10.817    0.000    0.051    0.661
##    .chla_gr           0.170    0.016   10.817    0.000    0.170    0.688
##    .potam             0.568    0.053   10.817    0.000    0.568    0.518
## 
## R-Square:
##                    Estimate
##     din_gr            0.339
##     chla_gr           0.312
##     potam             0.482
## 
## Defined Parameters:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##     ns                0.145    0.017    8.372    0.000    0.145    0.462
##     nt                0.163    0.030    5.358    0.000    0.163    0.291
##     nn                0.022    0.015    1.424    0.154    0.022    0.080
##     na                0.054    0.020    2.773    0.006    0.054    0.187
##     cb                0.005    0.032    0.163    0.871    0.005    0.009
##     cs                0.326    0.034    9.482    0.000    0.326    0.539
##     ct                0.016    0.029    0.574    0.566    0.016    0.035
##     ca                0.053    0.030    1.778    0.075    0.053    0.103
##     lb                0.187    0.049    3.815    0.000    0.187    0.181
##     ls                0.630    0.048   13.023    0.000    0.630    0.630
##     la                0.126    0.049    2.574    0.010    0.126    0.116
summary(modfitW, standardized=T, rsq=T)
## lavaan 0.6.17 ended normally after 28 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        27
## 
##                                                   Used       Total
##   Number of observations                           257         312
## 
## Model Test User Model:
##                                                       
##   Test statistic                                15.957
##   Degrees of freedom                                 3
##   P-value (Chi-square)                           0.001
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   din_gr ~                                                              
##     din_1    (ns1)   -0.163    0.017   -9.891    0.000   -0.163   -0.582
##     chla_gr  (nt1)   -0.127    0.026   -4.880    0.000   -0.127   -0.244
##     hzoop_1  (nn1)   -0.016    0.016   -1.032    0.302   -0.016   -0.061
##     pzoop_1  (nn2)    0.004    0.015    0.293    0.770    0.004    0.016
##     potam_1  (nn3)    0.005    0.016    0.317    0.751    0.005    0.018
##     flow     (na1)   -0.129    0.017   -7.730    0.000   -0.129   -0.460
##     temp     (na2)    0.021    0.014    1.477    0.140    0.021    0.076
##     turbid   (na3)    0.035    0.015    2.318    0.020    0.035    0.129
##   chla_gr ~                                                             
##     din_1    (cb1)   -0.053    0.034   -1.569    0.117   -0.053   -0.098
##     chla_1   (cs1)   -0.336    0.032  -10.635    0.000   -0.336   -0.607
##     hzoop_1  (ct1)    0.033    0.031    1.087    0.277    0.033    0.065
##     potam_1  (ct2)    0.001    0.032    0.033    0.973    0.001    0.002
##     flow     (ca1)    0.012    0.033    0.348    0.728    0.012    0.021
##     temp     (ca2)   -0.040    0.028   -1.409    0.159   -0.040   -0.076
##     turbid   (ca3)   -0.010    0.031   -0.342    0.732   -0.010   -0.020
##   potam ~                                                               
##     din_1    (lb1)    0.015    0.047    0.317    0.751    0.015    0.014
##     chla_1   (lb2)   -0.025    0.044   -0.576    0.565   -0.025   -0.024
##     hzoop_1  (lb3)   -0.007    0.045   -0.151    0.880   -0.007   -0.007
##     pzoop_1  (lb4)    0.073    0.041    1.779    0.075    0.073    0.072
##     potam_1  (ls1)    0.724    0.044   16.550    0.000    0.724    0.719
##     flow     (la1)   -0.128    0.046   -2.777    0.005   -0.128   -0.124
##     temp     (la2)   -0.007    0.039   -0.181    0.856   -0.007   -0.007
##     turbid   (la3)   -0.077    0.042   -1.826    0.068   -0.077   -0.076
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .din_gr ~~                                                             
##    .potam             0.003    0.008    0.347    0.728    0.003    0.022
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .din_gr            0.047    0.004   11.336    0.000    0.047    0.633
##    .chla_gr           0.190    0.017   11.336    0.000    0.190    0.685
##    .potam             0.363    0.032   11.336    0.000    0.363    0.355
## 
## R-Square:
##                    Estimate
##     din_gr            0.367
##     chla_gr           0.315
##     potam             0.645
## 
## Defined Parameters:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##     ns                0.163    0.017    9.891    0.000    0.163    0.582
##     nt                0.127    0.026    4.880    0.000    0.127    0.244
##     nn                0.018    0.016    1.083    0.279    0.018    0.066
##     na                0.135    0.017    7.804    0.000    0.135    0.484
##     cb                0.053    0.034    1.569    0.117    0.053    0.098
##     cs                0.336    0.032   10.635    0.000    0.336    0.607
##     ct                0.033    0.031    1.080    0.280    0.033    0.065
##     ca                0.043    0.030    1.422    0.155    0.043    0.081
##     lb                0.079    0.042    1.877    0.061    0.079    0.078
##     ls                0.724    0.044   16.550    0.000    0.724    0.719
##     la                0.150    0.041    3.644    0.000    0.150    0.145
summary(modfitN, standardized=T, rsq=T)
## lavaan 0.6.17 ended normally after 23 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        27
## 
##                                                   Used       Total
##   Number of observations                           255         312
## 
## Model Test User Model:
##                                                       
##   Test statistic                                24.097
##   Degrees of freedom                                 3
##   P-value (Chi-square)                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   din_gr ~                                                              
##     din_1    (ns1)   -0.189    0.019   -9.727    0.000   -0.189   -0.583
##     chla_gr  (nt1)   -0.121    0.023   -5.193    0.000   -0.121   -0.263
##     hzoop_1  (nn1)    0.017    0.017    1.027    0.305    0.017    0.054
##     pzoop_1  (nn2)    0.006    0.018    0.343    0.731    0.006    0.019
##     corbic_1 (nn3)   -0.009    0.017   -0.523    0.601   -0.009   -0.027
##     flow     (na1)   -0.151    0.019   -7.798    0.000   -0.151   -0.459
##     temp     (na2)    0.025    0.017    1.511    0.131    0.025    0.078
##     turbid   (na3)    0.025    0.016    1.557    0.119    0.025    0.079
##   chla_gr ~                                                             
##     din_1    (cb1)   -0.089    0.045   -1.985    0.047   -0.089   -0.126
##     chla_1   (cs1)   -0.407    0.036  -11.404    0.000   -0.407   -0.607
##     hzoop_1  (ct1)   -0.034    0.037   -0.928    0.353   -0.034   -0.049
##     corbic_1 (ct2)   -0.005    0.037   -0.140    0.889   -0.005   -0.007
##     pzoop_1  (ct3)   -0.043    0.040   -1.081    0.280   -0.043   -0.061
##     flow     (ca1)   -0.057    0.042   -1.334    0.182   -0.057   -0.079
##     temp     (ca2)    0.054    0.036    1.492    0.136    0.054    0.077
##     turbid   (ca3)    0.068    0.035    1.932    0.053    0.068    0.100
##   corbic ~                                                              
##     chla_1   (lb1)    0.041    0.052    0.796    0.426    0.041    0.043
##     hzoop_1  (lb2)    0.010    0.056    0.175    0.861    0.010    0.010
##     pzoop_1  (lb3)   -0.015    0.058   -0.263    0.793   -0.015   -0.015
##     corbic_1 (ls1)    0.465    0.056    8.364    0.000    0.465    0.463
##     flow     (la1)    0.090    0.060    1.510    0.131    0.090    0.089
##     temp     (la2)   -0.033    0.055   -0.591    0.554   -0.033   -0.033
##     turbid   (la3)   -0.120    0.053   -2.270    0.023   -0.120   -0.124
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .din_gr ~~                                                             
##    .corbic           -0.001    0.013   -0.082    0.935   -0.001   -0.005
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .din_gr            0.064    0.006   11.292    0.000    0.064    0.624
##    .chla_gr           0.307    0.027   11.292    0.000    0.307    0.632
##    .corbic            0.713    0.063   11.292    0.000    0.713    0.738
## 
## R-Square:
##                    Estimate
##     din_gr            0.376
##     chla_gr           0.368
##     corbic            0.262
## 
## Defined Parameters:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##     ns                0.189    0.019    9.727    0.000    0.189    0.583
##     nt                0.121    0.023    5.193    0.000    0.121    0.263
##     nn                0.020    0.016    1.299    0.194    0.020    0.063
##     na                0.155    0.019    8.064    0.000    0.155    0.472
##     cb                0.089    0.045    1.985    0.047    0.089    0.126
##     cs                0.407    0.036   11.404    0.000    0.407    0.607
##     ct                0.056    0.035    1.604    0.109    0.056    0.078
##     ca                0.104    0.039    2.696    0.007    0.104    0.149
##     lb                0.045    0.055    0.815    0.415    0.045    0.047
##     ls                0.465    0.056    8.364    0.000    0.465    0.463
##     la                0.154    0.057    2.707    0.007    0.154    0.156
summary(modfitS, standardized=T, rsq=T)
## lavaan 0.6.17 ended normally after 17 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        26
## 
##                                                   Used       Total
##   Number of observations                           256         312
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 2.092
##   Degrees of freedom                                 4
##   P-value (Chi-square)                           0.719
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   din_gr ~                                                              
##     din_1    (ns1)   -0.156    0.023   -6.782    0.000   -0.156   -0.393
##     chla_gr  (nt1)   -0.213    0.029   -7.324    0.000   -0.213   -0.386
##     hzoop_1  (nn1)   -0.023    0.023   -1.037    0.300   -0.023   -0.055
##     pzoop_1  (nn2)    0.010    0.023    0.412    0.680    0.010    0.022
##     corbic_1 (nn3)    0.028    0.022    1.298    0.194    0.028    0.069
##     flow     (na1)   -0.013    0.022   -0.583    0.560   -0.013   -0.031
##     temp     (na2)    0.022    0.022    1.030    0.303    0.022    0.054
##     turbid   (na3)    0.058    0.024    2.429    0.015    0.058    0.143
##   chla_gr ~                                                             
##     din_1    (cb1)    0.052    0.042    1.243    0.214    0.052    0.073
##     chla_1   (cs1)   -0.390    0.040   -9.827    0.000   -0.390   -0.537
##     hzoop_1  (ct1)    0.045    0.042    1.071    0.284    0.045    0.058
##     corbic_1 (ct2)    0.053    0.039    1.348    0.178    0.053    0.073
##     flow     (ca1)   -0.063    0.040   -1.556    0.120   -0.063   -0.084
##     temp     (ca2)    0.005    0.039    0.133    0.894    0.005    0.007
##     turbid   (ca3)   -0.014    0.044   -0.314    0.754   -0.014   -0.019
##   corbic ~                                                              
##     chla_1   (lb1)    0.054    0.058    0.928    0.354    0.054    0.055
##     hzoop_1  (lb2)   -0.024    0.061   -0.384    0.701   -0.024   -0.023
##     pzoop_1  (lb3)   -0.043    0.063   -0.675    0.500   -0.043   -0.040
##     corbic_1 (ls1)    0.315    0.058    5.471    0.000    0.315    0.318
##     flow     (la1)    0.082    0.058    1.396    0.163    0.082    0.080
##     temp     (la2)   -0.078    0.058   -1.351    0.177   -0.078   -0.078
##     turbid   (la3)    0.185    0.058    3.194    0.001    0.185    0.185
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .din_gr ~~                                                             
##    .corbic           -0.001    0.019   -0.047    0.962   -0.001   -0.003
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .din_gr            0.113    0.010   11.314    0.000    0.113    0.682
##    .chla_gr           0.382    0.034   11.314    0.000    0.382    0.705
##    .corbic            0.811    0.072   11.314    0.000    0.811    0.808
## 
## R-Square:
##                    Estimate
##     din_gr            0.318
##     chla_gr           0.295
##     corbic            0.192
## 
## Defined Parameters:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##     ns                0.156    0.023    6.782    0.000    0.156    0.393
##     nt                0.213    0.029    7.324    0.000    0.213    0.386
##     nn                0.038    0.024    1.604    0.109    0.038    0.092
##     na                0.063    0.024    2.603    0.009    0.063    0.156
##     cb                0.052    0.042    1.243    0.214    0.052    0.073
##     cs                0.390    0.040    9.827    0.000    0.390    0.537
##     ct                0.069    0.039    1.787    0.074    0.069    0.094
##     ca                0.064    0.039    1.640    0.101    0.064    0.087
##     lb                0.073    0.066    1.111    0.267    0.073    0.072
##     ls                0.315    0.058    5.471    0.000    0.315    0.318
##     la                0.216    0.055    3.913    0.000    0.216    0.216
#modificationindices(modfitW, sort=T, maximum.number=20)
#residuals(modfitW)
labelsfarwest=createLabels(modfitFW, cnameslag)
labelswest=createLabels(modfitW, cnameslag)
labelsnorth=createLabels(modfitN, cnameslag)
labelssouth=createLabels(modfitS, cnameslag)
#FAR WEST
lower_plot_far_west <- createGraph(fit=modfitFW, 
                                   reference_df=cnameslag, 
                                   model_type="monthly_lower_trophic",
                                   title="Far West",
                                   manual_port_settings=TRUE)
lower_plot_far_west
#WEST
lower_plot_west <- createGraph(fit=modfitW, 
                               reference_df=cnameslag, 
                               model_type="monthly_lower_trophic",
                               title="West",
                               manual_port_settings=TRUE)
lower_plot_west
#NORTH
lower_plot_north <- createGraph(fit=modfitN, 
                                reference_df=cnameslag, 
                                model_type="monthly_lower_trophic",
                                title="North",
                                manual_port_settings=TRUE)
lower_plot_north
#SOUTH
lower_plot_south <- createGraph(fit=modfitS, 
                                reference_df=cnameslag, 
                                model_type="monthly_lower_trophic",
                                title="South",
                                manual_port_settings=TRUE)
lower_plot_south

Zooplankton

modFW='chla_gr~chla_1+hcope_1+amphi_m_1+rotif_m_1+potam_1+flow+turbid+temp
       hcope_gr~chla_1+hcope_1+pcope_1+potam_1+flow+turbid+temp+estfish_bsmt_1
       amphi_m_gr~chla_1+amphi_m_1+flow+turbid+temp+estfish_bsmt_1
       rotif_m_gr~chla_1+rotif_m_1+flow+turbid+temp+estfish_bsmt_1
       pcope_gr~hcope_1+pcope_1+potam_1+flow+turbid+temp+estfish_bsmt_1
       estfish_bsmt_gr~estfish_bsmt_1+hcope_1+pcope_1+amphi_m_1+rotif_m_1+flow+turbid+temp
'
modW='chla_gr~chla_1+hcope_1+amphi_m_1+rotif_m_1+potam_1+flow+turbid+temp+mysid_1
       hcope_gr~chla_1+hcope_1+pcope_1+mysid_1+potam_1+flow+turbid+temp+estfish_bsmt_1+rotif_m_1
       amphi_m_gr~chla_1+amphi_m_1+mysid_1+flow+turbid+temp+estfish_bsmt_1
       rotif_m_gr~chla_1+rotif_m_1+flow+turbid+temp+estfish_bsmt_1
       pcope_gr~hcope_1+pcope_1+mysid_1+potam_1+flow+turbid+temp+estfish_bsmt_1+rotif_m_1
       mysid_gr~chla_1+hcope_1+pcope_1+amphi_m_1+mysid_1+flow+turbid+temp+estfish_bsmt_1
       estfish_bsmt_gr~estfish_bsmt_1+hcope_1+pcope_1+amphi_m_1+rotif_m_1+mysid_1+flow+turbid+temp
'
modN='chla_gr~chla_1+hcope_1+amphi_m_1+rotif_m_1+corbic_1+flow+turbid+temp
       hcope_gr~chla_1+hcope_1+pcope_1+mysid_1+corbic_1+flow+turbid+temp+estfish_bsmt_1
       amphi_m_gr~chla_1+amphi_m_1+flow+turbid+temp+estfish_bsmt_1
       rotif_m_gr~chla_1+rotif_m_1+flow+turbid+temp+estfish_bsmt_1
       pcope_gr~hcope_1+pcope_1+mysid_1+corbic_1+flow+turbid+temp+estfish_bsmt_1+chla_1
       mysid_gr~hcope_1+pcope_1+mysid_1+amphi_m_1+flow+turbid+temp+estfish_bsmt_1
       estfish_bsmt_gr~estfish_bsmt_1+hcope_1+pcope_1+amphi_m_1+rotif_m_1+mysid_1+flow+turbid+temp
'
modS='chla_gr~chla_1+hcope_1+clad_1+rotif_m_1+corbic_1+flow+turbid+temp
       hcope_gr~chla_1+hcope_1+pcope_1+corbic_1+flow+turbid+temp+estfish_bsmt_1
       clad_gr~chla_1+clad_1+pcope_1+flow+turbid+temp+estfish_bsmt_1
       amphi_m_gr~chla_1+amphi_m_1+flow+turbid+temp+estfish_bsmt_1
       rotif_m_gr~chla_1+rotif_m_1+flow+turbid+temp+estfish_bsmt_1
       pcope_gr~chla_1+hcope_1+clad_1+pcope_1+corbic_1+flow+turbid+temp+estfish_bsmt_1
       estfish_bsmt_gr~estfish_bsmt_1+hcope_1+pcope_1+amphi_m_1+rotif_m_1+clad_1+flow+turbid+temp
'
modfitFW=sem(modFW, data=filter(fdr_ds,region=="Far West"))
modfitW=sem(modW, data=filter(fdr_ds,region=="West"))
modfitN=sem(modN, data=filter(fdr_ds,region=="North"))
modfitS=sem(modS, data=filter(fdr_ds,region=="South"))
summary(modfitFW, standardized=T, rsq=T)
## lavaan 0.6.17 ended normally after 43 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        64
## 
##                                                   Used       Total
##   Number of observations                           183         312
## 
## Model Test User Model:
##                                                       
##   Test statistic                                22.070
##   Degrees of freedom                                17
##   P-value (Chi-square)                           0.182
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                     Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   chla_gr ~                                                              
##     chla_1            -0.346    0.037   -9.334    0.000   -0.346   -0.573
##     hcope_1            0.042    0.030    1.423    0.155    0.042    0.088
##     amphi_m_1          0.010    0.036    0.283    0.777    0.010    0.021
##     rotif_m_1         -0.028    0.035   -0.798    0.425   -0.028   -0.052
##     potam_1           -0.006    0.027   -0.222    0.824   -0.006   -0.014
##     flow               0.032    0.040    0.797    0.425    0.032    0.061
##     turbid            -0.037    0.039   -0.953    0.341   -0.037   -0.067
##     temp               0.028    0.034    0.808    0.419    0.028    0.052
##   hcope_gr ~                                                             
##     chla_1             0.133    0.080    1.656    0.098    0.133    0.093
##     hcope_1           -0.720    0.070  -10.314    0.000   -0.720   -0.626
##     pcope_1            0.070    0.072    0.975    0.329    0.070    0.058
##     potam_1           -0.111    0.062   -1.803    0.071   -0.111   -0.106
##     flow              -0.074    0.081   -0.906    0.365   -0.074   -0.060
##     turbid            -0.050    0.086   -0.585    0.559   -0.050   -0.038
##     temp              -0.047    0.077   -0.615    0.539   -0.047   -0.038
##     estfish_bsmt_1    -0.137    0.077   -1.782    0.075   -0.137   -0.114
##   amphi_m_gr ~                                                           
##     chla_1             0.074    0.083    0.895    0.371    0.074    0.058
##     amphi_m_1         -0.534    0.080   -6.705    0.000   -0.534   -0.523
##     flow              -0.511    0.089   -5.752    0.000   -0.511   -0.468
##     turbid             0.003    0.086    0.034    0.973    0.003    0.002
##     temp               0.063    0.077    0.818    0.413    0.063    0.056
##     estfish_bsmt_1     0.096    0.074    1.296    0.195    0.096    0.090
##   rotif_m_gr ~                                                           
##     chla_1            -0.390    0.164   -2.381    0.017   -0.390   -0.146
##     rotif_m_1         -1.317    0.147   -8.970    0.000   -1.317   -0.551
##     flow               0.148    0.161    0.918    0.359    0.148    0.065
##     turbid             0.086    0.170    0.505    0.614    0.086    0.035
##     temp               0.072    0.152    0.471    0.637    0.072    0.031
##     estfish_bsmt_1    -0.007    0.144   -0.050    0.960   -0.007   -0.003
##   pcope_gr ~                                                             
##     hcope_1            0.131    0.134    0.979    0.328    0.131    0.062
##     pcope_1           -1.298    0.138   -9.379    0.000   -1.298   -0.583
##     potam_1           -0.197    0.117   -1.682    0.093   -0.197   -0.102
##     flow               0.359    0.156    2.308    0.021    0.359    0.158
##     turbid             0.206    0.164    1.254    0.210    0.206    0.084
##     temp               0.239    0.148    1.616    0.106    0.239    0.103
##     estfish_bsmt_1    -0.031    0.147   -0.209    0.835   -0.031   -0.014
##   estfish_bsmt_gr ~                                                      
##     estfish_bsmt_1    -1.319    0.150   -8.784    0.000   -1.319   -0.587
##     hcope_1           -0.234    0.136   -1.726    0.084   -0.234   -0.109
##     pcope_1            0.314    0.141    2.223    0.026    0.314    0.140
##     amphi_m_1         -0.138    0.160   -0.862    0.389   -0.138   -0.064
##     rotif_m_1         -0.320    0.150   -2.137    0.033   -0.320   -0.133
##     flow               0.155    0.172    0.898    0.369    0.155    0.067
##     turbid             0.448    0.169    2.654    0.008    0.448    0.182
##     temp              -0.078    0.151   -0.514    0.607   -0.078   -0.033
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .chla_gr ~~                                                            
##    .hcope_gr          0.023    0.029    0.779    0.436    0.023    0.058
##    .amphi_m_gr       -0.001    0.029   -0.030    0.976   -0.001   -0.002
##    .rotif_m_gr        0.140    0.058    2.391    0.017    0.140    0.180
##    .pcope_gr          0.038    0.056    0.687    0.492    0.038    0.051
##    .estfsh_bsmt_gr   -0.057    0.056   -1.003    0.316   -0.057   -0.074
##  .hcope_gr ~~                                                           
##    .amphi_m_gr       -0.032    0.065   -0.491    0.624   -0.032   -0.036
##    .rotif_m_gr        0.143    0.129    1.107    0.268    0.143    0.082
##    .pcope_gr         -0.376    0.128   -2.945    0.003   -0.376   -0.223
##    .estfsh_bsmt_gr   -0.107    0.126   -0.846    0.398   -0.107   -0.063
##  .amphi_m_gr ~~                                                         
##    .rotif_m_gr       -0.233    0.130   -1.798    0.072   -0.233   -0.134
##    .pcope_gr          0.016    0.125    0.128    0.898    0.016    0.009
##    .estfsh_bsmt_gr    0.004    0.126    0.035    0.972    0.004    0.003
##  .rotif_m_gr ~~                                                         
##    .pcope_gr         -0.184    0.248   -0.743    0.458   -0.184   -0.055
##    .estfsh_bsmt_gr   -0.117    0.250   -0.467    0.640   -0.117   -0.035
##  .pcope_gr ~~                                                           
##    .estfsh_bsmt_gr   -0.513    0.245   -2.092    0.036   -0.513   -0.157
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .chla_gr           0.175    0.018    9.566    0.000    0.175    0.671
##    .hcope_gr          0.877    0.092    9.566    0.000    0.877    0.599
##    .amphi_m_gr        0.875    0.091    9.566    0.000    0.875    0.754
##    .rotif_m_gr        3.454    0.361    9.566    0.000    3.454    0.678
##    .pcope_gr          3.242    0.339    9.566    0.000    3.242    0.642
##    .estfsh_bsmt_gr    3.312    0.346    9.566    0.000    3.312    0.644
## 
## R-Square:
##                    Estimate
##     chla_gr           0.329
##     hcope_gr          0.401
##     amphi_m_gr        0.246
##     rotif_m_gr        0.322
##     pcope_gr          0.358
##     estfsh_bsmt_gr    0.356
summary(modfitW, standardized=T, rsq=T)
## lavaan 0.6.17 ended normally after 47 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        87
## 
##                                                   Used       Total
##   Number of observations                           202         312
## 
## Model Test User Model:
##                                                       
##   Test statistic                                24.272
##   Degrees of freedom                                18
##   P-value (Chi-square)                           0.146
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                     Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   chla_gr ~                                                              
##     chla_1            -0.330    0.035   -9.561    0.000   -0.330   -0.611
##     hcope_1            0.065    0.036    1.815    0.070    0.065    0.115
##     amphi_m_1          0.047    0.033    1.424    0.154    0.047    0.088
##     rotif_m_1          0.066    0.032    2.056    0.040    0.066    0.129
##     potam_1           -0.010    0.036   -0.288    0.774   -0.010   -0.019
##     flow              -0.005    0.037   -0.140    0.888   -0.005   -0.009
##     turbid             0.011    0.038    0.296    0.767    0.011    0.020
##     temp              -0.062    0.032   -1.909    0.056   -0.062   -0.116
##     mysid_1           -0.051    0.036   -1.449    0.147   -0.051   -0.092
##   hcope_gr ~                                                             
##     chla_1             0.033    0.037    0.895    0.371    0.033    0.055
##     hcope_1           -0.352    0.040   -8.798    0.000   -0.352   -0.559
##     pcope_1           -0.052    0.035   -1.472    0.141   -0.052   -0.088
##     mysid_1            0.036    0.041    0.869    0.385    0.036    0.057
##     potam_1           -0.088    0.037   -2.359    0.018   -0.088   -0.142
##     flow              -0.085    0.041   -2.095    0.036   -0.085   -0.138
##     turbid            -0.044    0.042   -1.061    0.289   -0.044   -0.071
##     temp               0.034    0.036    0.945    0.345    0.034    0.057
##     estfish_bsmt_1     0.013    0.036    0.375    0.708    0.013    0.022
##     rotif_m_1          0.103    0.034    3.039    0.002    0.103    0.182
##   amphi_m_gr ~                                                           
##     chla_1            -0.072    0.059   -1.215    0.224   -0.072   -0.081
##     amphi_m_1         -0.304    0.061   -4.959    0.000   -0.304   -0.348
##     mysid_1            0.153    0.062    2.478    0.013    0.153    0.167
##     flow               0.003    0.063    0.055    0.956    0.003    0.004
##     turbid            -0.210    0.066   -3.187    0.001   -0.210   -0.228
##     temp              -0.162    0.058   -2.801    0.005   -0.162   -0.186
##     estfish_bsmt_1    -0.251    0.061   -4.084    0.000   -0.251   -0.281
##   rotif_m_gr ~                                                           
##     chla_1             0.008    0.101    0.077    0.938    0.008    0.005
##     rotif_m_1         -0.884    0.097   -9.143    0.000   -0.884   -0.572
##     flow               0.309    0.110    2.803    0.005    0.309    0.183
##     turbid            -0.245    0.109   -2.252    0.024   -0.245   -0.144
##     temp              -0.005    0.098   -0.056    0.956   -0.005   -0.003
##     estfish_bsmt_1    -0.215    0.097   -2.217    0.027   -0.215   -0.130
##   pcope_gr ~                                                             
##     hcope_1           -0.136    0.061   -2.225    0.026   -0.136   -0.142
##     pcope_1           -0.494    0.057   -8.656    0.000   -0.494   -0.554
##     mysid_1            0.123    0.064    1.931    0.053    0.123    0.131
##     potam_1            0.032    0.063    0.506    0.613    0.032    0.034
##     flow               0.116    0.063    1.845    0.065    0.116    0.124
##     turbid            -0.073    0.065   -1.132    0.258   -0.073   -0.077
##     temp               0.184    0.055    3.360    0.001    0.184    0.206
##     estfish_bsmt_1     0.001    0.057    0.018    0.986    0.001    0.001
##     rotif_m_1          0.141    0.055    2.558    0.011    0.141    0.164
##   mysid_gr ~                                                             
##     chla_1             0.253    0.078    3.254    0.001    0.253    0.209
##     hcope_1            0.076    0.082    0.920    0.357    0.076    0.060
##     pcope_1            0.130    0.073    1.764    0.078    0.130    0.109
##     amphi_m_1         -0.119    0.076   -1.582    0.114   -0.119   -0.100
##     mysid_1           -0.697    0.086   -8.135    0.000   -0.697   -0.556
##     flow              -0.212    0.081   -2.602    0.009   -0.212   -0.169
##     turbid             0.332    0.087    3.806    0.000    0.332    0.263
##     temp               0.118    0.075    1.563    0.118    0.118    0.099
##     estfish_bsmt_1     0.006    0.078    0.076    0.940    0.006    0.005
##   estfish_bsmt_gr ~                                                      
##     estfish_bsmt_1    -0.964    0.104   -9.304    0.000   -0.964   -0.583
##     hcope_1            0.104    0.106    0.982    0.326    0.104    0.061
##     pcope_1           -0.027    0.101   -0.269    0.788   -0.027   -0.017
##     amphi_m_1         -0.269    0.104   -2.594    0.009   -0.269   -0.166
##     rotif_m_1          0.011    0.098    0.112    0.911    0.011    0.007
##     mysid_1           -0.164    0.112   -1.464    0.143   -0.164   -0.097
##     flow              -0.224    0.108   -2.071    0.038   -0.224   -0.133
##     turbid             0.259    0.114    2.265    0.023    0.259    0.152
##     temp               0.073    0.097    0.756    0.449    0.073    0.045
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .chla_gr ~~                                                            
##    .hcope_gr          0.055    0.016    3.501    0.000    0.055    0.254
##    .amphi_m_gr        0.004    0.025    0.157    0.875    0.004    0.011
##    .rotif_m_gr        0.134    0.044    3.049    0.002    0.134    0.220
##    .pcope_gr         -0.012    0.024   -0.488    0.625   -0.012   -0.034
##    .mysid_gr          0.078    0.033    2.397    0.017    0.078    0.171
##    .estfsh_bsmt_gr   -0.016    0.042   -0.391    0.696   -0.016   -0.028
##  .hcope_gr ~~                                                           
##    .amphi_m_gr       -0.047    0.028   -1.686    0.092   -0.047   -0.119
##    .rotif_m_gr       -0.026    0.047   -0.557    0.577   -0.026   -0.039
##    .pcope_gr          0.027    0.026    1.026    0.305    0.027    0.072
##    .mysid_gr          0.185    0.038    4.905    0.000    0.185    0.368
##    .estfsh_bsmt_gr   -0.122    0.047   -2.586    0.010   -0.122   -0.185
##  .amphi_m_gr ~~                                                         
##    .rotif_m_gr        0.127    0.077    1.649    0.099    0.127    0.117
##    .pcope_gr          0.010    0.043    0.246    0.806    0.010    0.017
##    .mysid_gr         -0.112    0.058   -1.929    0.054   -0.112   -0.137
##    .estfsh_bsmt_gr    0.046    0.075    0.612    0.541    0.046    0.043
##  .rotif_m_gr ~~                                                         
##    .pcope_gr          0.077    0.073    1.054    0.292    0.077    0.074
##    .mysid_gr         -0.100    0.099   -1.012    0.312   -0.100   -0.071
##    .estfsh_bsmt_gr    0.173    0.130    1.339    0.181    0.173    0.095
##  .pcope_gr ~~                                                           
##    .mysid_gr         -0.035    0.055   -0.638    0.524   -0.035   -0.045
##    .estfsh_bsmt_gr   -0.016    0.072   -0.218    0.827   -0.016   -0.015
##  .mysid_gr ~~                                                           
##    .estfsh_bsmt_gr   -0.076    0.097   -0.778    0.436   -0.076   -0.055
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .chla_gr           0.199    0.020   10.050    0.000    0.199    0.676
##    .hcope_gr          0.239    0.024   10.050    0.000    0.239    0.662
##    .amphi_m_gr        0.634    0.063   10.050    0.000    0.634    0.802
##    .rotif_m_gr        1.862    0.185   10.050    0.000    1.862    0.689
##    .pcope_gr          0.577    0.057   10.050    0.000    0.577    0.693
##    .mysid_gr          1.057    0.105   10.050    0.000    1.057    0.713
##    .estfsh_bsmt_gr    1.804    0.180   10.050    0.000    1.804    0.666
## 
## R-Square:
##                    Estimate
##     chla_gr           0.324
##     hcope_gr          0.338
##     amphi_m_gr        0.198
##     rotif_m_gr        0.311
##     pcope_gr          0.307
##     mysid_gr          0.287
##     estfsh_bsmt_gr    0.334
summary(modfitN, standardized=T, rsq=T)
## lavaan 0.6.17 ended normally after 60 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        83
## 
##                                                   Used       Total
##   Number of observations                           186         312
## 
## Model Test User Model:
##                                                       
##   Test statistic                                27.444
##   Degrees of freedom                                22
##   P-value (Chi-square)                           0.195
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                     Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   chla_gr ~                                                              
##     chla_1            -0.379    0.042   -8.961    0.000   -0.379   -0.553
##     hcope_1            0.034    0.058    0.582    0.560    0.034    0.039
##     amphi_m_1          0.026    0.044    0.586    0.558    0.026    0.035
##     rotif_m_1          0.002    0.042    0.052    0.959    0.002    0.003
##     corbic_1          -0.017    0.044   -0.392    0.695   -0.017   -0.025
##     flow              -0.013    0.047   -0.286    0.775   -0.013   -0.020
##     turbid             0.029    0.044    0.652    0.514    0.029    0.042
##     temp               0.046    0.043    1.060    0.289    0.046    0.068
##   hcope_gr ~                                                             
##     chla_1            -0.020    0.057   -0.362    0.718   -0.020   -0.019
##     hcope_1           -0.799    0.102   -7.869    0.000   -0.799   -0.602
##     pcope_1           -0.143    0.063   -2.273    0.023   -0.143   -0.141
##     mysid_1            0.072    0.085    0.854    0.393    0.072    0.066
##     corbic_1           0.154    0.057    2.685    0.007    0.154    0.142
##     flow              -0.387    0.072   -5.353    0.000   -0.387   -0.364
##     turbid             0.123    0.069    1.777    0.076    0.123    0.117
##     temp               0.018    0.065    0.284    0.776    0.018    0.018
##     estfish_bsmt_1    -0.003    0.065   -0.048    0.961   -0.003   -0.003
##   amphi_m_gr ~                                                           
##     chla_1             0.052    0.066    0.790    0.430    0.052    0.051
##     amphi_m_1         -0.503    0.070   -7.197    0.000   -0.503   -0.453
##     flow               0.006    0.073    0.082    0.935    0.006    0.006
##     turbid            -0.059    0.068   -0.872    0.383   -0.059   -0.059
##     temp              -0.034    0.066   -0.518    0.605   -0.034   -0.035
##     estfish_bsmt_1    -0.059    0.067   -0.882    0.378   -0.059   -0.062
##   rotif_m_gr ~                                                           
##     chla_1            -0.157    0.127   -1.240    0.215   -0.157   -0.070
##     rotif_m_1         -1.440    0.128  -11.263    0.000   -1.440   -0.649
##     flow               0.663    0.144    4.616    0.000    0.663    0.294
##     turbid            -0.149    0.133   -1.123    0.261   -0.149   -0.067
##     temp              -0.124    0.129   -0.964    0.335   -0.124   -0.056
##     estfish_bsmt_1    -0.068    0.130   -0.528    0.598   -0.068   -0.033
##   pcope_gr ~                                                             
##     hcope_1           -0.052    0.169   -0.305    0.760   -0.052   -0.023
##     pcope_1           -1.041    0.106   -9.787    0.000   -1.041   -0.603
##     mysid_1            0.197    0.143    1.380    0.168    0.197    0.106
##     corbic_1           0.069    0.102    0.678    0.498    0.069    0.037
##     flow              -0.271    0.121   -2.240    0.025   -0.271   -0.149
##     turbid            -0.294    0.116   -2.527    0.012   -0.294   -0.164
##     temp               0.038    0.109    0.347    0.729    0.038    0.021
##     estfish_bsmt_1    -0.181    0.110   -1.641    0.101   -0.181   -0.107
##     chla_1             0.249    0.104    2.392    0.017    0.249    0.137
##   mysid_gr ~                                                             
##     hcope_1            0.092    0.306    0.302    0.763    0.092    0.022
##     pcope_1           -0.181    0.193   -0.939    0.348   -0.181   -0.057
##     mysid_1           -2.365    0.257   -9.188    0.000   -2.365   -0.692
##     amphi_m_1         -0.309    0.182   -1.697    0.090   -0.309   -0.085
##     flow              -1.147    0.216   -5.315    0.000   -1.147   -0.344
##     turbid             0.808    0.208    3.891    0.000    0.808    0.246
##     temp               0.146    0.191    0.764    0.445    0.146    0.045
##     estfish_bsmt_1     0.095    0.199    0.478    0.633    0.095    0.031
##   estfish_bsmt_gr ~                                                      
##     estfish_bsmt_1    -1.399    0.176   -7.968    0.000   -1.399   -0.570
##     hcope_1            0.191    0.275    0.695    0.487    0.191    0.058
##     pcope_1           -0.186    0.176   -1.057    0.291   -0.186   -0.074
##     amphi_m_1         -0.067    0.183   -0.369    0.712   -0.067   -0.023
##     rotif_m_1          0.083    0.175    0.473    0.636    0.083    0.032
##     mysid_1            0.316    0.230    1.375    0.169    0.316    0.117
##     flow              -0.485    0.194   -2.502    0.012   -0.485   -0.184
##     turbid             0.101    0.184    0.548    0.583    0.101    0.039
##     temp              -0.026    0.169   -0.154    0.878   -0.026   -0.010
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .chla_gr ~~                                                            
##    .hcope_gr          0.103    0.036    2.828    0.005    0.103    0.212
##    .amphi_m_gr        0.044    0.037    1.186    0.236    0.044    0.087
##    .rotif_m_gr        0.074    0.073    1.026    0.305    0.074    0.075
##    .pcope_gr         -0.116    0.060   -1.923    0.055   -0.116   -0.142
##    .mysid_gr          0.075    0.106    0.706    0.480    0.075    0.052
##    .estfsh_bsmt_gr   -0.095    0.094   -1.010    0.312   -0.095   -0.074
##  .hcope_gr ~~                                                           
##    .amphi_m_gr        0.046    0.056    0.811    0.417    0.046    0.060
##    .rotif_m_gr       -0.331    0.112   -2.962    0.003   -0.331   -0.222
##    .pcope_gr          0.343    0.094    3.670    0.000    0.343    0.279
##    .mysid_gr          1.061    0.178    5.952    0.000    1.061    0.485
##    .estfsh_bsmt_gr   -0.163    0.142   -1.148    0.251   -0.163   -0.084
##  .amphi_m_gr ~~                                                         
##    .rotif_m_gr       -0.178    0.115   -1.555    0.120   -0.178   -0.115
##    .pcope_gr         -0.337    0.097   -3.459    0.001   -0.337   -0.262
##    .mysid_gr          0.161    0.168    0.956    0.339    0.161    0.070
##    .estfsh_bsmt_gr   -0.213    0.149   -1.435    0.151   -0.213   -0.106
##  .rotif_m_gr ~~                                                         
##    .pcope_gr          0.133    0.183    0.730    0.465    0.133    0.054
##    .mysid_gr         -0.837    0.331   -2.529    0.011   -0.837   -0.189
##    .estfsh_bsmt_gr    0.123    0.287    0.430    0.667    0.123    0.032
##  .pcope_gr ~~                                                           
##    .mysid_gr          0.914    0.277    3.301    0.001    0.914    0.249
##    .estfsh_bsmt_gr    0.424    0.239    1.776    0.076    0.424    0.131
##  .mysid_gr ~~                                                           
##    .estfsh_bsmt_gr   -0.069    0.421   -0.165    0.869   -0.069   -0.012
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .chla_gr           0.323    0.033    9.644    0.000    0.323    0.686
##    .hcope_gr          0.734    0.076    9.644    0.000    0.734    0.652
##    .amphi_m_gr        0.802    0.083    9.644    0.000    0.802    0.773
##    .rotif_m_gr        3.014    0.313    9.644    0.000    3.014    0.594
##    .pcope_gr          2.057    0.213    9.644    0.000    2.057    0.626
##    .mysid_gr          6.521    0.676    9.644    0.000    6.521    0.589
##    .estfsh_bsmt_gr    5.066    0.525    9.644    0.000    5.066    0.730
## 
## R-Square:
##                    Estimate
##     chla_gr           0.314
##     hcope_gr          0.348
##     amphi_m_gr        0.227
##     rotif_m_gr        0.406
##     pcope_gr          0.374
##     mysid_gr          0.411
##     estfsh_bsmt_gr    0.270
summary(modfitS, standardized=T, rsq=T)
## lavaan 0.6.17 ended normally after 42 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        81
## 
##                                                   Used       Total
##   Number of observations                           192         312
## 
## Model Test User Model:
##                                                       
##   Test statistic                                23.259
##   Degrees of freedom                                24
##   P-value (Chi-square)                           0.505
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                     Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   chla_gr ~                                                              
##     chla_1            -0.437    0.048   -9.175    0.000   -0.437   -0.573
##     hcope_1            0.065    0.044    1.479    0.139    0.065    0.087
##     clad_1             0.099    0.042    2.357    0.018    0.099    0.140
##     rotif_m_1         -0.064    0.044   -1.433    0.152   -0.064   -0.083
##     corbic_1          -0.004    0.043   -0.097    0.923   -0.004   -0.006
##     flow              -0.069    0.049   -1.403    0.161   -0.069   -0.088
##     turbid            -0.003    0.045   -0.071    0.943   -0.003   -0.004
##     temp               0.020    0.044    0.452    0.651    0.020    0.027
##   hcope_gr ~                                                             
##     chla_1             0.146    0.058    2.504    0.012    0.146    0.156
##     hcope_1           -0.460    0.057   -8.041    0.000   -0.460   -0.495
##     pcope_1           -0.001    0.054   -0.009    0.993   -0.001   -0.001
##     corbic_1           0.100    0.055    1.809    0.070    0.100    0.108
##     flow              -0.119    0.062   -1.922    0.055   -0.119   -0.125
##     turbid            -0.088    0.058   -1.531    0.126   -0.088   -0.098
##     temp               0.060    0.057    1.056    0.291    0.060    0.067
##     estfish_bsmt_1    -0.138    0.056   -2.474    0.013   -0.138   -0.155
##   clad_gr ~                                                              
##     chla_1             0.202    0.083    2.438    0.015    0.202    0.163
##     clad_1            -0.552    0.077   -7.164    0.000   -0.552   -0.480
##     pcope_1            0.006    0.077    0.081    0.936    0.006    0.005
##     flow               0.220    0.084    2.627    0.009    0.220    0.174
##     turbid            -0.100    0.079   -1.263    0.206   -0.100   -0.084
##     temp               0.019    0.078    0.246    0.806    0.019    0.016
##     estfish_bsmt_1    -0.110    0.076   -1.452    0.146   -0.110   -0.093
##   amphi_m_gr ~                                                           
##     chla_1            -0.041    0.094   -0.432    0.666   -0.041   -0.025
##     amphi_m_1         -0.885    0.089   -9.919    0.000   -0.885   -0.594
##     flow              -0.074    0.100   -0.743    0.457   -0.074   -0.045
##     turbid             0.198    0.096    2.063    0.039    0.198    0.126
##     temp               0.081    0.093    0.867    0.386    0.081    0.052
##     estfish_bsmt_1     0.066    0.094    0.700    0.484    0.066    0.042
##   rotif_m_gr ~                                                           
##     chla_1             0.005    0.101    0.053    0.957    0.005    0.003
##     rotif_m_1         -1.059    0.096  -10.992    0.000   -1.059   -0.604
##     flow               0.365    0.105    3.477    0.001    0.365    0.204
##     turbid            -0.088    0.098   -0.902    0.367   -0.088   -0.052
##     temp              -0.035    0.098   -0.360    0.719   -0.035   -0.021
##     estfish_bsmt_1     0.164    0.096    1.702    0.089    0.164    0.098
##   pcope_gr ~                                                             
##     chla_1             0.342    0.100    3.411    0.001    0.342    0.212
##     hcope_1           -0.116    0.099   -1.175    0.240   -0.116   -0.072
##     clad_1             0.125    0.095    1.325    0.185    0.125    0.084
##     pcope_1           -0.759    0.096   -7.893    0.000   -0.759   -0.490
##     corbic_1           0.044    0.094    0.469    0.639    0.044    0.028
##     flow              -0.003    0.106   -0.029    0.977   -0.003   -0.002
##     turbid            -0.090    0.099   -0.913    0.361   -0.090   -0.058
##     temp              -0.002    0.096   -0.019    0.985   -0.002   -0.001
##     estfish_bsmt_1    -0.056    0.097   -0.571    0.568   -0.056   -0.036
##   estfish_bsmt_gr ~                                                      
##     estfish_bsmt_1    -1.450    0.174   -8.314    0.000   -1.450   -0.522
##     hcope_1            0.008    0.175    0.047    0.962    0.008    0.003
##     pcope_1           -0.194    0.176   -1.105    0.269   -0.194   -0.069
##     amphi_m_1          0.232    0.158    1.465    0.143    0.232    0.087
##     rotif_m_1         -0.017    0.173   -0.098    0.922   -0.017   -0.006
##     clad_1             0.252    0.167    1.510    0.131    0.252    0.093
##     flow              -0.154    0.191   -0.806    0.421   -0.154   -0.052
##     turbid             0.516    0.178    2.901    0.004    0.516    0.185
##     temp              -0.033    0.172   -0.191    0.848   -0.033   -0.012
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .chla_gr ~~                                                            
##    .hcope_gr          0.115    0.035    3.337    0.001    0.115    0.248
##    .clad_gr           0.183    0.048    3.815    0.000    0.183    0.286
##    .amphi_m_gr        0.001    0.055    0.024    0.981    0.001    0.002
##    .rotif_m_gr        0.186    0.060    3.131    0.002    0.186    0.232
##    .pcope_gr         -0.012    0.057   -0.208    0.835   -0.012   -0.015
##    .estfsh_bsmt_gr   -0.025    0.102   -0.245    0.807   -0.025   -0.018
##  .hcope_gr ~~                                                           
##    .clad_gr           0.185    0.060    3.063    0.002    0.185    0.227
##    .amphi_m_gr        0.104    0.071    1.465    0.143    0.104    0.106
##    .rotif_m_gr       -0.189    0.075   -2.506    0.012   -0.189   -0.184
##    .pcope_gr          0.098    0.073    1.347    0.178    0.098    0.098
##    .estfsh_bsmt_gr   -0.301    0.132   -2.289    0.022   -0.301   -0.167
##  .clad_gr ~~                                                            
##    .amphi_m_gr        0.067    0.097    0.692    0.489    0.067    0.050
##    .rotif_m_gr        0.171    0.102    1.674    0.094    0.171    0.122
##    .pcope_gr          0.080    0.099    0.800    0.423    0.080    0.058
##    .estfsh_bsmt_gr   -0.296    0.179   -1.653    0.098   -0.296   -0.120
##  .amphi_m_gr ~~                                                         
##    .rotif_m_gr       -0.089    0.123   -0.725    0.468   -0.089   -0.052
##    .pcope_gr         -0.154    0.120   -1.283    0.199   -0.154   -0.093
##    .estfsh_bsmt_gr   -0.666    0.220   -3.031    0.002   -0.666   -0.224
##  .rotif_m_gr ~~                                                         
##    .pcope_gr          0.418    0.129    3.246    0.001    0.418    0.241
##    .estfsh_bsmt_gr    0.438    0.227    1.933    0.053    0.438    0.141
##  .pcope_gr ~~                                                           
##    .estfsh_bsmt_gr    0.742    0.225    3.290    0.001    0.742    0.244
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .chla_gr           0.364    0.037    9.798    0.000    0.364    0.677
##    .hcope_gr          0.594    0.061    9.798    0.000    0.594    0.736
##    .clad_gr           1.117    0.114    9.798    0.000    1.117    0.785
##    .amphi_m_gr        1.621    0.165    9.798    0.000    1.621    0.658
##    .rotif_m_gr        1.776    0.181    9.798    0.000    1.776    0.625
##    .pcope_gr          1.693    0.173    9.798    0.000    1.693    0.703
##    .estfsh_bsmt_gr    5.440    0.555    9.798    0.000    5.440    0.690
## 
## R-Square:
##                    Estimate
##     chla_gr           0.323
##     hcope_gr          0.264
##     clad_gr           0.215
##     amphi_m_gr        0.342
##     rotif_m_gr        0.375
##     pcope_gr          0.297
##     estfsh_bsmt_gr    0.310
#modificationindices(modfitW, sort=T, maximum.number=20)
#residuals(modfitW)
labelsfarwest=createLabels(modfitFW, cnameslag)
labelswest=createLabels(modfitW, cnameslag)
labelsnorth=createLabels(modfitN, cnameslag)
labelssouth=createLabels(modfitS, cnameslag)
#FAR WEST
zoop_plot_far_west <- createGraph(fit=modfitFW, 
                                  reference_df=cnameslag, 
                                  model_type="monthly_zoop",
                                  region="Far West",
                                  title="Far West",
                                  manual_port_settings=TRUE)
zoop_plot_far_west
#WEST
zoop_plot_west <- createGraph(fit=modfitW, 
                              reference_df=cnameslag, 
                              model_type="monthly_zoop",
                              region="West",
                              title="West",
                              manual_port_settings=TRUE)
zoop_plot_west
#NORTH
zoop_plot_north <- createGraph(fit=modfitN, 
                               reference_df=cnameslag, 
                               model_type="monthly_zoop",
                               region="North",
                               title="North",
                               manual_port_settings=TRUE)
zoop_plot_north
#SOUTH
zoop_plot_south <- createGraph(fit=modfitS, 
                               reference_df=cnameslag, 
                               model_type="monthly_zoop",
                               region="South",
                               title="South",
                               manual_port_settings=TRUE)
zoop_plot_south