├── .DS_Store ├── .gitignore ├── case_study2_model_out ├── Langlois_gamm.plot.png ├── clams_10_CPN_mod_fits.png ├── clams_11_CPN_mod_fits.png ├── clams_12_CPN_mod_fits.png ├── clams_13_CPN_mod_fits.png ├── clams_14_CPN_mod_fits.png ├── clams_15_CPN_mod_fits.png ├── clams_16_CPN_mod_fits.png ├── clams_17_CPN_mod_fits.png ├── clams_18_CPN_mod_fits.png ├── clams_19_CPN_mod_fits.png ├── clams_1_BDS_mod_fits.png ├── clams_1_BMS_mod_fits.png ├── clams_1_CPN_mod_fits.png ├── clams_20_CPN_mod_fits.png ├── clams_21_CPN_mod_fits.png ├── clams_22_CPN_mod_fits.png ├── clams_23_CPN_mod_fits.png ├── clams_24_CPN_mod_fits.png ├── clams_25_CPN_mod_fits.png ├── clams_26_CPN_mod_fits.png ├── clams_2_BDS_mod_fits.png ├── clams_2_BMS_mod_fits.png ├── clams_2_CPN_mod_fits.png ├── clams_3_BDS_mod_fits.png ├── clams_3_CPN_mod_fits.png ├── clams_4_BDS_mod_fits.png ├── clams_4_CPN_mod_fits.png ├── clams_5_BDS_mod_fits.png ├── clams_5_CPN_mod_fits.png ├── clams_6_BDS_mod_fits.png ├── clams_6_CPN_mod_fits.png ├── clams_7_BDS_mod_fits.png ├── clams_7_CPN_mod_fits.png ├── clams_8_BDS_mod_fits.png ├── clams_8_CPN_mod_fits.png ├── clams_9_BDS_mod_fits.png ├── clams_9_CPN_mod_fits.png ├── clams_var_importance_heatmap.pdf ├── clams_all.var.imp.csv ├── predicts.csv └── clams_all.mod.fits.csv ├── FSSgam.Rproj ├── scratch.R ├── README.md ├── x_function_check_correlations_v1.00.R ├── FAQ.Rmd ├── extra_examples.R ├── case_study3_reproductive_cycles.R ├── case_study1_reef_fish.R ├── case_study1_dataset.csv ├── case_study2_soft_sediment.R ├── x_function_full_subsets_gam_v1.11.R └── case_study2_dataset.csv /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | FSSgam.Rproj 6 | -------------------------------------------------------------------------------- /case_study2_model_out/Langlois_gamm.plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/Langlois_gamm.plot.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_10_CPN_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_10_CPN_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_11_CPN_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_11_CPN_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_12_CPN_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_12_CPN_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_13_CPN_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_13_CPN_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_14_CPN_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_14_CPN_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_15_CPN_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_15_CPN_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_16_CPN_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_16_CPN_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_17_CPN_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_17_CPN_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_18_CPN_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_18_CPN_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_19_CPN_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_19_CPN_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_1_BDS_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_1_BDS_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_1_BMS_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_1_BMS_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_1_CPN_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_1_CPN_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_20_CPN_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_20_CPN_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_21_CPN_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_21_CPN_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_22_CPN_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_22_CPN_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_23_CPN_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_23_CPN_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_24_CPN_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_24_CPN_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_25_CPN_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_25_CPN_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_26_CPN_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_26_CPN_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_2_BDS_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_2_BDS_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_2_BMS_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_2_BMS_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_2_CPN_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_2_CPN_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_3_BDS_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_3_BDS_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_3_CPN_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_3_CPN_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_4_BDS_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_4_BDS_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_4_CPN_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_4_CPN_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_5_BDS_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_5_BDS_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_5_CPN_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_5_CPN_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_6_BDS_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_6_BDS_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_6_CPN_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_6_CPN_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_7_BDS_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_7_BDS_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_7_CPN_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_7_CPN_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_8_BDS_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_8_BDS_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_8_CPN_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_8_CPN_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_9_BDS_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_9_BDS_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_9_CPN_mod_fits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_9_CPN_mod_fits.png -------------------------------------------------------------------------------- /case_study2_model_out/clams_var_importance_heatmap.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beckyfisher/FSSgam/HEAD/case_study2_model_out/clams_var_importance_heatmap.pdf -------------------------------------------------------------------------------- /FSSgam.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | -------------------------------------------------------------------------------- /case_study2_model_out/clams_all.var.imp.csv: -------------------------------------------------------------------------------- 1 | "","sqrt.X4mm","sqrt.X2mm","sqrt.X1mm","sqrt.X500um","fetch","org","snapper","lobster","Status","Distance" 2 | "BDS",0.02,0.001,0.09,0.521,0.339,0.004,0,0,1.001,1 3 | "BMS",0,0.025,0.009,0,0,0.706,0,0.294,0.706,0.706 4 | "CPN",0.538,0.045,0.134,0.252,0.229,0.109,0.211,0.203,0.24,0.079 5 | -------------------------------------------------------------------------------- /scratch.R: -------------------------------------------------------------------------------- 1 | # set arg vals 2 | use.dat 3 | test.fit 4 | pred.vars.cont=NA 5 | pred.vars.fact=NA 6 | cyclic.vars=NA 7 | linear.vars=NA 8 | max.predictors=3 9 | k=5 10 | factor.smooth.interactions=pred.vars.fact 11 | factor.factor.interactions=F 12 | smooth.smooth.interactions=F 13 | cov.cutoff=0.28 14 | bs.arg="'cr'" 15 | null.terms="" 16 | max.models=500 17 | parallel=F 18 | n.cores=4 19 | r2.type="r2.lm.est" 20 | report.unique.r2=F 21 | cor.matrix=NA 22 | factor.interactions="previous.arg" 23 | smooth.interactions="previous.arg" 24 | size="previous.arg" 25 | check.non.linear.correlations=F -------------------------------------------------------------------------------- /case_study2_model_out/predicts.csv: -------------------------------------------------------------------------------- 1 | "","lobster","response","se.fit" 2 | "1",0,4.56010799634739,3.03824958262531 3 | "2",0.342105263157895,4.3348348375891,2.85751970124952 4 | "3",0.684210526315789,4.12068279411692,2.69353364038042 5 | "4",1.02631578947368,3.9170960274824,2.5449091707147 6 | "5",1.36842105263158,3.72354716910911,2.41030339383045 7 | "6",1.71052631578947,3.53953581241756,2.28842620515283 8 | "7",2.05263157894737,3.36458708793407,2.17805201145119 9 | "8",2.39473684210526,3.19825031663126,2.07802675567615 10 | "9",2.73684210526316,3.04009773703121,1.98726988203269 11 | "10",3.07894736842105,2.88972330287714,1.9047732053941 12 | "11",3.42105263157895,2.74674356141527,1.8296017198844 13 | "12",3.76315789473684,2.61080012140116,1.76089685117753 14 | "13",4.10526315789474,2.48155264158531,1.69787017290439 15 | "14",4.44736842105263,2.35867674276576,1.63980378794186 16 | "15",4.78947368421053,2.24186329507881,1.58605167128133 17 | "16",5.13157894736842,2.13081773471558,1.53603920048135 18 | "17",5.47368421052632,2.02525940900355,1.48926060653281 19 | "18",5.81578947368421,1.92492094882062,1.44527474051724 20 | "19",6.15789473684211,1.82954766733786,1.40369977824219 21 | "20",6.5,1.73889698411462,1.36420744105473 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### FSSgam 2 | Requires: doSNOW, MuMIn, gamm4, mgcv, nnet 3 | Last tested using R version 4.0.5 4 | 5 | ### Summary ################################################################ 6 | 7 | Full subsets information theoretic approaches are becoming an increasingly popular tool for exploring predictive power and variable importance where a wide range of candidate predictors are being considered. 8 | 9 | This repository contains a set o functions in the statistical programming language R that can be used to construct, fit and compare a complete model set of possible ecological or environmental predictors, given a response variable of interest. The function is based on Generalized Additive Models (GAM) and builds on the MuMIn package. 10 | 11 | Advantages include the capacity to fit more predictors than there are replicates, automatic removal of models with correlated predictors, and model sets that include interactions between factors and smooth predictors, as well as smooth interactions with other smooths (via t2). 12 | 13 | The function(s) take a range of arguments that allow control over the model set being constructed, including specifying cyclic and linear continuous predictors, specification of the smoothing algorithm used and the maximum complexity allowed for smooth terms. 14 | 15 | The use of the package is demonstrated via case studies that highlight how appropriate model sets can be easily constructed, and the broader utility of the approach for exploratory ecology. 16 | 17 | ### Installation 18 | install.packages("devtools") 19 | devtools::install_github("beckyfisher/FSSgam_package") 20 | 21 | ### Argument and outputs 22 | See Table S1 and Table S2 for argument details and an explanation of outputs returned by the function. 23 | 24 | ### known issues 25 | This package assumes you know what you are doing. Non-gaussian mixed model 26 | gamm resorts to PQL meaning that AICc calls will not return the AIC of the 27 | actual model. Please thoroughly read the help files contained within the gamm4 28 | and mgcv packages, including information under details. 29 | 30 | GAMM is highly sensitive to the spread of your predictors, so please check those carefully ensuring a robust range of values and that there are no gaps. 31 | 32 | 33 | ### License 34 | 35 | The code is released under the Apache License 2.0 36 | 37 | Copyright 2020 Australian Institute of Marine Science 38 | 39 | Licensed under the Apache License, Version 2.0 (the "License"); 40 | you may not use this file except in compliance with the License. 41 | You may obtain a copy of the License at 42 | 43 | http://www.apache.org/licenses/LICENSE-2.0 44 | 45 | Unless required by applicable law or agreed to in writing, software 46 | distributed under the License is distributed on an "AS IS" BASIS, 47 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 48 | See the License for the specific language governing permissions and 49 | limitations under the License. -------------------------------------------------------------------------------- /x_function_check_correlations_v1.00.R: -------------------------------------------------------------------------------- 1 | check.correlations=function(dat,parallel=F,n.cores=4){ 2 | classes.dat=sapply(dat,class) 3 | fact.vars=names(which(classes.dat=="factor" | classes.dat=="character")) 4 | cont.vars=names(which(classes.dat=="integer" | classes.dat=="numeric")) 5 | if(length(cont.vars)>1){ 6 | cor.mat=cor(dat[,cont.vars],use="pairwise.complete.obs")}else{ 7 | cor.mat=matrix(1,ncol=1,nrow=1) 8 | colnames(cor.mat)=cont.vars 9 | rownames(cor.mat)=cont.vars} 10 | if(length(fact.vars)>0){ 11 | if(length(cont.vars)>0){ 12 | lm.grid=expand.grid(list(fact.var=fact.vars,cont.var=cont.vars)) 13 | r.estimates=cbind(lm.grid,apply(lm.grid,MARGIN=1,FUN=function(x){ 14 | sqrt(summary(lm(dat[,x[2]]~factor(dat[,x[1]])))$r.sq)})) 15 | 16 | fact.cont.upper.right=matrix(NA,ncol=length(fact.vars),nrow=length(cont.vars)) 17 | colnames(fact.cont.upper.right)=fact.vars;rownames(fact.cont.upper.right)=cont.vars 18 | 19 | fact.cont.lower.left=matrix(NA,ncol=length(cont.vars),nrow=length(fact.vars)) 20 | colnames(fact.cont.lower.left)=cont.vars;rownames(fact.cont.lower.left)=fact.vars 21 | 22 | fact.fact.lower.right=matrix(NA,ncol=length(fact.vars),nrow=length(fact.vars)) 23 | colnames(fact.fact.lower.right)=fact.vars;rownames(fact.fact.lower.right)=fact.vars 24 | 25 | out.cor.mat=rbind(cbind(cor.mat,fact.cont.upper.right), 26 | cbind(fact.cont.lower.left,fact.fact.lower.right)) 27 | 28 | # assign the estimated r values to the upper right and lower left corners 29 | for(r in 1:nrow(r.estimates)){ 30 | # upper right 31 | col.index=which(colnames(out.cor.mat)==r.estimates$fact.var[r]) 32 | row.index=which(rownames(out.cor.mat)==r.estimates$cont.var[r]) 33 | out.cor.mat[row.index,col.index]=r.estimates[r,3] 34 | # lower left 35 | col.index=which(colnames(out.cor.mat)==r.estimates$cont.var[r]) 36 | row.index=which(rownames(out.cor.mat)==r.estimates$fact.var[r]) 37 | out.cor.mat[row.index,col.index]=r.estimates[r,3] 38 | } 39 | }else{ 40 | fact.fact.lower.right=matrix(NA,ncol=length(fact.vars),nrow=length(fact.vars)) 41 | colnames(fact.fact.lower.right)=fact.vars;rownames(fact.fact.lower.right)=fact.vars 42 | out.cor.mat=fact.fact.lower.right} 43 | 44 | # estimate r values for fact-fact combinations 45 | lm.grid=expand.grid(list(fact.var1=fact.vars,fact.var2=fact.vars)) 46 | require(nnet) 47 | if(parallel==T){ 48 | require(doSNOW) 49 | cl=makePSOCKcluster(n.cores) 50 | registerDoSNOW(cl) 51 | out.cor.dat<-foreach(r = 1:nrow(lm.grid),.packages=c('nnet'),.errorhandling='pass')%dopar%{ 52 | var.1=as.character(lm.grid[r,1]) 53 | var.2=as.character(lm.grid[r,2]) 54 | dat.r=na.omit(dat[,c(var.1,var.2)]) 55 | fit <- try(summary(multinom(dat.r[,var.1] ~ dat.r[,var.2],trace=F))$deviance,silent=T) 56 | null.fit=try(summary(multinom(dat[,var.1] ~ 1,trace=F))$deviance,silent=T) 57 | if(class(fit)!="try-error"){ 58 | if(round(fit,4)==round(null.fit,4)){r.est=0}else{ 59 | r.est=sqrt(1-(fit/null.fit))} 60 | c(var.1,var.2,r.est)}} 61 | stopCluster(cl) 62 | registerDoSEQ() 63 | }else{ 64 | out.cor.dat=list() 65 | for(r in 1:nrow(lm.grid)){ 66 | var.1=as.character(lm.grid[r,1]) 67 | var.2=as.character(lm.grid[r,2]) 68 | dat.r=na.omit(dat[,c(var.1,var.2)]) 69 | fit <- try(summary(multinom(dat.r[,var.1] ~ dat.r[,var.2],trace=F))$deviance,silent=T) 70 | null.fit=try(summary(multinom(dat[,var.1] ~ 1,trace=F))$deviance,silent=T) 71 | out=NA 72 | if(class(fit)!="try-error"){ 73 | if(round(fit,4)==round(null.fit,4)){r.est=0}else{ 74 | r.est=sqrt(1-(fit/null.fit))} 75 | out=c(var.1,var.2,r.est)} 76 | out.cor.dat=c(out.cor.dat,list(out))} 77 | } 78 | 79 | for(r in 1:length(out.cor.dat)){ 80 | out.cor.mat[which(colnames(out.cor.mat)==out.cor.dat[[r]][1]), 81 | which(rownames(out.cor.mat)==out.cor.dat[[r]][2])]= 82 | as.numeric(out.cor.dat[[r]][3])}}else{out.cor.mat=cor.mat} 83 | return(out.cor.mat) 84 | } -------------------------------------------------------------------------------- /FAQ.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "FSSgam FAQs" 3 | author: "Rebecca Fisher" 4 | date: "04/05/2020" 5 | output: html_document 6 | --- 7 | 8 | ```{r setup, include=FALSE} 9 | knitr::opts_chunk$set(echo = TRUE) 10 | ``` 11 | 12 | ## How do you choose which variables to include in **test.fit** (e.g. Model1) 13 | 14 | The **generate.model.set** function must be supplied **test.fit**, which is a gam(m) model fitted to the desired response data, with the appropriate random effects structure (unless supplied as an **re** agument to **gam**, see below) and **family**. This **test.fit** is simply updated with new model formula by the **fit.model.set** function, so anything supplied in the formula of the **test.fit** is not actually used in the full subsets fitting procedure - rather just the underlying structure of the model set. This means it doesn't actually matter what variables are included in **test.fit** as predictors, they must just be present in the data.frame supplied as **use.dat**. Fitting a sensible **test.fit** can be helpful to examine the assumptions of your model fits before you even get started, as this can save a lot of time in the long run compared to waiting for your "top model" or model set to examine the validity of the underlying model assumptions. I highly recommending fitting a reasonable **test.fit** and exploring this thoroughly to be confident the model has fit as you intend. 15 | 16 | There are two examples of generating **test.fit** in the supporting material. The first is on line 102 ). This example shows a **test.fit** calling the gam function in mgcv directly, which is necessary to use the **tw()** distribution in this example. The main things that need to be specified are the response variable (here called simply **response** - but this would be whatever variable you want to build the model set to predict), family - in this case **tw()**, and the data to use. Here we have fit one of the predictors that we think will be important (although that was not strictly necessary), as well as the two predictors that we are going to use in our null model (again, also not necessary, but **test.fit** is a good place to make sure your gam models are fitting as intended). Note our null model in this example consists of a random effect of **site** specified through **s(site, bs="re")**. Note that specifying the null terms in **test.fit** does not automatically mean the null terms are carried into the full subsets gam. They must also be specified as **null.terms** (see line 111 of the case_study1_reef_fish.R example). 17 | 18 | At line 48 of you can see an alternative specification of **test.fit** using the **uGamm** function from the **MuMIn**. **uGamm** is wrapper function that allows **gamm4** model fits to be updateable and therefore usable by **FSSgam**. Here we are fitting a binomial model using the **cbind** format for **successes** and **failures** which must be as labelled in the **use.dat** data.frame. With uGamm the random effects are specified outside the model formula, meaning they will not be updated by **FSSgam** and must be specified exactly in the **test.fit**. The random effect terms will not need to be specified explicitly as **null.terms**, but they will need to appear in **use.dat**. 19 | 20 | ## What exactly is the r2.vals metric, and how is it derived. 21 | 22 | Some information on the R-squuared values reported by **FSSgam** can be found in the help file, type **?fit.model.set** into the R console. The default value supplied is an approximation based on the R-square value calculated for a model between the fitted values and the observed data. This approximation was used because R.sq is not always provided by the underlying **gam(m)** functions used, and may cause errors. If you set the argument **r2.type=”r2”** **FSSgam** will return the R-square as calculated by the underlying gam function, which in most cases is what should be reported. If you want an **R.sq** that represents that left over after random effects are removed, you can also set **report.unique.r2=TRUE** which will subtract the null model **R2** from each of the fitted models in the set. The **report.unique.r2** as defined can sometimes yield negative R.sq values, so may or may not be useful for reporting. There are more formal methods for calculating the R.sq for the fixed component of models as these cannot be easily generalised across all the model types handled by **FSSgam** this is not currently implemented in the package. Subtracting the null model R.sq is a simplification, but potentially still informative. 23 | 24 | ## Do I need to include a Null intercept only model in **null.terms**? 25 | 26 | FSSgam automatically includes a null, intercept only model in the model set. This model will add any additional terms specified as **null.terms** to the model formula as well. The null model is useful to assess if any of the included predictors have explanatory value, thus if your null model is in the top set (say within 2AICc), it may be inferred that none of the predictors are useful beyond simply a mean value of the response. 27 | 28 | ## When I use lm4=TRUE, so I need to include my random effect in **null.terms**? 29 | 30 | The FSSgam package only updates the model formula, everything else in the model remains the same and becomes part of the null model. When a gamm4 is fit using lme4 = TRUE, this is a separate argument to gamm4 ("random") - and so the specified random effect will be retained as part of the null model. SO the answer is NO, in this case you do not need to add your random effect to **null.terms**. The only reason random effects sometimes need to be specified in **null.terms** is when the formulation bs='re' is used to specify them in gam from mgcv - because in that case they are part of the model formula and will be overwritten by the set of model formula as they are fit by FSSgam. 31 | 32 | -------------------------------------------------------------------------------- /extra_examples.R: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Australian Institute of Marine Science 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # A simple function for full subsets multiple regression in ecology with R 16 | # 17 | # R. Fisher 18 | # S.K. Wilson 19 | # S.M. Sin 20 | # A.C. Lee 21 | # T.J. Langlois 22 | 23 | # Source the package 24 | devtools::install_github("beckyfisher/FSSgam_package") 25 | library(FSSgam) 26 | library(RCurl) 27 | 28 | ################################################################################ 29 | ### Example showing use of uGamm to allow fitting with gamm4 ################## 30 | # load data coral data set 31 | #dat <-read.csv(text=getURL("https://raw.githubusercontent.com/beckyfisher/FSSgam/master/extra_examples_coral_data.csv")) 32 | dat <- read.csv("extra_examples_coral_data.csv") 33 | colnames(dat) 34 | head(dat) 35 | str(dat) 36 | 37 | cat.preds=c("Survey","bleach.pres","dredge.pres","dhw.fact") 38 | null.vars=c("Site") 39 | cont.preds=c("av.wave","Depth") 40 | 41 | # get rid of NA's and unused columns 42 | use.dat=na.omit(dat[,c(null.vars,cat.preds,cont.preds,"allcoral","totalpoints")]) 43 | use.dat$successes=use.dat$allcoral 44 | use.dat$failures=use.dat$totalpoints-use.dat$allcoral 45 | use.dat$trials=use.dat$totalpoints 46 | 47 | #test.fit model for all coral, with total points as trials 48 | require(MuMIn) 49 | Model1=uGamm(cbind(successes,failures)~s(Depth,k=4,bs='cr'), 50 | family=binomial(), random=~(1|Site), 51 | data=use.dat, 52 | lme4=TRUE) 53 | 54 | model.set=generate.model.set(use.dat=use.dat, 55 | test.fit=Model1, 56 | pred.vars.cont=cont.preds, 57 | pred.vars.fact=cat.preds) 58 | out.list=fit.model.set(model.set, parallel = TRUE, #r2.type = "dev", 59 | report.unique.r2 = TRUE) 60 | # examine the output 61 | names(out.list) 62 | out.list$failed.models 63 | length(out.list$success.models) 64 | mod.table=out.list$mod.data.out 65 | mod.table=mod.table[order(mod.table$AICc),] 66 | head(mod.table) 67 | 68 | # check the predictor correlation matrix 69 | model.set$predictor.correlations 70 | 71 | # now run the same thing using the non.linear correlation matrix 72 | model.set=generate.model.set(use.dat=use.dat, 73 | test.fit=Model1, 74 | pred.vars.cont=cont.preds, 75 | pred.vars.fact=cat.preds, 76 | non.linear.correlations=TRUE) 77 | model.set$predictor.correlations 78 | out.list=fit.model.set(model.set) 79 | mod.table=out.list$mod.data.out 80 | mod.table=mod.table[order(mod.table$AICc),] 81 | head(mod.table) 82 | 83 | #--- now an example running across a range of response variables ------------ 84 | resp.vars=c("Acropora.spp.","Turbinaria.spp.","Pocillopora.spp.","Porites.spp.") 85 | # get rid of NA's and unused columns 86 | use.dat=na.omit(dat[,c(null.vars,cat.preds,cont.preds,resp.vars,"totalpoints")]) 87 | 88 | out.all=list() 89 | var.imp=list() 90 | fss.all=list() 91 | top.all=list() 92 | i=1 93 | pdf(file="mod_fits_all.pdf",onefile=T) 94 | for(i in 1:length(resp.vars)){ 95 | use.dat$response=use.dat[,resp.vars[i]] 96 | #test.fit model for the particular coral i, with total points as trials 97 | Model1=uGamm(cbind(use.dat$response,use.dat$totalpoints-use.dat$response)~s(Depth,k=4,bs='cr'), 98 | family=binomial(), random=~(1|Site), 99 | data=use.dat, 100 | lme4=TRUE) 101 | 102 | model.set=generate.model.set(use.dat=use.dat, 103 | test.fit=Model1, 104 | pred.vars.cont=cont.preds, 105 | pred.vars.fact=cat.preds) 106 | out.list=fit.model.set(model.set) 107 | fss.all=c(fss.all,list(out.list)) 108 | mod.table=out.list$mod.data.out 109 | mod.table=mod.table[order(mod.table$AICc),] 110 | out.i=mod.table 111 | out.all=c(out.all,list(out.i)) 112 | var.imp=c(var.imp,list(out.list$variable.importance$aic$variable.weights.raw)) 113 | all.less.2AICc=mod.table[which(mod.table$delta.AICc<2),] 114 | top.all=c(top.all,list(all.less.2AICc)) 115 | 116 | # plot the all best models 117 | par(oma=c(1,1,4,1)) 118 | for(r in 1:nrow(all.less.2AICc)){ 119 | best.model.name=as.character(all.less.2AICc$modname[r]) 120 | best.model=out.list$success.models[[best.model.name]] 121 | if(best.model.name!="null"){ 122 | plot(best.model$gam,all.terms=T,pages=1,residuals=T,pch=16) 123 | mtext(side=3,text=resp.vars[i],outer=T)} 124 | } 125 | } 126 | dev.off() 127 | 128 | names(out.all)=resp.vars 129 | names(var.imp)=resp.vars 130 | names(top.all)=resp.vars 131 | names(fss.all)=resp.vars 132 | 133 | all.mod.fits=do.call("rbind",out.all) 134 | all.var.imp=do.call("rbind",var.imp) 135 | top.mod.fits=do.call("rbind",top.all) 136 | 137 | require(car) 138 | require(doBy) 139 | require(gplots) 140 | require(RColorBrewer) 141 | 142 | pdf(file="var_importance.pdf",height=5,width=7,pointsize=10) 143 | heatmap.2(all.var.imp,notecex=0.4, dendrogram ="none", 144 | col=colorRampPalette(c("yellow","orange","red"))(30), 145 | trace="none",key.title = "",keysize=2, 146 | notecol="black",key=T, 147 | sepcolor = "black",margins=c(12,14), lhei=c(3,10),lwid=c(3,10), 148 | Rowv=FALSE,Colv=FALSE) 149 | dev.off() 150 | 151 | write.csv(all.mod.fits,"all_model_fits.csv") 152 | write.csv(top.mod.fits,"top_model_fits.csv") 153 | 154 | ################################################################################ 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | -------------------------------------------------------------------------------- /case_study3_reproductive_cycles.R: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Australian Institute of Marine Science 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # A simple function for full subsets multiple regression in ecology with R 16 | # 17 | # R. Fisher 18 | # S.K. Wilson 19 | # S.M. Sin 20 | # A.C. Lee 21 | # T.J. Langlois 22 | 23 | # Reproducible example for: 24 | # Case Study 3: Reproductive patterns of tropical intertidal invertebrates over 25 | # multiple temporal scales 26 | 27 | # The analysis uses the full.subsets.function to fit a complete model set 28 | # to explore temporal patterns in gonadal somatix index (GSI) in two species of 29 | # gastropods. GSI is modelled as a Gamma distribution. 30 | # Both lunar.date and month are entered into the model as continous cyclic smooths. 31 | # Sex and Species are included as interaction terms with each other, and as 32 | # interaction terms between the two smoothers. 33 | 34 | # note this example was updated on the 11th Oct 2018 to demonstrate useage of the replacement functions 35 | # generate.model.set and fit.model.set that have now superced full.subsets.gam in package FSSgam 36 | # Between them these functions carry out the same analysis, take the same arguments and return the same 37 | # outputs as full.subsets.gam with the only difference being that the model set generation and model 38 | # fitting procedures are separated into two steps. This was done to make the function easier to use, 39 | # because the model set can be interrogated, along with the correlation matrix of the predictors before model 40 | # fitting is even attempted. 41 | 42 | 43 | # Install package---- 44 | library(RCurl) 45 | devtools::install_github("beckyfisher/FSSgam_package") 46 | library(FSSgam) 47 | 48 | # load data 49 | download.file("https://raw.githubusercontent.com/beckyfisher/FSSgam/master/case_study3_dataset.csv", destfile = "/tmp/c3dat.csv") 50 | dat <-read.csv("/tmp/c3dat.csv") 51 | dim(dat) 52 | 53 | str(dat) 54 | # specify factors 55 | dat$year=as.factor(dat$year) 56 | 57 | # response variable exploration, what distribution? 58 | hist(dat$GSI) 59 | range(dat$GSI) 60 | # slightly skewed, continuous variable, does not include zero = gamma 61 | 62 | # specify predictors 63 | cyclic.vars=c("lunar.date","month") 64 | factor.vars=c("Sex","Species") 65 | cont.vars=c("lunar.date","month") 66 | 67 | require(mgcv) 68 | require(MuMIn) 69 | use.dat=dat 70 | start.fit=gam(GSI~s(lunar.date,k=5,bs='cc'), 71 | family="Gamma", 72 | data=use.dat) 73 | model.set=generate.model.set(use.dat=use.dat, 74 | test.fit=start.fit, 75 | pred.vars.cont=cont.vars, 76 | pred.vars.fact=factor.vars, 77 | cyclic.vars=cyclic.vars,k=5, 78 | factor.factor.interactions=T, 79 | smooth.smooth.interactions=T, 80 | max.predictors=4) 81 | out.list=fit.model.set(model.set,parallel=T) 82 | names(out.list) 83 | 84 | write.csv(out.list$predictor.correlations,"predictor_correlations.csv") 85 | out.list$predictor.correlations 86 | 87 | # examine the list of failed models 88 | length(out.list$failed.models) 89 | length(out.list$success.models) 90 | 91 | # look at the model selection table 92 | mod.table=out.list$mod.data.out 93 | mod.table=mod.table[order(mod.table$AICc),] 94 | head(mod.table) 95 | write.csv(mod.table[,-2],"modfits.csv") 96 | 97 | barplot(out.list$variable.importance$bic$variable.weights.raw,las=2, 98 | ylab="Relative variable importance") 99 | 100 | write.csv(model.set$predictor.correlations,"predictor_correlations.csv") 101 | 102 | # extract the best model 103 | mod.table=mod.table[order(mod.table$AIC),] 104 | head(mod.table) 105 | 106 | best.model=out.list$success.models[[as.character(mod.table$modname[1])]] 107 | plot(best.model,all.terms=T,pages=1) 108 | 109 | gam.check(best.model) 110 | summary(best.model) 111 | 112 | # make a pretty plot 113 | # get the data from the out.list object because this contains the interactions 114 | model.dat=model.set$used.data 115 | head(model.dat) 116 | str(model.dat) 117 | 118 | x.seq=seq(from=1,to=30,length=100) 119 | 120 | best.mod.fact.vars=c("Sex","Species") 121 | fact.grid=unique(model.dat[,best.mod.fact.vars]) 122 | sex.ltys=c(1,2) 123 | sex.pchs=c(19,21) 124 | sex.lvls=levels(model.dat$Sex) 125 | spp.lvls=levels(model.dat$Species) 126 | sex.cols=c("blue","red") 127 | 128 | # create some symbology and colour schemes for plotting 129 | model.dat$pchs=16 130 | for(a in 1:length(sex.lvls)){ 131 | model.dat$cols[which(model.dat$Sex==sex.lvls[a])]=sex.cols[a]} 132 | 133 | y.lim=c(0,ceiling(max(model.dat$GSI))) 134 | lunar.lim=range(model.dat$lunar.date) 135 | lunar.seq=seq(from=1,to=30,length=100) 136 | month.lim=range(model.dat$month) 137 | month.seq=seq(from=1,to=30,length=100) 138 | 139 | month.labels=c("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec") 140 | 141 | spp.labels=c("Monodonta labio", "Patelloida saccharina") 142 | pdf(file="best_model.pdf",pointsize=12) 143 | par(mfcol=c(2,2),mar=c(0,0.5,0.5,0.5),oma=c(5,4,0.5,2)) 144 | for(x in 1:length(spp.lvls)){ 145 | # lunar 146 | spp=spp.lvls[x] 147 | fact.grid.plot=fact.grid[grep(spp,fact.grid$Species),] 148 | plot.dat=model.dat[grep(spp,model.dat$Species),] 149 | plot(NA,ylim=y.lim,xlim=lunar.lim,ylab="",xlab="",main="",xpd=NA,yaxt="n",xaxt="n") 150 | axis(side=2) 151 | if(x==2){axis(side=1)} 152 | for(r in 1:nrow(fact.grid.plot)){ 153 | pred.vals=predict(best.model,newdata=data.frame( 154 | lunar.date=lunar.seq, 155 | month=mean(model.dat$month), 156 | Species=spp, 157 | Sex=fact.grid.plot[r,"Sex"]), 158 | type="response",se=T) 159 | lines(x.seq,pred.vals$fit,lwd=1.5, 160 | col=sex.cols[which(fact.grid.plot[r,"Sex"]==sex.lvls)]) 161 | lines(x.seq,pred.vals$fit+1.96*pred.vals$se,lty=3,lwd=1.5, 162 | col=sex.cols[which(fact.grid.plot[r,"Sex"]==sex.lvls)]) 163 | lines(x.seq,pred.vals$fit-1.96*pred.vals$se, lty=3,lwd=1.5, 164 | col=sex.cols[which(fact.grid.plot[r,"Sex"]==sex.lvls)])} 165 | points(jitter(plot.dat$lunar.date),plot.dat$GSI,pch=16,col=plot.dat$cols)} 166 | # month 167 | for(x in 1:length(spp.lvls)){ 168 | spp=spp.lvls[x] 169 | fact.grid.plot=fact.grid[grep(spp,fact.grid$Species),] 170 | plot.dat=model.dat[grep(spp,model.dat$Species),] 171 | plot(NA,ylim=y.lim,xlim=month.lim,ylab="",xlab="",main="",xpd=NA,yaxt="n",xaxt="n") 172 | #if(x==1){axis(side=2)} 173 | if(x==2){axis(side=1,at=c(2,4,6,8,10,12),labels=month.labels[c(2,4,6,8,10,12)])} 174 | for(r in 1:nrow(fact.grid.plot)){ 175 | pred.vals=predict(best.model,newdata=data.frame( 176 | lunar.date=mean(model.dat$lunar.date), 177 | month=month.seq, 178 | Species=spp, 179 | Sex=fact.grid.plot[r,"Sex"]), 180 | type="response",se=T) 181 | lines(x.seq,pred.vals$fit,lwd=1.5, 182 | col=sex.cols[which(fact.grid.plot[r,"Sex"]==sex.lvls)]) 183 | lines(x.seq,pred.vals$fit+1.96*pred.vals$se,lty=3,lwd=1.5, 184 | col=sex.cols[which(fact.grid.plot[r,"Sex"]==sex.lvls)]) 185 | lines(x.seq,pred.vals$fit-1.96*pred.vals$se, lty=3,lwd=1.5, 186 | col=sex.cols[which(fact.grid.plot[r,"Sex"]==sex.lvls)])} 187 | points(jitter(plot.dat$month),plot.dat$GSI,pch=16,col=plot.dat$cols)} 188 | 189 | mtext(side=1,text=c("Lunar date","Month of the year"),at=c(0.25,0.75),outer=T,line=2.5) 190 | mtext(side=2,text="GSI",outer=T,line=2) 191 | mtext(side=4,text=spp.labels,at=c(0.75,0.25),outer=T) 192 | legend.dat=unique(model.dat[,c("Sex","cols")]) 193 | legend.dat=legend.dat[order(legend.dat$Sex),] 194 | 195 | legend("bottom",legend=paste(legend.dat$Sex),bty="n",cex=1, 196 | inset=-0.275,ncol=2,lty=1,col=legend.dat$cols,pch=16,xpd=NA) 197 | dev.off() 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | -------------------------------------------------------------------------------- /case_study1_reef_fish.R: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Australian Institute of Marine Science 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # A simple function for full subsets multiple regression in ecology with R 16 | # 17 | # R. Fisher 18 | # S.K. Wilson 19 | # S.M. Sin 20 | # A.C. Lee 21 | # T.J. Langlois 22 | 23 | # Reproducible example for: 24 | # Case Study 1: The relative influence of management and habitat on fish abundance and biomass 25 | 26 | # note this example was updated on the 11th Oct 2018 to demonstrate useage of the replacement functions 27 | # generate.model.set and fit.model.set that have now superced full.subsets.gam in package FSSgam 28 | # Between them these functions carry out the same analysis, take the same arguments and return the same 29 | # outputs as full.subsets.gam with the only difference being that the model set generation and model 30 | # fitting procedures are separated into two steps. This was done to make the function easier to use, 31 | # because the model set can be interrogated, along with the correlation matrix of the predictors before model 32 | # fitting is even attempted. 33 | 34 | # Source functions---- 35 | devtools::install_github("beckyfisher/FSSgam_package") 36 | library(FSSgam) 37 | library(RCurl) 38 | # load data 39 | download.file("https://raw.githubusercontent.com/beckyfisher/FSSgam/master/case_study1_dataset.csv", destfile = "c1dat.csv") 40 | dat <-read.csv("c1dat.csv") 41 | dim(dat) 42 | 43 | require(mgcv) 44 | require(MuMIn) 45 | require(doParallel) 46 | require(plyr) 47 | 48 | colnames(dat) 49 | 50 | dat$SQRTSA=dat$SA 51 | dat$sqrt.rug=sqrt(dat$rugosity) 52 | dat$sqrtLC=sqrt(dat$LC) 53 | dat$sqrtHC=sqrt(dat$HC) 54 | dat$sqrtMacro=sqrt(dat$macro) 55 | 56 | cat.preds="ZONE" 57 | null.vars=c("depth","site","SQRTSA") # use as random effect and null model 58 | cont.preds=c("complexity","sqrt.rug","sqrtLC","sqrtHC","sqrtMacro", 59 | "SCORE1","SCORE2") # use as continuous predictors. 60 | cor(dat[,cont.preds]) 61 | # have a look at the distribution of the continuous predictors 62 | pdf(file="pred_vars.pdf",onefile=T) 63 | for(p in 1:length(cont.preds)){ 64 | par(mfrow=c(2,1)) 65 | hist(dat[,cont.preds[p]],main=cont.preds[p]) 66 | plot(jitter(dat[,cont.preds[p]])) 67 | } 68 | dev.off() 69 | 70 | # remove extreme outliers 71 | dat$Piscivore.abundance[which(dat$Piscivore.abundance>150)]=NA 72 | dat$Piscivore.biomass[which(dat$Piscivore.biomass>40000)]=NA 73 | dat$Invertivore.biomass[which(dat$Invertivore.biomass>40000)]=NA 74 | dat$site <- as.factor(dat$site) 75 | 76 | resp.vars.fams=list("Herbivore.abundance"=tw(), 77 | "Invertivore.abundance"=tw(), 78 | "Piscivore.abundance"=tw(), 79 | "Planktivore.abundance"=tw(), 80 | "Herbivore.biomass"=tw(), 81 | "Invertivore.biomass"=tw(), 82 | "Piscivore.biomass"=tw(), 83 | "Planktivore.biomass"=tw()) 84 | resp.vars=names(resp.vars.fams) 85 | 86 | # take a look at the response variables 87 | pdf(file="resp_vars.pdf",onefile=T) 88 | for(r in 1:length(resp.vars)){ 89 | par(mfrow=c(2,1)) 90 | hist(dat[,resp.vars[r]],main=resp.vars[r]) 91 | plot(jitter(dat[,resp.vars[r]])) 92 | } 93 | dev.off() 94 | 95 | ### now fit the models --------------------------------------------------------- 96 | i=1 97 | out.all=list() 98 | var.imp=list() 99 | fss.all=list() 100 | top.all=list() 101 | pdf(file="mod_fits_functional_biomass.pdf",onefile=T) 102 | for(i in 1:length(resp.vars)){ 103 | use.dat=na.omit(dat[,c(null.vars,cont.preds,cat.preds,resp.vars[i])]) 104 | use.dat$response=use.dat[,resp.vars[i]] 105 | Model1=gam(response~s(complexity,k=4,bs='cr')+ 106 | +s(SQRTSA,bs='cr',k=4) +s(site,bs="re"), 107 | family=tw(), 108 | data=use.dat) 109 | 110 | model.set=generate.model.set(use.dat=use.dat,max.predictors=2, # limit size here because null model already complex 111 | test.fit=Model1,k=3, 112 | pred.vars.cont=cont.preds, 113 | pred.vars.fact=cat.preds, 114 | null.terms="s(SQRTSA,bs='cr',k=3)+s(site,bs='re')+s(depth,bs='cr',k=3)") 115 | 116 | out.list=fit.model.set(model.set, parallel = TRUE) 117 | ?d#names(out.list) 118 | # examine the list of failed models 119 | #out.list$failed.models 120 | #out.list$success.models 121 | fss.all=c(fss.all,list(out.list)) 122 | mod.table=out.list$mod.data.out 123 | mod.table=mod.table[order(mod.table$AICc),] 124 | out.i=mod.table 125 | out.all=c(out.all,list(out.i)) 126 | var.imp=c(var.imp,list(out.list$variable.importance$aic$variable.weights.raw)) 127 | all.less.2AICc=mod.table[which(mod.table$delta.AICc<2),] 128 | top.all=c(top.all,list(all.less.2AICc)) 129 | 130 | # plot the all best models 131 | par(oma=c(1,1,4,1)) 132 | for(r in 1:nrow(all.less.2AICc)){ 133 | best.model.name=as.character(all.less.2AICc$modname[r]) 134 | best.model=out.list$success.models[[best.model.name]] 135 | if(best.model.name!="null"){ 136 | plot(best.model,all.terms=T,pages=1,residuals=T,pch=16) 137 | mtext(side=3,text=resp.vars[i],outer=T)} 138 | } 139 | } 140 | dev.off() 141 | 142 | names(out.all)=resp.vars 143 | names(var.imp)=resp.vars 144 | names(top.all)=resp.vars 145 | names(fss.all)=resp.vars 146 | 147 | all.mod.fits=do.call("rbind",out.all) 148 | all.var.imp=do.call("rbind",var.imp) 149 | top.mod.fits=do.call("rbind",top.all) 150 | 151 | require(car) 152 | require(doBy) 153 | require(gplots) 154 | require(RColorBrewer) 155 | 156 | pdf(file="var_importance_heatmap_functional_biomass.pdf",height=5,width=7,pointsize=10) 157 | heatmap.2(all.var.imp,notecex=0.4, dendrogram ="none", 158 | col=colorRampPalette(c("white","yellow","orange","red"))(30), 159 | trace="none",key.title = "",keysize=2, 160 | notecol="black",key=T, 161 | sepcolor = "black",margins=c(12,14), lhei=c(3,10),lwid=c(3,10), 162 | Rowv=FALSE,Colv=FALSE) 163 | dev.off() 164 | 165 | write.csv(all.mod.fits[,-2],"all_model_fits_functional_biomass.csv") 166 | write.csv(top.mod.fits[,-2],"top_model_fits_functional_biomass.csv") 167 | write.csv(model.set$predictor.correlations,"predictor_correlations.csv") 168 | 169 | #### pretty plots of best models ----------------------------------------------- 170 | zones=levels(dat$ZONE) 171 | pdf("best_top_model_quick_plots.pdf",height=8,width=7,pointsize=12) 172 | par(mfcol=c(4,2),mar=c(4,4,0.5,0.5),oma=c(2,0.5,0.5,0.5),bty="l") 173 | for(r in 1:length(resp.vars)){ 174 | tab.r=out.all[[resp.vars[r]]] 175 | top.mods.r=tab.r[1,] 176 | mod.r.m=as.character(top.mods.r[1,"modname"]) 177 | mod.m=fss.all[[resp.vars[r]]]$success.models[[mod.r.m]] 178 | mod.vars=unique(unlist(strsplit(unlist(strsplit(mod.r.m,split="+",fixed=T)), 179 | split=".by."))) 180 | # which continuous predictor is the variable included? 181 | plot.var=as.character(na.omit(mod.vars[match(cont.preds,mod.vars)])) 182 | # plot that variables, with symbol colours for zone 183 | plot(dat[,plot.var],dat[,resp.vars[r]],pch=16, 184 | ylab=resp.vars[r],xlab=plot.var,col=dat$ZONE) 185 | legend("topleft",legend=paste("(",LETTERS[r],")",sep=""), 186 | bty="n") 187 | range.v=range(dat[,plot.var]) 188 | seq.v=seq(range.v[1],range.v[2],length=20) 189 | newdat.list=list(seq.v,# across the range of the included variable 190 | mean(use.dat$depth), # for a median depth 191 | mean(use.dat$SQRTSA),# for a median SQRTSA 192 | "MANGROVE", # pick the first site, except don't predict on 193 | # this by setting terms=c(plot.var,"ZONE") 194 | zones) # for each zone 195 | names(newdat.list)=c(plot.var,"depth","SQRTSA","site","ZONE") 196 | pred.vals=predict(mod.m,newdata=expand.grid(newdat.list), 197 | type="response",se=T,exclude=c("site","SQRTSA","depth")) 198 | for(z in 1:length(zones)){ 199 | zone.index=which(expand.grid(newdat.list)$ZONE==zones[z]) 200 | lines(seq.v,pred.vals$fit[zone.index],col=z) 201 | lines(seq.v,pred.vals$fit[zone.index]+pred.vals$se[zone.index]*1.96,lty=3,col=z) 202 | lines(seq.v,pred.vals$fit[zone.index]-pred.vals$se[zone.index]*1.96,lty=3,col=z)} 203 | } 204 | legend("bottom",legend= zones,bty="n",ncol=2,col=c(1,2),pch=c(16,16), 205 | inset=-0.61,xpd=NA,cex=.8) 206 | dev.off() 207 | 208 | -------------------------------------------------------------------------------- /case_study2_model_out/clams_all.mod.fits.csv: -------------------------------------------------------------------------------- 1 | "","modname","AICc","BIC","r2.vals","r2.vals.unique","edf","edf.less.1","delta.AICc","delta.BIC","wi.AICc","wi.BIC","sqrt.X4mm","sqrt.X2mm","sqrt.X1mm","sqrt.X500um","fetch","org","snapper","lobster","Status","Distance","cumsum.wi" 2 | "BDS.sqrt.X500um+Status+Distance","sqrt.X500um+Status+Distance",344.61503443035,387.330617320029,0.5337,NA,19.65,0,0,0,0.162,0.225,0,0,0,1,0,0,0,0,1,1,0.162 3 | "BDS.fetch+Status+Distance","fetch+Status+Distance",345.261126296606,388.334827664104,0.46305,NA,20.14,0,0.646,1.004,0.117,0.136,0,0,0,0,1,0,0,0,1,1,0.279 4 | "BDS.Status+Distance+sqrt.X500um.by.Status","Status+Distance+sqrt.X500um.by.Status",345.593896325794,388.849916465516,0.51263,NA,20.09,0,0.979,1.519,0.099,0.105,0,0,0,1,0,0,0,0,1,1,0.378 5 | "BDS.fetch+lobster+Distance","fetch+lobster+Distance",345.815874753348,389.00416555432,0.47085,NA,19.96,0,1.201,1.674,0.089,0.097,0,0,0,0,1,0,0,1,0,1,0.467 6 | "BDS.fetch+Distance","fetch+Distance",345.881566785452,389.067029100226,0.44186,NA,20.3,0,1.267,1.736,0.086,0.094,0,0,0,0,1,0,0,0,0,1,0.553 7 | "BDS.fetch+snapper+Distance","fetch+snapper+Distance",346.663891977369,390.21739533209,0.4408,NA,20.66,0,2.049,2.887,0.058,0.053,0,0,0,0,1,0,1,0,0,1,0.611 8 | "BDS.sqrt.X500um+Status+Distance.t.Status","sqrt.X500um+Status+Distance.t.Status",346.960283821045,390.707969441043,0.52404,NA,20.66,0,2.345,3.377,0.05,0.041,0,0,0,1,0,0,0,0,1,1,0.661 9 | "BDS.sqrt.X500um+snapper+Distance","sqrt.X500um+snapper+Distance",347.17847388405,391.12262900101,0.52615,NA,20.98,0,2.563,3.792,0.045,0.034,0,0,0,1,0,0,1,0,0,1,0.706 10 | "BDS.fetch+Status+Distance.t.Status","fetch+Status+Distance.t.Status",347.193349866642,391.275285563359,0.45834,NA,21.17,0,2.578,3.945,0.045,0.031,0,0,0,0,1,0,0,0,1,1,0.751 11 | "BMS","Status+Distance+org.by.Status",312.607228213057,357.982246907728,0.52627,NA,22.45,0,0,0,0.937,0.661,0,0,0,0,0,1,0,0,1,1,0.937 12 | "CPN.sqrt.X4mm+Distance","sqrt.X4mm+Distance",477.211361111149,521.093352614688,0.49295,NA,20.9,0,0,1.603,0.061,0.031,1,0,0,0,0,0,0,0,0,1,0.061 13 | "CPN.sqrt.X4mm+fetch+Distance","sqrt.X4mm+fetch+Distance",477.40026937098,521.391999648418,0.48872,NA,21.06,0,0.189,1.902,0.056,0.027,1,0,0,0,1,0,0,0,0,1,0.117 14 | "CPN.sqrt.X1mm+lobster+Distance","sqrt.X1mm+lobster+Distance",477.515528727141,519.489945455275,0.44359,NA,19.05,0,0.304,0,0.053,0.069,0,0,1,0,0,0,0,1,0,1,0.17 15 | "CPN.sqrt.X1mm+Distance","sqrt.X1mm+Distance",477.877695247619,519.889490244463,0.45414,NA,19.11,0,0.666,0.4,0.044,0.056,0,0,1,0,0,0,0,0,0,1,0.214 16 | "CPN.sqrt.X1mm+snapper+Distance","sqrt.X1mm+snapper+Distance",478.147611241407,520.250863032048,0.44695,NA,19.14,0,0.936,0.761,0.038,0.047,0,0,1,0,0,0,1,0,0,1,0.252 17 | "CPN.sqrt.X1mm+Status+Distance","sqrt.X1mm+Status+Distance",478.21208595992,520.414163799793,0.45348,NA,19.28,0,1.001,0.924,0.037,0.043,0,0,1,0,0,0,0,0,1,1,0.289 18 | "CPN.sqrt.X4mm+lobster","sqrt.X4mm+lobster",479.079400932741,521.580519673982,0.46683,NA,19.54,0,1.868,2.091,0.024,0.024,1,0,0,0,0,0,0,1,0,0,0.313 19 | "CPN.sqrt.X4mm+sqrt.X500um+lobster","sqrt.X4mm+sqrt.X500um+lobster",479.090826711357,521.925136714939,0.4619,NA,19.84,0,1.879,2.435,0.024,0.02,1,0,0,1,0,0,0,1,0,0,0.337 20 | "CPN.sqrt.X4mm+sqrt.X500um","sqrt.X4mm+sqrt.X500um",479.302765563719,522.156893109892,0.47359,NA,19.9,0,2.091,2.667,0.022,0.018,1,0,0,1,0,0,0,0,0,0,0.359 21 | "CPN.sqrt.X4mm+sqrt.X500um+snapper","sqrt.X4mm+sqrt.X500um+snapper",479.352501207602,522.235248787769,0.46417,NA,19.87,0,2.141,2.745,0.021,0.017,1,0,0,1,0,0,1,0,0,0,0.38 22 | "CPN.sqrt.X4mm+snapper","sqrt.X4mm+snapper",479.362901330117,521.935946256357,0.47143,NA,19.62,0,2.152,2.446,0.021,0.02,1,0,0,0,0,0,1,0,0,0,0.401 23 | "CPN.sqrt.X4mm","sqrt.X4mm",479.37301432298,521.939049096695,0.48102,NA,19.66,0,2.162,2.449,0.021,0.02,1,0,0,0,0,0,0,0,0,0,0.422 24 | "CPN.sqrt.X500um+Distance","sqrt.X500um+Distance",479.465024386517,521.729452923577,0.4755,NA,19.31,0,2.254,2.24,0.02,0.023,0,0,0,1,0,0,0,0,0,1,0.442 25 | "CPN.Status+Distance+sqrt.X1mm.by.Status","Status+Distance+sqrt.X1mm.by.Status",479.472598620822,522.616963093334,0.4592,NA,20.19,0,2.261,3.127,0.02,0.014,0,0,1,0,0,0,0,0,1,1,0.462 26 | "CPN.sqrt.X500um+snapper+Distance","sqrt.X500um+snapper+Distance",479.636303796396,521.946173965538,0.46642,NA,19.29,0,2.425,2.456,0.018,0.02,0,0,0,1,0,0,1,0,0,1,0.48 27 | "CPN.sqrt.X4mm+sqrt.X500um+Status","sqrt.X4mm+sqrt.X500um+Status",479.642217597407,522.676767371616,0.47183,NA,20.07,0,2.431,3.187,0.018,0.014,1,0,0,1,0,0,0,0,1,0,0.498 28 | "CPN.sqrt.X4mm+fetch+lobster","sqrt.X4mm+fetch+lobster",479.672960029634,522.362372822011,0.45759,NA,19.68,0,2.462,2.872,0.018,0.016,1,0,0,0,1,0,0,1,0,0,0.516 29 | "CPN.sqrt.X4mm+Status","sqrt.X4mm+Status",479.709795359168,522.451899096407,0.47796,NA,19.82,0,2.498,2.962,0.018,0.016,1,0,0,0,0,0,0,0,1,0,0.534 30 | "CPN.sqrt.X2mm+lobster+Distance","sqrt.X2mm+lobster+Distance",479.787801405757,522.247872517036,0.45333,NA,19.53,0,2.576,2.758,0.017,0.017,0,1,0,0,0,0,0,1,0,1,0.551 31 | "CPN.sqrt.X4mm+fetch","sqrt.X4mm+fetch",479.800250113978,522.568934146593,0.47558,NA,19.81,0,2.589,3.079,0.017,0.015,1,0,0,0,1,0,0,0,0,0,0.568 32 | "CPN.sqrt.X500um+Status+Distance","sqrt.X500um+Status+Distance",479.923091821053,522.415419936469,0.474,NA,19.51,0,2.712,2.925,0.016,0.016,0,0,0,1,0,0,0,0,1,1,0.584 33 | "CPN.Distance","Distance",479.97597674282,522.155984987439,0.48292,NA,19.27,0,2.765,2.666,0.015,0.018,0,0,0,0,0,0,0,0,0,1,0.599 34 | "CPN.sqrt.X4mm+fetch+snapper","sqrt.X4mm+fetch+snapper",479.990755372925,522.840505965131,0.46456,NA,19.84,0,2.779,3.351,0.015,0.013,1,0,0,0,1,0,1,0,0,0,0.614 35 | "CPN.snapper+Distance","snapper+Distance",480.105762810659,522.318054806322,0.47393,NA,19.23,0,2.894,2.828,0.014,0.017,0,0,0,0,0,0,1,0,0,1,0.628 36 | "CPN.fetch+lobster+Distance","fetch+lobster+Distance",480.175879532209,522.470570697533,0.4583,NA,19.26,0,2.965,2.981,0.014,0.016,0,0,0,0,1,0,0,1,0,1,0.642 37 | "CPN.sqrt.X4mm+fetch+Status","sqrt.X4mm+fetch+Status",480.187262319785,523.108439277508,0.4709,NA,19.93,0,2.976,3.618,0.014,0.011,1,0,0,0,1,0,0,0,1,0,0.656 38 | "NA.sqrt.X4mm+Distance","sqrt.X4mm+Distance",477.211361111149,521.093352614688,0.49295,NA,20.9,0,0,1.603,0.061,0.031,1,0,0,0,0,0,0,0,0,1,0.061 39 | "NA.sqrt.X4mm+fetch+Distance","sqrt.X4mm+fetch+Distance",477.40026937098,521.391999648418,0.48872,NA,21.06,0,0.189,1.902,0.056,0.027,1,0,0,0,1,0,0,0,0,1,0.117 40 | "NA.sqrt.X1mm+lobster+Distance","sqrt.X1mm+lobster+Distance",477.515528727141,519.489945455275,0.44359,NA,19.05,0,0.304,0,0.053,0.069,0,0,1,0,0,0,0,1,0,1,0.17 41 | "NA.sqrt.X1mm+Distance","sqrt.X1mm+Distance",477.877695247619,519.889490244463,0.45414,NA,19.11,0,0.666,0.4,0.044,0.056,0,0,1,0,0,0,0,0,0,1,0.214 42 | "NA.sqrt.X1mm+snapper+Distance","sqrt.X1mm+snapper+Distance",478.147611241407,520.250863032048,0.44695,NA,19.14,0,0.936,0.761,0.038,0.047,0,0,1,0,0,0,1,0,0,1,0.252 43 | "NA.sqrt.X1mm+Status+Distance","sqrt.X1mm+Status+Distance",478.21208595992,520.414163799793,0.45348,NA,19.28,0,1.001,0.924,0.037,0.043,0,0,1,0,0,0,0,0,1,1,0.289 44 | "NA.sqrt.X4mm+lobster","sqrt.X4mm+lobster",479.079400932741,521.580519673982,0.46683,NA,19.54,0,1.868,2.091,0.024,0.024,1,0,0,0,0,0,0,1,0,0,0.313 45 | "NA.sqrt.X4mm+sqrt.X500um+lobster","sqrt.X4mm+sqrt.X500um+lobster",479.090826711357,521.925136714939,0.4619,NA,19.84,0,1.879,2.435,0.024,0.02,1,0,0,1,0,0,0,1,0,0,0.337 46 | "NA.sqrt.X4mm+sqrt.X500um","sqrt.X4mm+sqrt.X500um",479.302765563719,522.156893109892,0.47359,NA,19.9,0,2.091,2.667,0.022,0.018,1,0,0,1,0,0,0,0,0,0,0.359 47 | "NA.sqrt.X4mm+sqrt.X500um+snapper","sqrt.X4mm+sqrt.X500um+snapper",479.352501207602,522.235248787769,0.46417,NA,19.87,0,2.141,2.745,0.021,0.017,1,0,0,1,0,0,1,0,0,0,0.38 48 | "NA.sqrt.X4mm+snapper","sqrt.X4mm+snapper",479.362901330117,521.935946256357,0.47143,NA,19.62,0,2.152,2.446,0.021,0.02,1,0,0,0,0,0,1,0,0,0,0.401 49 | "NA.sqrt.X4mm","sqrt.X4mm",479.37301432298,521.939049096695,0.48102,NA,19.66,0,2.162,2.449,0.021,0.02,1,0,0,0,0,0,0,0,0,0,0.422 50 | "NA.sqrt.X500um+Distance","sqrt.X500um+Distance",479.465024386517,521.729452923577,0.4755,NA,19.31,0,2.254,2.24,0.02,0.023,0,0,0,1,0,0,0,0,0,1,0.442 51 | "NA.Status+Distance+sqrt.X1mm.by.Status","Status+Distance+sqrt.X1mm.by.Status",479.472598620822,522.616963093334,0.4592,NA,20.19,0,2.261,3.127,0.02,0.014,0,0,1,0,0,0,0,0,1,1,0.462 52 | "NA.sqrt.X500um+snapper+Distance","sqrt.X500um+snapper+Distance",479.636303796396,521.946173965538,0.46642,NA,19.29,0,2.425,2.456,0.018,0.02,0,0,0,1,0,0,1,0,0,1,0.48 53 | "NA.sqrt.X4mm+sqrt.X500um+Status","sqrt.X4mm+sqrt.X500um+Status",479.642217597407,522.676767371616,0.47183,NA,20.07,0,2.431,3.187,0.018,0.014,1,0,0,1,0,0,0,0,1,0,0.498 54 | "NA.sqrt.X4mm+fetch+lobster","sqrt.X4mm+fetch+lobster",479.672960029634,522.362372822011,0.45759,NA,19.68,0,2.462,2.872,0.018,0.016,1,0,0,0,1,0,0,1,0,0,0.516 55 | "NA.sqrt.X4mm+Status","sqrt.X4mm+Status",479.709795359168,522.451899096407,0.47796,NA,19.82,0,2.498,2.962,0.018,0.016,1,0,0,0,0,0,0,0,1,0,0.534 56 | "NA.sqrt.X2mm+lobster+Distance","sqrt.X2mm+lobster+Distance",479.787801405757,522.247872517036,0.45333,NA,19.53,0,2.576,2.758,0.017,0.017,0,1,0,0,0,0,0,1,0,1,0.551 57 | "NA.sqrt.X4mm+fetch","sqrt.X4mm+fetch",479.800250113978,522.568934146593,0.47558,NA,19.81,0,2.589,3.079,0.017,0.015,1,0,0,0,1,0,0,0,0,0,0.568 58 | "NA.sqrt.X500um+Status+Distance","sqrt.X500um+Status+Distance",479.923091821053,522.415419936469,0.474,NA,19.51,0,2.712,2.925,0.016,0.016,0,0,0,1,0,0,0,0,1,1,0.584 59 | "NA.Distance","Distance",479.97597674282,522.155984987439,0.48292,NA,19.27,0,2.765,2.666,0.015,0.018,0,0,0,0,0,0,0,0,0,1,0.599 60 | "NA.sqrt.X4mm+fetch+snapper","sqrt.X4mm+fetch+snapper",479.990755372925,522.840505965131,0.46456,NA,19.84,0,2.779,3.351,0.015,0.013,1,0,0,0,1,0,1,0,0,0,0.614 61 | "NA.snapper+Distance","snapper+Distance",480.105762810659,522.318054806322,0.47393,NA,19.23,0,2.894,2.828,0.014,0.017,0,0,0,0,0,0,1,0,0,1,0.628 62 | "NA.fetch+lobster+Distance","fetch+lobster+Distance",480.175879532209,522.470570697533,0.4583,NA,19.26,0,2.965,2.981,0.014,0.016,0,0,0,0,1,0,0,1,0,1,0.642 63 | "NA.sqrt.X4mm+fetch+Status","sqrt.X4mm+fetch+Status",480.187262319785,523.108439277508,0.4709,NA,19.93,0,2.976,3.618,0.014,0.011,1,0,0,0,1,0,0,0,1,0,0.656 64 | "NA.sqrt.X500um+Status+Distance1","sqrt.X500um+Status+Distance",344.61503443035,387.330617320029,0.5337,NA,19.65,0,0,0,0.162,0.225,0,0,0,1,0,0,0,0,1,1,0.162 65 | "NA.fetch+Status+Distance","fetch+Status+Distance",345.261126296606,388.334827664104,0.46305,NA,20.14,0,0.646,1.004,0.117,0.136,0,0,0,0,1,0,0,0,1,1,0.279 66 | "NA.Status+Distance+sqrt.X500um.by.Status","Status+Distance+sqrt.X500um.by.Status",345.593896325794,388.849916465516,0.51263,NA,20.09,0,0.979,1.519,0.099,0.105,0,0,0,1,0,0,0,0,1,1,0.378 67 | "NA.fetch+lobster+Distance1","fetch+lobster+Distance",345.815874753348,389.00416555432,0.47085,NA,19.96,0,1.201,1.674,0.089,0.097,0,0,0,0,1,0,0,1,0,1,0.467 68 | "NA.fetch+Distance","fetch+Distance",345.881566785452,389.067029100226,0.44186,NA,20.3,0,1.267,1.736,0.086,0.094,0,0,0,0,1,0,0,0,0,1,0.553 69 | "NA.fetch+snapper+Distance","fetch+snapper+Distance",346.663891977369,390.21739533209,0.4408,NA,20.66,0,2.049,2.887,0.058,0.053,0,0,0,0,1,0,1,0,0,1,0.611 70 | "NA.sqrt.X500um+Status+Distance.t.Status","sqrt.X500um+Status+Distance.t.Status",346.960283821045,390.707969441043,0.52404,NA,20.66,0,2.345,3.377,0.05,0.041,0,0,0,1,0,0,0,0,1,1,0.661 71 | "NA.sqrt.X500um+snapper+Distance1","sqrt.X500um+snapper+Distance",347.17847388405,391.12262900101,0.52615,NA,20.98,0,2.563,3.792,0.045,0.034,0,0,0,1,0,0,1,0,0,1,0.706 72 | "NA.fetch+Status+Distance.t.Status","fetch+Status+Distance.t.Status",347.193349866642,391.275285563359,0.45834,NA,21.17,0,2.578,3.945,0.045,0.031,0,0,0,0,1,0,0,0,1,1,0.751 73 | "NA","Status+Distance+org.by.Status",312.607228213057,357.982246907728,0.52627,NA,22.45,0,0,0,0.937,0.661,0,0,0,0,0,1,0,0,1,1,0.937 74 | "NA.sqrt.X4mm+Distance1","sqrt.X4mm+Distance",477.211361111149,521.093352614688,0.49295,NA,20.9,0,0,1.603,0.061,0.031,1,0,0,0,0,0,0,0,0,1,0.061 75 | "NA.sqrt.X4mm+fetch+Distance1","sqrt.X4mm+fetch+Distance",477.40026937098,521.391999648418,0.48872,NA,21.06,0,0.189,1.902,0.056,0.027,1,0,0,0,1,0,0,0,0,1,0.117 76 | "NA.sqrt.X1mm+lobster+Distance1","sqrt.X1mm+lobster+Distance",477.515528727141,519.489945455275,0.44359,NA,19.05,0,0.304,0,0.053,0.069,0,0,1,0,0,0,0,1,0,1,0.17 77 | "NA.sqrt.X1mm+Distance1","sqrt.X1mm+Distance",477.877695247619,519.889490244463,0.45414,NA,19.11,0,0.666,0.4,0.044,0.056,0,0,1,0,0,0,0,0,0,1,0.214 78 | "NA.sqrt.X1mm+snapper+Distance1","sqrt.X1mm+snapper+Distance",478.147611241407,520.250863032048,0.44695,NA,19.14,0,0.936,0.761,0.038,0.047,0,0,1,0,0,0,1,0,0,1,0.252 79 | "NA.sqrt.X1mm+Status+Distance1","sqrt.X1mm+Status+Distance",478.21208595992,520.414163799793,0.45348,NA,19.28,0,1.001,0.924,0.037,0.043,0,0,1,0,0,0,0,0,1,1,0.289 80 | "NA.sqrt.X4mm+lobster1","sqrt.X4mm+lobster",479.079400932741,521.580519673982,0.46683,NA,19.54,0,1.868,2.091,0.024,0.024,1,0,0,0,0,0,0,1,0,0,0.313 81 | "NA.sqrt.X4mm+sqrt.X500um+lobster1","sqrt.X4mm+sqrt.X500um+lobster",479.090826711357,521.925136714939,0.4619,NA,19.84,0,1.879,2.435,0.024,0.02,1,0,0,1,0,0,0,1,0,0,0.337 82 | "NA.sqrt.X4mm+sqrt.X500um1","sqrt.X4mm+sqrt.X500um",479.302765563719,522.156893109892,0.47359,NA,19.9,0,2.091,2.667,0.022,0.018,1,0,0,1,0,0,0,0,0,0,0.359 83 | "NA.sqrt.X4mm+sqrt.X500um+snapper1","sqrt.X4mm+sqrt.X500um+snapper",479.352501207602,522.235248787769,0.46417,NA,19.87,0,2.141,2.745,0.021,0.017,1,0,0,1,0,0,1,0,0,0,0.38 84 | "NA.sqrt.X4mm+snapper1","sqrt.X4mm+snapper",479.362901330117,521.935946256357,0.47143,NA,19.62,0,2.152,2.446,0.021,0.02,1,0,0,0,0,0,1,0,0,0,0.401 85 | "NA.sqrt.X4mm1","sqrt.X4mm",479.37301432298,521.939049096695,0.48102,NA,19.66,0,2.162,2.449,0.021,0.02,1,0,0,0,0,0,0,0,0,0,0.422 86 | "NA.sqrt.X500um+Distance1","sqrt.X500um+Distance",479.465024386517,521.729452923577,0.4755,NA,19.31,0,2.254,2.24,0.02,0.023,0,0,0,1,0,0,0,0,0,1,0.442 87 | "NA.Status+Distance+sqrt.X1mm.by.Status1","Status+Distance+sqrt.X1mm.by.Status",479.472598620822,522.616963093334,0.4592,NA,20.19,0,2.261,3.127,0.02,0.014,0,0,1,0,0,0,0,0,1,1,0.462 88 | "NA.sqrt.X500um+snapper+Distance2","sqrt.X500um+snapper+Distance",479.636303796396,521.946173965538,0.46642,NA,19.29,0,2.425,2.456,0.018,0.02,0,0,0,1,0,0,1,0,0,1,0.48 89 | "NA.sqrt.X4mm+sqrt.X500um+Status1","sqrt.X4mm+sqrt.X500um+Status",479.642217597407,522.676767371616,0.47183,NA,20.07,0,2.431,3.187,0.018,0.014,1,0,0,1,0,0,0,0,1,0,0.498 90 | "NA.sqrt.X4mm+fetch+lobster1","sqrt.X4mm+fetch+lobster",479.672960029634,522.362372822011,0.45759,NA,19.68,0,2.462,2.872,0.018,0.016,1,0,0,0,1,0,0,1,0,0,0.516 91 | "NA.sqrt.X4mm+Status1","sqrt.X4mm+Status",479.709795359168,522.451899096407,0.47796,NA,19.82,0,2.498,2.962,0.018,0.016,1,0,0,0,0,0,0,0,1,0,0.534 92 | "NA.sqrt.X2mm+lobster+Distance1","sqrt.X2mm+lobster+Distance",479.787801405757,522.247872517036,0.45333,NA,19.53,0,2.576,2.758,0.017,0.017,0,1,0,0,0,0,0,1,0,1,0.551 93 | "NA.sqrt.X4mm+fetch1","sqrt.X4mm+fetch",479.800250113978,522.568934146593,0.47558,NA,19.81,0,2.589,3.079,0.017,0.015,1,0,0,0,1,0,0,0,0,0,0.568 94 | "NA.sqrt.X500um+Status+Distance2","sqrt.X500um+Status+Distance",479.923091821053,522.415419936469,0.474,NA,19.51,0,2.712,2.925,0.016,0.016,0,0,0,1,0,0,0,0,1,1,0.584 95 | "NA.Distance1","Distance",479.97597674282,522.155984987439,0.48292,NA,19.27,0,2.765,2.666,0.015,0.018,0,0,0,0,0,0,0,0,0,1,0.599 96 | "NA.sqrt.X4mm+fetch+snapper1","sqrt.X4mm+fetch+snapper",479.990755372925,522.840505965131,0.46456,NA,19.84,0,2.779,3.351,0.015,0.013,1,0,0,0,1,0,1,0,0,0,0.614 97 | "NA.snapper+Distance1","snapper+Distance",480.105762810659,522.318054806322,0.47393,NA,19.23,0,2.894,2.828,0.014,0.017,0,0,0,0,0,0,1,0,0,1,0.628 98 | "NA.fetch+lobster+Distance2","fetch+lobster+Distance",480.175879532209,522.470570697533,0.4583,NA,19.26,0,2.965,2.981,0.014,0.016,0,0,0,0,1,0,0,1,0,1,0.642 99 | "NA.sqrt.X4mm+fetch+Status1","sqrt.X4mm+fetch+Status",480.187262319785,523.108439277508,0.4709,NA,19.93,0,2.976,3.618,0.014,0.011,1,0,0,0,1,0,0,0,1,0,0.656 100 | -------------------------------------------------------------------------------- /case_study1_dataset.csv: -------------------------------------------------------------------------------- 1 | "","ZONE","site","depth","SA","complexity","rugosity","LC","HC","macro","SCORE1","SCORE2","Herbivore.abundance","Invertivore.abundance","Piscivore.abundance","Planktivore.abundance","Herbivore.biomass","Invertivore.biomass","Piscivore.biomass","Planktivore.biomass","sqrt.Herbivore.abundance","sqrt.Invertivore.abundance","sqrt.Piscivore.abundance","sqrt.Planktivore.abundance","log.Herbivore.biomass","log.Invertivore.biomass","log.Piscivore.biomass","log.Planktivore.biomass" 2 | "1","FISHED","MESA",3.2,321.8344412,3.5,1.643835616,0,0,0,1.22,-0.00782,17.9999999989878,53.9999999948629,29.9999999994341,288.000000051688,1221.26602510691,4724.72393894517,3364.99517423276,10444.5473480415,4.242640687,7.348469228,5.477225575,16.97056275,3.08716574,3.674468348,3.527113489,4.018931202 3 | "2","FISHED","MESA",3.9,309.1074592,4.5,1.714285714,20,16,2,2.44,-0.00349,58.0000000020729,252.000000114692,66.000000005915,196,12321.3436673446,22065.5382834406,11102.265072064,2565.59869434395,7.615773106,15.87450787,8.124038405,14,4.090693317,4.343734208,4.045450708,3.409357969 4 | "3","FISHED","MESA",3.9,118.7198571,2.5,1.395348837,38,0,0,1.1,-1.59,22.0000000016564,27.0000000030488,1,122.000000062135,9475.76226484881,16687.4200701221,65.0320602805228,2025.8221229092,4.69041576,5.196152423,1,11.04536102,3.976659986,4.222415223,1.819754848,3.306815636 5 | "4","FISHED","MESA",1.7,252.3626052,1,1.045296167,0,0,67,-2.72,-0.157,3.00000000149345,12.9999999966541,4,0,473.192678260718,633.419949460574,437.724781145413,0,1.732050808,3.605551275,2,0,2.675954844,2.802376831,2.642192166,0 6 | "5","FISHED","MESA",3.2,132.359942,0.5,1.052631579,0,0,69,-2.96,-0.116,0,4,0,0,0,445.451484109656,0,0,0,2,0,0,0,2.649774271,0,0 7 | "6","SANCTUARY","MANGROVE",2.1,149.2458084,3,1.967213115,4,6,6,1.46,0.242,84.9999999945994,210.000000110441,8.00000000143577,80.000000000015,8672.12624549027,15458.4671937023,232.574848591353,3324.79221972758,9.219544457,14.49137675,2.828427125,8.94427191,3.938175668,4.189194522,2.368426076,3.521895113 8 | "7","SANCTUARY","MANGROVE",2.5,344.8978579,3.5,1.538461538,24,2,24,1.06,-1.02,45.9999999983008,145.999999913133,64.999999995186,286.000000159382,4438.89516852428,21960.4129880093,7486.25226698156,6996.1604223524,6.782329983,12.08304597,8.062257748,16.91153453,3.647372716,4.341660279,3.874322466,3.844921831 9 | "8","SANCTUARY","MANGROVE",2.9,61.93655062,2,1.363636364,4,1,20,-0.276,-0.104,19.0000000040043,25,1,46.9999999945012,461.300564775596,1097.15729016117,43.1888305313141,352.198147445669,4.358898944,5,1,6.8556546,2.664924424,3.040664549,1.645312508,2.548018417 10 | "9","SANCTUARY","MANGROVE",3.1,380.2003416,1,1.2,2,6,75,-2.24,0.135,34.0000000018041,64,1.99999999894473,64,589.295661097885,3415.47996290325,11.0338228236699,212.875592166239,5.830951895,8,1.414213562,8,2.771069591,3.533578878,1.080403613,2.330161225 11 | "10","SANCTUARY","MANGROVE",3.7,188.8987909,2.5,1.62601626,48.6,0,8,1.55,-2.03,14.0000000016917,50.0000000019025,1,71.9999999959513,1116.00484533771,5970.92133010013,251.552148224307,438.826832681203,3.741657387,7.071067812,1,8.485281374,3.048055057,3.776114078,2.402351067,2.643281721 12 | "11","SANCTUARY","MANGROVE",4.5,436.6838093,3.5,2.181818182,3,5.6,18.4,1.59,0.191,47.9999999961824,90.999999996767,53.9999999948629,208.999999861187,5330.11754102872,14939.5596232971,7528.88225191989,3271.76466819422,6.92820323,9.539392014,7.348469228,14.45683229,3.726818258,4.174366865,3.876788185,3.514914778 13 | "12","FISHED","NTH MANGROVE",3.5,83.51676336,2.5,1.846153846,0,80,0,2.63,4.87,12.9999999966541,66.000000005915,19.0000000040043,550.000000041409,659.490008117319,4364.26505685227,1542.96281314696,4834.14268908772,3.605551275,8.124038405,4.358898944,23.4520788,2.819866252,3.640010619,3.188636836,3.684409295 14 | "13","SANCTUARY","MANGROVE",3.1,54.72277731,3.5,1.363636364,34,0,9.6,1.2,-1.55,29.9999999994341,44.0000000038367,1.99999999894473,75.0000000026953,13663.612011845,15135.2385961678,303.180173308558,1800.77051231799,5.477225575,6.633249581,1.414213562,8.660254038,4.135597305,4.180017965,2.483130903,3.255699475 15 | "14","FISHED","NTH MANGROVE",3,88.19923016,2.5,1.237113402,0,5.6,0,0.0904,0.336,38.0000000003825,88.0000000066255,4,135.000000032016,19267.4436830695,14044.6643873359,918.49897616444,1588.88456454855,6.164414003,9.38083152,2,11.61895004,4.284846638,4.147542287,2.96355125,3.201365593 16 | "15","FISHED","NTH MANGROVE",3.3,110.4295177,2,1.239669421,3.6,14,4,0.0275,0.714,17.9999999989878,50.0000000019025,14.0000000016917,136.000000007216,1277.2106831054,6743.62664649807,4581.36199105927,4630.97668810655,4.242640687,7.071067812,3.741657387,11.66190379,3.106602443,3.828957914,3.661089394,3.665766365 17 | "16","FISHED","NTH MANGROVE",4.1,62.63568974,1,1.149425287,0,40,0,-0.138,2.49,10.9999999976425,27.0000000030488,1.99999999894473,14.0000000016917,142.248235457368,603.138082755167,425.9955087239,40.9037181530545,3.31662479,5.196152423,1.414213562,3.741657387,2.156089281,2.781136213,2.630423307,1.62225256 18 | "17","FISHED","MESA",2,68.95717424,2,1.357466063,7,3,17,-0.125,-0.104,19.0000000040043,29.9999999994341,4.99999999776487,8.00000000143577,345.390492278582,838.23684417519,741.730954141442,77.1578706754258,4.358898944,5.477225575,2.236067977,2.828427125,2.539565963,2.923884542,2.870831524,1.892972719 19 | "18","FISHED","MESA",3,136.8339956,3.5,1.428571429,40,14,2,1.89,-0.935,52.0000000010387,66.000000005915,59.0000000020185,623.999999820464,2094.78040741202,4639.48603445052,8737.27902094003,8570.1545872064,7.211102551,8.124038405,7.681145748,24.97999199,3.321345776,3.66656347,3.941425908,3.933039328 20 | "19","FISHED","MESA",2,517.593683,0,1.034482759,0,0,22,-2.24,0.0912,0,10.9999999976425,0,1,0,584.226700171777,0,2.44727623961774,0,3.31662479,0,1,0,2.767324132,0,0.537476086 21 | "20","FISHED","MESA",2.1,405.5879967,0,1.094890511,0,5,74,-3.05,0.224,6.00000000106221,14.0000000016917,4.99999999776487,10.9999999976425,1658.89489016528,5272.54523962138,1248.24508948688,120.638318520431,2.449489743,3.741657387,2.236067977,3.31662479,3.220080588,3.722102676,3.096647651,2.085070408 22 | "21","FISHED","MESA",3.2,136.1109364,4,1.769911504,48,0,0,2.58,-2.09,38.999999995024,64.999999995186,3.00000000149345,241.00000011612,7390.80169077023,3966.23542238732,444.035930835147,5894.02444050308,6.244997998,8.062257748,1.732050808,15.5241747,3.868750307,3.598487973,2.648395076,3.77048561 23 | "22","SANCTUARY","MANDU",2.1,164.0462845,1,1.158301158,0,6,46,-1.78,0.312,31.9999999944294,31.0000000018928,4.99999999776487,22.9999999970005,1772.46304019201,1332.31204960917,577.823778572901,121.797628025761,5.656854249,5.567764363,2.236067977,4.795831523,3.248822142,3.124931804,2.762546364,2.089189978 24 | "23","SANCTUARY","MANDU",2.2,257.4920567,3,1.5,28,4,34,0.673,-1.07,49,98.9999999986826,17.9999999989878,128.999999963643,12806.4183252856,11206.835368805,787.674263691376,1123.24098044933,7,9.949874371,4.242640687,11.35781669,4.107461595,4.049521743,2.896897669,3.050859412 25 | "24","SANCTUARY","MANDU",1.7,296.1813284,3,1.463414634,80,0,0,2.3,-3.42,47.9999999961824,45.9999999983008,1.99999999894473,28.9999999985513,8343.71296988854,3698.10591098611,1145.98380800491,381.785065256269,6.92820323,6.782329983,1.414213562,5.385164807,3.921411403,3.568096766,3.059557287,2.582954985 26 | "25","SANCTUARY","MANDU",1.4,288.8181012,0,1.071428571,0,0,26,-2.19,0.0903,3.00000000149345,17.9999999989878,3.00000000149345,1,292.047151314622,191.013233414674,688.734816657813,2.09306177591751,1.732050808,4.242640687,1.732050808,1,2.466937504,2.283331161,2.838682149,0.490388594 27 | "26","FISHED","NTH MANDU",3.2,191.6852386,3.5,1.518987342,26,6,4,1.57,-0.8,53.9999999948629,162.999999877341,38.0000000003825,279.999999977192,5886.49529405029,9105.21988773141,72484.779399963,7022.7475885908,7.348469228,12.76714533,6.164414003,16.73320053,3.769930573,3.959338133,4.860252813,3.846568896 28 | "27","FISHED","MESA",2.1,115.5687763,0.5,1.081081081,0,0,22,-1.85,0.062,3.00000000149345,27.0000000030488,4,0,351.296360825305,529.287674609995,287.208804528759,0,1.732050808,5.196152423,2,0,2.546908157,2.724511533,2.459707244,0 29 | "28","SANCTUARY","JURABI",3.8,167.1399663,3,1.41509434,18,6,0,1.09,-0.417,20.0000000000038,38.999999995024,4.99999999776487,0,2941.87591052794,4535.50384178282,451.993675891001,0,4.472135955,6.244997998,2.236067977,0,3.46877195,3.656721283,2.656092139,0 30 | "29","SANCTUARY","JURABI",3.7,235.3277637,3.5,1.284796574,0,28,0,1.1,1.59,42.9999999960393,67.999999996119,6.00000000106221,40.9999999944568,8358.85011541856,4981.38079652407,1131.67633788632,1953.9533476594,6.557438524,8.246211251,2.449489743,6.403124237,3.922198491,3.697436917,3.054105828,3.291136398 31 | "30","SANCTUARY","JURABI",3.6,224.1610093,2,1.086956522,0,0,52,-1.81,-0.181,20.0000000000038,27.0000000030488,4.99999999776487,41.9999999947135,2130.57399377384,6023.06223580602,1457.16413793745,558.600000232206,4.472135955,5.196152423,2.236067977,6.480740698,3.328700413,3.77988945,3.163806413,2.747877706 32 | "31","SANCTUARY","JURABI",3.4,475.0149746,1,1.140684411,0,0,34,-1.69,-0.00734,1.99999999894473,27.0000000030488,9,75.9999999985817,434.440478951229,3860.00801349385,2670.89568748267,255.659033788354,1.414213562,5.196152423,3,8.717797887,2.638928799,3.586700703,3.426819499,2.409356555 33 | "32","SANCTUARY","JURABI",4.1,100.4914679,2,1.310043668,6,2,0,0.0951,-0.0707,10.9999999976425,9,1,22.0000000016564,693.313160088093,371.185001733075,124.827796125472,501.382199501752,3.31662479,3,1,4.69041576,2.841555397,2.570758868,2.09977659,2.701034243 34 | "33","SANCTUARY","JURABI",3.6,109.6232002,1.5,1.181102362,0,0,22,-1.09,0.0016,12.9999999966541,27.9999999986329,4,11.9999999990456,1109.14862663588,3050.82737963711,813.883554092825,41.7515852285687,3.605551275,5.291502622,2,3.464101615,3.045381126,3.484559965,2.911095553,1.630952223 35 | "34","FISHED","MESA",3.7,74.20490393,3,1.276595745,6,4,4,0.415,-0.0661,27.0000000030488,44.9999999933003,11.9999999990456,262.000000121766,2371.21813143295,2835.56621556444,1950.37885187333,8509.00366260813,5.196152423,6.708203932,3.464101615,16.18641406,3.375154621,3.452792926,3.290341594,3.929929747 36 | "35","FISHED","MESA",2.9,135.4058951,4,1.304347826,8,10,0,1.17,0.134,62.999999996924,53.9999999948629,6.00000000106221,194.000000078441,9025.61898066485,3144.97596988605,816.538835334374,2049.73958218322,7.937253933,7.348469228,2.449489743,13.92838828,3.955525111,3.497755401,2.912508392,3.311910514 37 | "36","FISHED","MESA",2.1,98.84527186,0.5,1.034482759,0,0,44,-2.49,-0.0333,6.00000000106221,12.9999999966541,29.9999999994341,3.00000000149345,89.9983297426225,66.9613562267837,118.567373683093,11.7011372766485,2.449489743,3.605551275,5.477225575,1.732050808,1.959033421,1.832262037,2.07761269,1.10384261 38 | "37","SANCTUARY","MANGROVE",2.6,32.99946287,3,1.176470588,6,2,10,-0.0195,-0.233,33.0000000053077,38.0000000003825,4.99999999776487,10.9999999976425,4690.14048602965,2915.73752467281,317.044031571955,272.158654598455,5.744562647,6.164414003,2.236067977,3.31662479,3.671278439,3.464897349,2.50248725,2.436414965 39 | "38","SANCTUARY","MANGROVE",1.8,71.59080261,0,1.008403361,0,0,30,-2.51,0.0526,0,6.00000000106221,0,0,0,83.7984527299636,0,0,0,2.449489743,0,0,0,1.928387928,0,0 40 | "39","SANCTUARY","MANGROVE",2.2,76.09548083,2.5,1.333333333,12,2,24,-0.026,-0.454,29.9999999994341,25,11.9999999990456,131.999999929318,4977.87089597978,1073.80203241903,1507.94541926123,3190.79295640672,5.477225575,5,3.464101615,11.48912529,3.697130865,3.031328479,3.178673531,3.504034712 41 | "40","SANCTUARY","MANGROVE",2.2,159.2629172,3.5,1.518987342,8,0,2,1.14,-0.378,38.0000000003825,70.999999997028,11.9999999990456,199.000000009427,7806.16908018198,4955.72914488236,227.33292967184,3940.78029384707,6.164414003,8.426149773,3.464101615,14.10673598,3.892493585,3.695195188,2.358568549,3.595692414 42 | "41","SANCTUARY","MANGROVE",1.8,339.8302956,4,1.428571429,0,12,8,1.14,0.594,93.0000000001359,277.000000096756,45.9999999983008,204.99999990618,10043.7039914905,13920.1687517736,6945.40183915422,5342.95514265709,9.643650761,16.64331698,6.782329983,14.31782106,4.001937143,4.143675698,3.841759903,3.727862804 43 | "42","FISHED","NTH MANGROVE",3.6,51.51412119,2,1.071428571,0,4,70,-2.17,-0.0128,3.00000000149345,46.9999999945012,4,11.9999999990456,915.299572616541,1047.94820230611,412.032981201455,157.707413177998,1.732050808,6.8556546,2,3.464101615,2.962037484,3.020754043,2.615984732,2.200597213 44 | "43","FISHED","NTH MANGROVE",2.7,94.46147955,3,1.428571429,0,0,16,0.288,-0.0558,27.0000000030488,54.9999999985811,3.00000000149345,88.999999998932,3901.58471280347,15067.2449674418,389.98774840657,2751.08832530569,5.196152423,7.416198487,1.732050808,9.433981132,3.591352339,4.178062672,2.592163149,3.439662368 45 | "44","FISHED","NTH MANGROVE",2.5,248.5939142,3,1.538461538,0,0,58,-0.418,-0.186,29.9999999994341,67.999999996119,6.00000000106221,85.999999990806,7624.26587315595,5038.4015706263,580.602070580925,3185.03727120538,5.477225575,8.246211251,2.449489743,9.273618495,3.882254991,3.702378967,2.764625944,3.503250852 46 | "45","FISHED","NTH MANGROVE",2,90.19713362,0,1.034482759,0,0,62,-3.1,-0.0516,0,9,0,0,0,16.5242147262598,0,0,0,3,0,0,0,1.243638566,0,0 47 | "46","SANCTUARY","MANDU",1.8,23.64948303,1.5,1.363636364,0,0,52,-1.29,-0.0599,11.9999999990456,21.0000000004047,1,1.99999999894473,697.541000682387,618.24909420182,27.1296416744342,4.18612355195873,3.464101615,4.582575695,1,1.414213562,2.844191902,2.79186538,1.4491642,0.714842859 48 | "47","SANCTUARY","MANDU",2.4,142.3711518,2.5,1.428571429,7,8,8,0.537,0.194,28.9999999985513,34.0000000018041,1,50.0000000019025,1032.75346200403,2020.89417928879,6.43590848164176,154.957566496407,5.385164807,5.830951895,1,7.071067812,3.014416977,3.305758422,0.871334036,2.19300645 49 | "48","SANCTUARY","MANDU",2,146.1088593,3.5,2.068965517,0,30,0,2.31,1.83,69.000000001361,42.9999999960393,4,33.0000000053077,12744.969678556,5192.59999825238,1008.03050727283,234.478300093222,8.306623863,6.557438524,2,5.744562647,4.105372881,3.715468498,3.003904297,2.371950892 50 | "49","FISHED","NTH MANDU",2.1,131.5907204,2.5,1.463414634,0,4,30,-0.0907,0.185,46.9999999945012,80.000000000015,9,14.0000000016917,5507.43484669658,2388.71761036502,1052.78118479028,129.659281903241,6.8556546,8.94427191,3,3.741657387,3.741028217,3.378346584,3.02275044,2.116140267 51 | "50","FISHED","NTH MANDU",2.1,245.8616162,3.5,1.621621622,0,14,4,1.38,0.807,98.0000000076886,169,24.0000000042488,90.0000000093893,16834.0386972312,7608.5233146435,2359.76798527546,1162.4897161534,9.899494937,13,4.898979486,9.486832981,4.226214119,3.881357452,3.373053307,3.065762549 52 | "51","FISHED","NTH MANDU",1.8,104.9810693,0.5,1.025641026,0,0,42,-2.48,-0.0295,1,8.00000000143577,0,0,534.622235802582,387.181562667963,0,0,1,2.828427125,0,0,2.728858598,2.589034904,0,0 53 | "52","SANCTUARY","JURABI",3.5,68.67859444,3.5,1.578947368,6,2,0,1.28,-0.156,44.0000000038367,25,3.00000000149345,3.00000000149345,9472.66874115594,6984.73577381751,741.409370844327,123.156957059698,6.633249581,5,1.732050808,1.732050808,3.976518195,3.844212155,2.870643445,2.09397106 54 | "53","SANCTUARY","JURABI",3.1,93.17856669,2.5,1.304347826,24,0,4,0.539,-1.02,45.9999999983008,47.9999999961824,34.9999999988213,601.999999864043,13787.904793807,8292.37163449782,4674.57175060516,6934.96632630571,6.782329983,6.92820323,5.916079783,24.53568829,4.139529773,3.918731127,3.669834726,3.841106976 55 | "54","SANCTUARY","JURABI",3.9,16.65044968,2,1.25,6,1,0,-0.0707,-0.145,8.00000000143577,19.0000000040043,1.99999999894473,4,3129.13640765179,1162.3392579337,756.544265505118,121.333229805774,2.828427125,4.358898944,1.414213562,2,3.495563264,3.065706384,2.879408015,2.087544442 56 | "55","SANCTUARY","MANDU",2.2,35.70542831,2.5,1.666666667,0,32,0,1.44,1.99,29.9999999994341,28.9999999985513,4,44.9999999933003,4958.2708627735,137.228795284991,1138.81817041535,212.80694248691,5.477225575,5.385164807,2,6.708203932,3.695417829,2.140598523,3.056835576,2.330021803 57 | "56","SANCTUARY","MANDU",1.8,189.2793098,3.5,1.538461538,16,12,0,1.61,0.00253,34.9999999988213,67.999999996119,9.99999999893508,54.9999999985811,2962.86207064677,7473.90244408142,793.142385324529,718.255013860871,5.916079783,8.246211251,3.16227766,7.416198487,3.471857989,3.873605529,2.899898376,2.856882898 58 | "57","SANCTUARY","MANDU",2.1,125.4875385,0.5,1.090909091,0,0,58,-2.59,-0.0631,1.99999999894473,6.99999999965822,1.99999999894473,6.00000000106221,545.637876961523,848.035942978674,239.717132884047,29.6675114433664,1.414213562,2.645751311,1.414213562,2.449489743,2.737699721,2.928926076,2.381507002,1.486678536 59 | "58","SANCTUARY","MANDU",1.7,74.33842479,0.5,1.111111111,0,4,30,-1.84,0.281,1.99999999894473,8.00000000143577,3.00000000149345,1,288.63226795177,933.93018378085,632.93370505313,1.34797077510078,1.414213562,2.828427125,1.732050808,1,2.461846945,2.970779181,2.802043843,0.370692687 60 | "59","SANCTUARY","MANDU",2.4,121.483438,3,1.578947368,0,22,0,1.34,1.34,12.9999999966541,27.0000000030488,4,27.0000000030488,1345.25980702884,3453.08026206883,32.6877972019976,177.364699709445,3.605551275,5.196152423,2,5.196152423,3.12912888,3.538332425,1.527472614,2.251308907 61 | "60","FISHED","NTH MANGROVE",2.7,22.45597068,1.5,1.071428571,0,0,30,-1.61,-0.0618,0,9.99999999893508,1,33.0000000053077,0,74.9712503205486,7.53740737659967,299.910347347852,0,3.16227766,1,5.744562647,0,1.880649274,0.931326005,2.478437122 62 | "61","FISHED","NTH MANGROVE",4,128.1922721,3.5,1.538461538,20,24,0,1.93,0.544,24.0000000042488,54.9999999985811,9.99999999893508,149.999999904081,4581.57478363159,9062.73501248728,2176.89212726392,552.800944380725,4.898979486,7.416198487,3.16227766,12.24744871,3.661109561,3.9573072,3.338036365,2.743353692 63 | "62","FISHED","NTH MANGROVE",3.7,323.6801358,3,1.463414634,0,2,0,0.738,0.127,61.0000000014581,153.000000077853,228.999999987241,105.999999979676,15379.4341977427,20539.1075369777,50338.4136952294,4229.13727321757,7.810249676,12.36931688,15.13274595,10.29563014,4.186968596,4.312602713,4.701908153,3.626354461 64 | "63","FISHED","NTH MANGROVE",3.5,181.7703167,3,1.714285714,0,6,0,1.22,0.405,53.9999999948629,71.9999999959513,6.99999999965822,106.999999942309,15925.8484278544,2805.71612671661,560.008908941227,1251.17842606241,7.348469228,8.485281374,2.645751311,10.34408043,4.202129847,3.44819849,2.748969758,3.097666217 65 | "64","FISHED","NTH MANDU",1.8,178.8794146,1.5,1.2,0,0,64,-1.94,-0.143,9.99999999893508,31.9999999944294,9,22.0000000016564,1049.28925149044,2754.78323024882,724.264850223222,489.503659648725,3.16227766,5.656854249,3,4.69041576,3.021308921,3.440245053,2.86049663,2.690642252 66 | "65","FISHED","NTH MANDU",2.1,106.6574218,3,1.333333333,0,0,36,-0.342,-0.147,39.9999999957403,44.0000000038367,11.9999999990456,61.0000000014581,3333.30344396718,1789.92491780471,251.462538666738,603.152295580001,6.32455532,6.633249581,3.464101615,7.810249676,3.523005121,3.253077379,2.402196945,2.78114643 67 | "66","FISHED","NTH MANDU",2.2,247.9225686,3,1.463414634,4,10,0,0.978,0.431,70.999999997028,54.9999999985811,1.99999999894473,217.999999993108,8010.401455417,4448.31140645917,449.248587454151,1083.16794353401,8.426149773,7.416198487,1.414213562,14.76482306,3.903708495,3.648292803,2.653452359,3.035096562 68 | "67","FISHED","NTH MANDU",2.9,51.58277782,3,1.875,4,0,0,1.38,-0.103,20.0000000000038,24.0000000042488,8.00000000143577,105.000000082804,1099.8229191416,1600.51802504207,896.055652280181,2111.21285779557,4.472135955,4.898979486,2.828427125,10.24695077,3.041717463,3.204531831,2.952819387,3.324737682 69 | "68","FISHED","NTH MANDU",3.1,385.0423834,4,1.363636364,22,0,34,0.653,-1.17,85.999999990806,133.999999935402,11.9999999990456,201.999999899036,19124.6324326281,144429.207436687,1233.68805619499,4373.69900130873,9.273618495,11.5758369,3.464101615,14.2126704,4.281615805,5.159658035,3.091557247,3.640948177 70 | -------------------------------------------------------------------------------- /case_study2_soft_sediment.R: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Australian Institute of Marine Science 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # A simple function for full subsets multiple regression in ecology with R 16 | # 17 | # R. Fisher 18 | # S.K. Wilson 19 | # S.M. Sin 20 | # A.C. Lee 21 | # Dr Tim J. Langlois 22 | 23 | # Reproducible example for: 24 | # Case Study 2: The role of large reef-associated predators in structuring adjacent soft-sediment communities 25 | 26 | # A re-analysis of data presented in: 27 | # Langlois, T. J., M. J. Anderson, and R. C. Babcock. 2005. Reef-associated predators influence adjacent soft-sediment communities. Ecology 86: 1508–1519. 28 | 29 | # note this example was updated on the 11th Oct 2018 to demonstrate useage of the replacement functions 30 | # generate.model.set and fit.model.set that have now superced full.subsets.gam in package FSSgam 31 | # Between them these functions carry out the same analysis, take the same arguments and return the same 32 | # outputs as full.subsets.gam with the only difference being that the model set generation and model 33 | # fitting procedures are separated into two steps. This was done to make the function easier to use, 34 | # because the model set can be interrogated, along with the correlation matrix of the predictors before model 35 | # fitting is even attempted. 36 | 37 | # Script information---- 38 | 39 | # Part 1-FSS modeling---- 40 | # This script is designed to work with long format data - where response variables are stacked one upon each other (see http://tidyr.tidyverse.org/) 41 | # There are two random factors, Site and NTR location 42 | # We have used a Tweedie error distribution to account for the high occurence of zero values in the dataset. 43 | # We have implemented the ramdom effects and Tweedie error distribution using the mgcv() package 44 | 45 | # Part 2 - custom plot of importance scores---- 46 | # using ggplot2() 47 | 48 | # Part 3 - plots of the most parsimonious models---- 49 | # here we use plots of the raw response variables and fitted relationships - to allow for the plotting of interactions between continous predictor variables and factors with levels again using ggplot2() 50 | 51 | # Part 1-FSS modeling---- 52 | 53 | # librarys---- 54 | detach("package:plyr", unload=TRUE)#will error - don't worry 55 | library(tidyr) 56 | library(dplyr) 57 | options(dplyr.width = Inf) #enables head() to display all coloums 58 | library(mgcv) 59 | library(MuMIn) 60 | library(car) 61 | library(doBy) 62 | library(gplots) 63 | library(RColorBrewer) 64 | library(doParallel) #this can removed? 65 | library(doSNOW) 66 | library(gamm4) 67 | library(RCurl) #needed to download data from GitHub 68 | 69 | rm(list=ls()) 70 | 71 | 72 | # install package---- 73 | # devtools::install_github("beckyfisher/FSSgam_package") #run once 74 | library(FSSgam) 75 | 76 | # Bring in and format the data---- 77 | name<-"clams" 78 | 79 | # Load the dataset - from github 80 | 81 | download.file("https://raw.githubusercontent.com/beckyfisher/FSSgam/master/case_study2_dataset.csv", destfile = "/tmp/c2dat.csv") 82 | dat <-read.csv("/tmp/c2dat.csv")%>% 83 | 84 | rename(response=Abundance)%>% 85 | # Transform variables 86 | mutate(sqrt.X4mm=sqrt(X4mm))%>% 87 | mutate(sqrt.X2mm=sqrt(X2mm))%>% 88 | mutate(sqrt.X1mm=sqrt(X1mm))%>% 89 | mutate(sqrt.X500um=sqrt(X500um))%>% 90 | na.omit()%>% 91 | glimpse() 92 | 93 | 94 | 95 | 96 | # Set predictor variables--- 97 | pred.vars=c("depth","X4mm","X2mm","X1mm","X500um","X250um","X125um","X63um", 98 | "fetch","org","snapper","lobster") 99 | 100 | # predictor variables Removed at first pass--- 101 | # broad.Sponges and broad.Octocoral.Black and broad.Consolidated , "InPreds","BioTurb" are too rare 102 | 103 | # Check for correalation of predictor variables- remove anything highly correlated (>0.95)--- 104 | round(cor(dat[,pred.vars]),2) 105 | # nothing is highly correlated 106 | 107 | # Plot of likely transformations - thanks to Anna Cresswell for this loop! 108 | par(mfrow=c(3,2)) 109 | for (i in pred.vars) { 110 | x<-dat[ ,i] 111 | x = as.numeric(unlist(x)) 112 | hist((x))#Looks best 113 | plot((x),main = paste(i)) 114 | hist(sqrt(x)) 115 | plot(sqrt(x)) 116 | hist(log(x+1)) 117 | plot(log(x+1)) 118 | } 119 | 120 | # Review of individual predictors - we have to make sure they have an even distribution--- 121 | #If the data are squewed to low numbers try sqrt>log or if squewed to high numbers try ^2 of ^3 122 | # Decided that X4mm, X2mm, X1mm and X500um needed a sqrt transformation 123 | #Decided Depth, x63um, InPreds and BioTurb were not informative variables. 124 | 125 | # # Re-set the predictors for modeling---- 126 | pred.vars=c("sqrt.X4mm","sqrt.X2mm","sqrt.X1mm","sqrt.X500um", 127 | "fetch","org","snapper","lobster") 128 | 129 | # Check to make sure Response vector has not more than 80% zeros---- 130 | unique.vars=unique(as.character(dat$Taxa)) 131 | unique.vars.use=character() 132 | for(i in 1:length(unique.vars)){ 133 | temp.dat=dat[which(dat$Taxa==unique.vars[i]),] 134 | if(length(which(temp.dat$response==0))/nrow(temp.dat)<0.8){ 135 | unique.vars.use=c(unique.vars.use,unique.vars[i])} 136 | } 137 | unique.vars.use 138 | 139 | #"BDS" bivalve Dosina subrosea 140 | #"BMS" bivalve Myadora striata 141 | #"CPN" crustacean Pagrus novaezelandiae 142 | 143 | # Run the full subset model selection---- 144 | setwd("~/GitHub/FSSgam/case_study2_model_out") #Set wd for example outputs - will differ on your computer 145 | resp.vars=unique.vars.use 146 | use.dat=dat 147 | factor.vars=c("Status")# Status as a Factor with two levels 148 | out.all=list() 149 | var.imp=list() 150 | 151 | # Loop through the FSS function for each Taxa---- 152 | for(i in 1:length(resp.vars)){ 153 | use.dat=dat[which(dat$Taxa==resp.vars[i]),] 154 | 155 | Model1=gam(response~s(lobster,k=3,bs='cr')+ s(Location,Site,bs="re"), 156 | family=tw(), data=use.dat) 157 | 158 | model.set=generate.model.set(use.dat=use.dat, 159 | test.fit=Model1, 160 | pred.vars.cont=pred.vars, 161 | pred.vars.fact=factor.vars, 162 | linear.vars="Distance", 163 | k=3, 164 | null.terms="s(Location,Site,bs='re')") 165 | out.list=fit.model.set(model.set, 166 | max.models=600, 167 | parallel=T) 168 | names(out.list) 169 | 170 | out.list$failed.models # examine the list of failed models 171 | mod.table=out.list$mod.data.out # look at the model selection table 172 | mod.table=mod.table[order(mod.table$AICc),] 173 | mod.table$cumsum.wi=cumsum(mod.table$wi.AICc) 174 | out.i=mod.table[which(mod.table$delta.AICc<=3),] 175 | out.all=c(out.all,list(out.i)) 176 | # var.imp=c(var.imp,list(out.list$variable.importance$aic$variable.weights.raw)) #Either raw importance score 177 | var.imp=c(var.imp,list(out.list$variable.importance$aic$variable.weights.raw)) #Or importance score weighted by r2 178 | 179 | # plot the best models 180 | for(m in 1:nrow(out.i)){ 181 | best.model.name=as.character(out.i$modname[m]) 182 | 183 | png(file=paste(name,m,resp.vars[i],"mod_fits.png",sep="_")) 184 | if(best.model.name!="null"){ 185 | par(mfrow=c(3,1),mar=c(9,4,3,1)) 186 | best.model=out.list$success.models[[best.model.name]] 187 | plot(best.model,all.terms=T,pages=1,residuals=T,pch=16) 188 | mtext(side=2,text=resp.vars[i],outer=F)} 189 | dev.off() 190 | } 191 | } 192 | 193 | # Model fits and importance--- 194 | names(out.all)=resp.vars 195 | names(var.imp)=resp.vars 196 | all.mod.fits=do.call("rbind",out.all) 197 | all.var.imp=do.call("rbind",var.imp) 198 | write.csv(all.mod.fits[,-2],file=paste(name,"all.mod.fits.csv",sep="_")) 199 | write.csv(all.var.imp,file=paste(name,"all.var.imp.csv",sep="_")) 200 | 201 | # Generic importance plots- 202 | heatmap.2(all.var.imp,notecex=0.4, dendrogram ="none", 203 | col=colorRampPalette(c("white","yellow","red"))(10), 204 | trace="none",key.title = "",keysize=2, 205 | notecol="black",key=T, 206 | sepcolor = "black",margins=c(12,8), lhei=c(4,15),Rowv=FALSE,Colv=FALSE) 207 | 208 | 209 | # Part 2 - custom plot of importance scores---- 210 | 211 | # Load the importance score dataset produced above 212 | # dat.taxa <-read.csv(text=getURL("https://raw.githubusercontent.com/beckyfisher/FSSgam/master/case_study2_model_out/clams_all.var.imp.csv"))%>% #from github 213 | dat.taxa <-read.csv("clams_all.var.imp.csv")%>% #from local copy 214 | rename(resp.var=X)%>% 215 | gather(key=predictor,value=importance,2:ncol(.))%>% 216 | glimpse() 217 | 218 | 219 | # Plotting defaults---- 220 | library(ggplot2) 221 | # Theme- 222 | Theme1 <- 223 | theme( # use theme_get() to see available options 224 | panel.grid.major = element_blank(), 225 | panel.grid.minor = element_blank(), 226 | legend.background = element_rect(fill="white"), 227 | legend.key = element_blank(), # switch off the rectangle around symbols in the legend 228 | legend.text = element_text(size=8), 229 | legend.title = element_text(size=8, face="bold"), 230 | legend.position = "top", 231 | legend.direction="horizontal", 232 | text=element_text(size=10), 233 | strip.text.y = element_text(size = 10,angle = 0), 234 | axis.title.x=element_text(vjust=0.3, size=10), 235 | axis.title.y=element_text(vjust=0.6, angle=90, size=10), 236 | axis.text.x=element_text(size=10,angle = 90, hjust=1,vjust=0.5), 237 | axis.text.y=element_text(size=10,face="italic"), 238 | axis.line.x=element_line(colour="black", size=0.5,linetype='solid'), 239 | axis.line.y=element_line(colour="black", size=0.5,linetype='solid'), 240 | strip.background = element_blank()) 241 | 242 | 243 | # colour ramps- 244 | re <- colorRampPalette(c("mistyrose", "red2","darkred"))(200) 245 | 246 | # Labels- 247 | legend_title<-"Importance" 248 | 249 | # Annotations- 250 | dat.taxa.label<-dat.taxa%>% 251 | mutate(label=NA)%>% 252 | mutate(label=ifelse(predictor=="Distance"&resp.var=="BDS","X",ifelse(predictor=="Status"&resp.var=="BDS","X",ifelse(predictor=="sqrt.X500um"&resp.var=="BDS","X",label))))%>% 253 | mutate(label=ifelse(predictor=="lobster"&resp.var=="BMS","X",label))%>% 254 | mutate(label=ifelse(predictor=="sqrt.X4mm"&resp.var=="CPN","X",ifelse(predictor=="lobster"&resp.var=="CPN","X",label)))%>% 255 | glimpse() 256 | 257 | # Plot gg.importance.scores ---- 258 | gg.importance.scores <- ggplot(dat.taxa.label, aes(x=predictor,y=resp.var,fill=importance))+ 259 | geom_tile(show.legend=T) + 260 | scale_fill_gradientn(legend_title,colours=c("white", re), na.value = "grey98", 261 | limits = c(0, max(dat.taxa.label$importance)))+ 262 | scale_x_discrete(limits=c("Distance", 263 | "Status", 264 | "lobster", 265 | "snapper", 266 | "fetch", 267 | "org", 268 | "sqrt.X4mm", 269 | "sqrt.X2mm", 270 | "sqrt.X1mm", 271 | "sqrt.X500um"), 272 | labels=c( 273 | "Distance", 274 | "Status", 275 | "Lobster", 276 | "Snapper", 277 | "Fetch (km)", 278 | "Organic content", 279 | "Grain size: 4mm", 280 | " 2mm", 281 | " 1mm", 282 | " 500um" 283 | ))+ 284 | scale_y_discrete(limits = c("CPN", 285 | "BMS", 286 | "BDS"), 287 | labels=c("P. novizelandiae", 288 | "M. striata", 289 | "D. subrosea"))+ 290 | xlab(NULL)+ 291 | ylab(NULL)+ 292 | theme_classic()+ 293 | Theme1+ 294 | geom_text(aes(label=label)) 295 | gg.importance.scores 296 | 297 | 298 | # Part 3 - plots of the most parsimonious models---- 299 | 300 | ### now make a nice plot of the most interesting models----- 301 | library(gridExtra) 302 | library(grid) 303 | # Theme- 304 | Theme1 <- 305 | theme( # use theme_get() to see available options 306 | panel.grid.major = element_blank(), 307 | panel.grid.minor = element_blank(), 308 | # legend.background = element_rect(fill="white"), 309 | legend.background = element_blank(), 310 | legend.key = element_blank(), # switch off the rectangle around symbols in the legend 311 | legend.text = element_text(size=15), 312 | legend.title = element_blank(), 313 | legend.position = c(0.2, 0.8), 314 | text=element_text(size=15), 315 | strip.text.y = element_text(size = 15,angle = 0), 316 | axis.title.x=element_text(vjust=0.3, size=15), 317 | axis.title.y=element_text(vjust=0.6, angle=90, size=15), 318 | axis.text.x=element_text(size=15), 319 | axis.text.y=element_text(size=15), 320 | axis.line.x=element_line(colour="black", size=0.5,linetype='solid'), 321 | axis.line.y=element_line(colour="black", size=0.5,linetype='solid'), 322 | strip.background = element_blank()) 323 | 324 | 325 | # Bring in and format the raw data---- 326 | setwd("~/GitHub/FSSgam") 327 | name<-"clams" 328 | 329 | # Load the dataset - from github 330 | # dat <-read.csv(text=getURL("https://raw.githubusercontent.com/beckyfisher/FSSgam/master/case_study2_dataset.csv?token=AOSO6uyYhat9-Era46nbjALQpTydsTskks5ZY3vhwA%3D%3D"))%>% 331 | # Load the dataset - from local files 332 | dat <-read.csv("case_study2_dataset.csv")%>% 333 | rename(response=Abundance)%>% 334 | # Transform variables 335 | mutate(sqrt.X4mm=sqrt(X4mm))%>% 336 | mutate(sqrt.X2mm=sqrt(X2mm))%>% 337 | mutate(sqrt.X1mm=sqrt(X1mm))%>% 338 | mutate(sqrt.X500um=sqrt(X500um))%>% 339 | mutate(distance=as.numeric(as.character(Distance)))%>% 340 | na.omit()%>% 341 | glimpse() 342 | 343 | 344 | 345 | 346 | # Manually make the most parsimonious GAM models for each taxa ---- 347 | setwd("~/GitHub/FSSgam/case_study2_model_out") 348 | 349 | 350 | # MODEL Bivalve.Dosina.subrosea 500um + distance x Status ---- 351 | dat.bds<-dat%>%filter(Taxa=="BDS") 352 | gamm=gam(response~s(sqrt.X500um,k=3,bs='cr')+s(distance,k=1,bs='cr', by=Status)+ s(Location,Site,bs="re")+ Status, family=tw(),data=dat.bds) 353 | 354 | # predict - status from MODEL Bivalve.Dosina.subrosea---- 355 | mod<-gamm 356 | testdata <- expand.grid(distance=mean(mod$model$distance), 357 | sqrt.X500um=mean(mod$model$sqrt.X500um), 358 | Location=(mod$model$Location), 359 | Site=(mod$model$Site), 360 | Status = c("Fished","No-take"))%>% 361 | distinct()%>% 362 | glimpse() 363 | 364 | 365 | fits <- predict.gam(mod, newdata=testdata, type='response', se.fit=T) 366 | #head(fits,2) 367 | predicts.bds.status = testdata%>%data.frame(fits)%>% 368 | group_by(Status)%>% #only change here 369 | summarise(response=mean(fit),se.fit=mean(se.fit))%>% 370 | ungroup() 371 | write.csv(predicts.bds.status,"predicts.csv") #there is some BUG in dplyr - that this fixes 372 | predicts.bds.status<-read.csv("predicts.csv")%>% 373 | glimpse() 374 | 375 | # predict - distance.x.status from MODEL Bivalve.Dosina.subrosea---- 376 | mod<-gamm 377 | testdata <- expand.grid(distance=seq(min(dat$distance),max(dat$distance),length.out = 20), 378 | sqrt.X500um=mean(mod$model$sqrt.X500um), 379 | Location=(mod$model$Location), 380 | Site=(mod$model$Site), 381 | Status = c("Fished","No-take"))%>% 382 | distinct()%>% 383 | glimpse() 384 | 385 | fits <- predict.gam(mod, newdata=testdata, type='response', se.fit=T) 386 | #head(fits,2) 387 | predicts.bds.distance.x.status = testdata%>%data.frame(fits)%>% 388 | group_by(distance,Status)%>% #only change here 389 | # group_by(sqrt.X500um,Status)%>% #only change here 390 | summarise(response=mean(fit),se.fit=mean(se.fit))%>% 391 | ungroup() 392 | write.csv(predicts.bds.distance.x.status,"predicts.csv") #there is some BUG in dplyr - that this fixes 393 | predicts.bds.distance.x.status<-read.csv("predicts.csv")%>% 394 | glimpse() 395 | 396 | # predict 500um from MODEL Bivalve.Dosina.subrosea---- 397 | mod<-gamm 398 | testdata <- expand.grid(sqrt.X500um=seq(min(dat$sqrt.X500um),max(dat$sqrt.X500um),length.out = 20), 399 | distance=mean(mod$model$distance), 400 | Location=(mod$model$Location), 401 | Site=(mod$model$Site), 402 | Status = c("Fished","No-take"))%>% 403 | distinct()%>% 404 | glimpse() 405 | 406 | fits <- predict.gam(mod, newdata=testdata, type='response', se.fit=T) 407 | #head(fits,2) 408 | predicts.bds.500um = testdata%>%data.frame(fits)%>% 409 | group_by(sqrt.X500um)%>% #only change here 410 | # group_by(sqrt.X500um,Status)%>% #only change here 411 | summarise(response=mean(fit),se.fit=mean(se.fit))%>% 412 | ungroup() 413 | write.csv(predicts.bds.500um,"predicts.csv") #there is some BUG in dplyr - that this fixes 414 | predicts.bds.500um<-read.csv("predicts.csv")%>% 415 | glimpse() 416 | 417 | # MODEL Bivalve.Myadora.striata Lobster---- 418 | dat.bms<-dat%>%filter(Taxa=="BMS") 419 | head(dat.bms,2) 420 | gamm=gam(response~s(lobster,k=3,bs='cr')+ s(Location,Site,bs="re"), family=tw(),data=dat.bms) 421 | 422 | # predict - lobster from model for Bivalve.Myadora.striata ---- 423 | mod<-gamm 424 | testdata <- expand.grid(lobster=seq(min(dat$lobster),max(dat$lobster),length.out = 20), 425 | Location=(mod$model$Location), 426 | Site=(mod$model$Site), 427 | Status = c("Fished","No-take"))%>% 428 | distinct()%>% 429 | glimpse() 430 | 431 | fits <- predict.gam(mod, newdata=testdata, type='response', se.fit=T) 432 | #head(fits,2) 433 | predicts.bms.lobster = testdata%>%data.frame(fits)%>% 434 | group_by(lobster)%>% #only change here 435 | # group_by(sqrt.X500um,Status)%>% #only change here 436 | summarise(response=mean(fit),se.fit=mean(se.fit))%>% 437 | ungroup() 438 | write.csv(predicts.bms.lobster,"predicts.csv") #there is some BUG in dplyr - that this fixes 439 | predicts.bms.lobster<-read.csv("predicts.csv")%>% 440 | glimpse() 441 | 442 | # MODEL Decapod.P.novazelandiae 4mm + Lobster---- 443 | dat.cpn<-dat%>%filter(Taxa=="CPN") 444 | head(dat.cpn,2) 445 | gamm=gam(response~s(sqrt.X4mm,k=3,bs='cr')+s(lobster,k=3,bs='cr')+ s(Location,Site,bs="re"), family=tw(),data=dat.cpn) 446 | 447 | # predict - sqrt.X4mm from model for Decapod.P.novazelandiae ---- 448 | mod<-gamm 449 | testdata <- expand.grid(sqrt.X4mm=seq(min(dat$sqrt.X4mm),max(dat$sqrt.X4mm),length.out = 20), 450 | lobster=mean(mod$model$lobster), 451 | Location=(mod$model$Location), 452 | Site=(mod$model$Site), 453 | Status = c("Fished","No-take"))%>% 454 | distinct()%>% 455 | glimpse() 456 | 457 | fits <- predict.gam(mod, newdata=testdata, type='response', se.fit=T) 458 | head(fits,2) 459 | predicts.cpn.4mm = testdata%>%data.frame(fits)%>% 460 | group_by(sqrt.X4mm)%>% #only change here 461 | summarise(response=mean(fit),se.fit=mean(se.fit))%>% 462 | ungroup() 463 | write.csv(predicts.cpn.4mm,"predicts.csv") #there is some BUG in dplyr - that this fixes 464 | predicts.cpn.4mm<-read.csv("predicts.csv")%>% 465 | glimpse() 466 | 467 | # predict - lobster from model for Decapod.P.novazelandiae ---- 468 | mod<-gamm 469 | testdata <- expand.grid(lobster=seq(min(dat$lobster),max(dat$lobster),length.out = 20), 470 | sqrt.X4mm=mean(mod$model$sqrt.X4mm), 471 | Location=(mod$model$Location), 472 | Site=(mod$model$Site), 473 | Status = c("Fished","No-take"))%>% 474 | distinct()%>% 475 | glimpse() 476 | 477 | fits <- predict.gam(mod, newdata=testdata, type='response', se.fit=T) 478 | #head(fits,2) 479 | predicts.cpn.lobster = testdata%>%data.frame(fits)%>% 480 | group_by(lobster)%>% #only change here 481 | # group_by(sqrt.X500um,Status)%>% #only change here 482 | summarise(response=mean(fit),se.fit=mean(se.fit))%>% 483 | ungroup() 484 | write.csv(predicts.cpn.lobster,"predicts.csv") #there is some BUG in dplyr - that this fixes 485 | predicts.cpn.lobster<-read.csv("predicts.csv")%>% 486 | glimpse() 487 | 488 | # PLOTS for Bivalve.Dosina.subrosea 500um + distance x Status ---- 489 | ggmod.bds.status<- ggplot(aes(x=Status,y=response,fill=Status,colour=Status), data=predicts.bds.status) + 490 | ylab(" ")+ 491 | xlab('Status')+ 492 | # ggtitle(substitute(italic(name)))+ 493 | scale_fill_manual(labels = c("Fished", "No-take"),values=c("red", "black"))+ 494 | scale_colour_manual(labels = c("Fished", "No-take"),values=c("red", "black"))+ 495 | scale_x_discrete(limits = rev(levels(predicts.bds.status$Status)))+ 496 | geom_bar(stat = "identity")+ 497 | geom_errorbar(aes(ymin = response-se.fit,ymax = response+se.fit),width = 0.5) + 498 | theme_classic()+ 499 | Theme1+ 500 | annotate("text", x = -Inf, y=Inf, label = "(a)",vjust = 1, hjust = -.1,size=5)+ 501 | annotate("text", x = -Inf, y=Inf, label = " Dosinia subrosea",vjust = 1, hjust = -.1,size=5,fontface="italic") 502 | ggmod.bds.status 503 | 504 | ggmod.bds.distance.x.status<- ggplot(aes(x=distance,y=response,colour=Status), data=dat.bds) + 505 | ylab(" ")+ 506 | xlab('Distance (m)')+ 507 | # ggtitle(substitute(italic(name)))+ 508 | scale_color_manual(labels = c("Fished", "No-take"),values=c("red", "black"))+ 509 | geom_jitter(width = 0.25,height = 0,alpha=0.75, size=2,show.legend=FALSE)+ 510 | # geom_point(alpha=0.75, size=2)+ 511 | geom_line(data=predicts.bds.distance.x.status,show.legend=FALSE)+ 512 | geom_line(data=predicts.bds.distance.x.status,aes(y=response - se.fit),linetype="dashed",show.legend=FALSE)+ 513 | geom_line(data=predicts.bds.distance.x.status,aes(y=response + se.fit),linetype="dashed",show.legend=FALSE)+ 514 | theme_classic()+ 515 | Theme1+ 516 | annotate("text", x = -Inf, y=Inf, label = "(b)",vjust = 1, hjust = -.1,size=5) 517 | ggmod.bds.distance.x.status 518 | 519 | ggmod.bds.500um<- ggplot() + 520 | ylab(" ")+ 521 | xlab('Grain size: 500 um (sqrt)')+ 522 | # ggtitle(substitute(italic(name)))+ 523 | scale_color_manual(labels = c("Fished", "No-take"),values=c("red", "black"))+ 524 | # geom_jitter(width = 0.25,height = 0)+ 525 | geom_point(data=dat.bds,aes(x=sqrt.X500um,y=response,colour=Status), alpha=0.75, size=2,show.legend=FALSE)+ 526 | geom_line(data=predicts.bds.500um,aes(x=sqrt.X500um,y=response),alpha=0.5)+ 527 | geom_line(data=predicts.bds.500um,aes(x=sqrt.X500um,y=response - se.fit),linetype="dashed",alpha=0.5)+ 528 | geom_line(data=predicts.bds.500um,aes(x=sqrt.X500um,y=response + se.fit),linetype="dashed",alpha=0.5)+ 529 | theme_classic()+ 530 | Theme1+ 531 | annotate("text", x = -Inf, y=Inf, label = "(c)",vjust = 1, hjust = -.1,size=5) 532 | ggmod.bds.500um 533 | 534 | # PLOTS Bivalve M.striata lobster ---- 535 | ggmod.bms.lobster<- ggplot() + 536 | ylab("Abundance")+ 537 | xlab(bquote('Density of legal lobster (no./25' *m^-2*')'))+ 538 | scale_color_manual(labels = c("Fished", "SZ"),values=c("red", "black"))+ 539 | geom_point(data=dat.bms,aes(x=lobster,y=response,colour=Status), alpha=0.75, size=2,show.legend=FALSE)+ 540 | geom_line(data=predicts.bms.lobster,aes(x=lobster,y=response),alpha=0.5)+ 541 | geom_line(data=predicts.bms.lobster,aes(x=lobster,y=response - se.fit),linetype="dashed",alpha=0.5)+ 542 | geom_line(data=predicts.bms.lobster,aes(x=lobster,y=response + se.fit),linetype="dashed",alpha=0.5)+ 543 | theme_classic()+ 544 | Theme1+ 545 | annotate("text", x = -Inf, y=Inf, label = "(d)",vjust = 1, hjust = -.1,size=5)+ 546 | annotate("text", x = -Inf, y=Inf, label = " Myadora striata",vjust = 1, hjust = -.1,size=5,fontface="italic")+ 547 | geom_blank(data=dat.bms,aes(x=lobster,y=response*1.05))#to nudge data off annotations 548 | ggmod.bms.lobster 549 | 550 | # PLOTS Decapod.P.novazelandiae 4mm + lobster ---- 551 | ggmod.cpn.lobster<- ggplot() + 552 | ylab(" ")+ 553 | xlab(bquote('Density of legal lobster (no./25' *m^-2*')'))+ 554 | scale_color_manual(labels = c("Fished", "SZ"),values=c("red", "black"))+ 555 | geom_point(data=dat.cpn,aes(x=lobster,y=response,colour=Status), alpha=0.75, size=2,show.legend=FALSE)+ 556 | geom_line(data=predicts.cpn.lobster,aes(x=lobster,y=response),alpha=0.5)+ 557 | geom_line(data=predicts.cpn.lobster,aes(x=lobster,y=response - se.fit),linetype="dashed",alpha=0.5)+ 558 | geom_line(data=predicts.cpn.lobster,aes(x=lobster,y=response + se.fit),linetype="dashed",alpha=0.5)+ 559 | theme_classic()+ 560 | Theme1+ 561 | annotate("text", x = -Inf, y=Inf, label = "(e)",vjust = 1, hjust = -.1,size=5)+ 562 | annotate("text", x = -Inf, y=Inf, label = " Pagurus novizelandiae",vjust = 1, hjust = -.1,size=5,fontface="italic")+ 563 | geom_blank(data=dat.cpn,aes(x=lobster,y=response*1.05))#to nudge data off annotations 564 | ggmod.cpn.lobster 565 | 566 | ggmod.cpn.4mm<- ggplot() + 567 | ylab(" ")+ 568 | xlab('Grain size: 4 mm (sqrt)')+ 569 | scale_color_manual(labels = c("Fished", "No-take"),values=c("red", "black"))+ 570 | geom_point(data=dat.cpn,aes(x=sqrt.X4mm,y=response,colour=Status), alpha=0.75, size=2,show.legend=FALSE)+ 571 | geom_line(data=predicts.cpn.4mm,aes(x=sqrt.X4mm,y=response),alpha=0.5)+ 572 | geom_line(data=predicts.cpn.4mm,aes(x=sqrt.X4mm,y=response - se.fit),linetype="dashed",alpha=0.5)+ 573 | geom_line(data=predicts.cpn.4mm,aes(x=sqrt.X4mm,y=response + se.fit),linetype="dashed",alpha=0.5)+ 574 | theme_classic()+ 575 | Theme1+ 576 | annotate("text", x = -Inf, y=Inf, label = "(f)",vjust = 1, hjust = -.1,size=5)+ 577 | annotate("text", x = -Inf, y=Inf, label = " ",vjust = 1, hjust = -.1,size=5,fontface="italic") 578 | ggmod.cpn.4mm 579 | 580 | # combined.plot using grid() and gridExtra()------ 581 | blank <- grid.rect(gp=gpar(col="white")) 582 | 583 | # To see what they will look like use grid.arrange() - make sure Plot window is large enough! - or will error! 584 | grid.arrange(ggmod.bds.status,ggmod.bds.distance.x.status,ggmod.bds.500um, 585 | ggmod.bms.lobster,blank,blank, 586 | ggmod.cpn.lobster,ggmod.cpn.4mm,blank,nrow=3,ncol=3) 587 | 588 | # Use arrangeGrob ONLY - as we can pass this to ggsave! Note use of raw ggplot's 589 | combine.plot<-arrangeGrob(ggmod.bds.status,ggmod.bds.distance.x.status,ggmod.bds.500um, 590 | ggmod.bms.lobster,blank,blank, 591 | ggmod.cpn.lobster,ggmod.cpn.4mm,blank,nrow=3,ncol=3) 592 | 593 | ggsave(combine.plot,file="Langlois_gamm.plot.png", width = 30, height = 30,units = "cm") 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | -------------------------------------------------------------------------------- /x_function_full_subsets_gam_v1.11.R: -------------------------------------------------------------------------------- 1 | full.subsets.gam=function(use.dat, 2 | test.fit, 3 | pred.vars.cont=NA, 4 | pred.vars.fact=NA, 5 | cyclic.vars=NA, 6 | linear.vars=NA, 7 | factor.smooth.interactions=pred.vars.fact, 8 | factor.factor.interactions=F, 9 | smooth.smooth.interactions=F, 10 | cov.cutoff=0.28, 11 | cor.matrix=NA, 12 | max.predictors=3, 13 | k=5, 14 | bs.arg="'cr'", 15 | null.terms="", 16 | max.models=500, 17 | parallel=F, 18 | n.cores=4, 19 | r2.type="r2.lm.est", 20 | report.unique.r2=F, 21 | factor.interactions="previous.arg", 22 | smooth.interactions="previous.arg", 23 | size="previous.arg"){ 24 | # make sure use.dat is a data.frame 25 | use.dat=as.data.frame(use.dat) 26 | # manage previous version arguments 27 | if(factor.interactions!="previous.arg"){ 28 | factor.factor.interactions=factor.interactions 29 | warning('Argument factor.interactions has been replaced with factor.factor.interactions. 30 | Please update your code as usage of factor.interactions will not be supported in 31 | future versions.') 32 | } 33 | if(is.na(smooth.interactions)==T){ 34 | factor.smooth.interactions=smooth.interactions 35 | warning('Argument smooth.interactions has been replaced with factor.smooth.interactions. 36 | Please update your code as usage of smooth.interactions will not be supported in 37 | future versions.')}else{if(smooth.interactions!="previous.arg"){ 38 | factor.smooth.interactions=smooth.interactions 39 | warning('Argument smooth.interactions has been replaced with factor.smooth.interactions. 40 | Please update your code as usage of smooth.interactions will not be supported in 41 | future versions.') 42 | }} 43 | if(size!="previous.arg"){ 44 | size=max.predictors 45 | warning('Argument size has been replaced with max.predictors. 46 | Please update your code as usage of size will not be supported in 47 | future versions.') 48 | } 49 | 50 | # make an "intercept" term for the null model 51 | use.dat$intercept=1 52 | interaction.terms=NA 53 | linear.interaction.terms=NA 54 | all.predictors=unique(na.omit(c(pred.vars.cont,pred.vars.fact,linear.vars))) 55 | included.vars=all.predictors 56 | 57 | 58 | # check the null model will fit 59 | if(nchar(null.terms)>0){ 60 | null.formula=as.formula(paste("~ intercept-1",null.terms,sep="+"))}else{ 61 | null.formula=as.formula("~ intercept-1")} 62 | 63 | if(length(grep("dsm",class(test.fit)))>0){ 64 | null.formula=as.formula(paste("~1",null.terms,sep="+")) 65 | null.fit=try(update(test.fit,formula=null.formula),silent=T) 66 | }else{ 67 | null.fit=try(update(test.fit,formula=null.formula,data=use.dat),silent=T)} 68 | 69 | if(class(null.fit)[1]=="try-error"){ 70 | stop(paste("Null model not successfully fitted, please check your inputs. 71 | If there are no random effects try using 'gam' instead of 'uGamm' 72 | in your test.fit model call.", 73 | " ", 74 | "The following error message was provided: ", 75 | " ", 76 | null.fit, ""))} 77 | 78 | # check for missing predictor values 79 | if(max(is.na(use.dat[,all.predictors]))==1){ 80 | stop("Predictor variables contain NA and AICc/BIC comparisons are invalid. 81 | Remove rows with NA from the input data or interpolate missing predictors.")} 82 | 83 | # make the interaction terms vector 84 | interaction.terms=NA 85 | 86 | # if there are factors 87 | if(length(na.omit(pred.vars.fact))>0){ 88 | # if there are two or more factors 89 | if(length(na.omit(pred.vars.fact))>1){ 90 | # make all the interactions between factors 91 | if(class(factor.factor.interactions)=="logical"){ 92 | if(factor.factor.interactions==T){ 93 | if(length(pred.vars.fact)<2){ 94 | stop("You have less than 2 factors. Please reset 'factor.factor.interactions' to 'False'")} 95 | factor.correlations=check.correlations(use.dat[,pred.vars.fact]) 96 | fact.combns=list() 97 | fact.cmbns.max.predictors=max.predictors 98 | if(max.predictors>length(pred.vars.fact)){fact.cmbns.max.predictors=length(pred.vars.fact)} 99 | for(i in 2:fact.cmbns.max.predictors){ 100 | if(i<=length(pred.vars.fact)){ 101 | fact.combns=c(fact.combns, 102 | combn(pred.vars.fact,i,simplify=F)) }} 103 | # check which were correlated 104 | fact.combns=lapply(fact.combns,FUN=function(x){ 105 | row.index=which(match(rownames(factor.correlations),x)>0) 106 | col.index=which(match(colnames(factor.correlations),x)>0) 107 | cor.mat.m=factor.correlations[row.index,col.index] 108 | out=x 109 | if(max(abs(cor.mat.m[upper.tri(cor.mat.m)]))>cov.cutoff){out=NA} 110 | return(out)}) 111 | fact.combns[which(is.na(fact.combns))]=NULL 112 | tt=data.frame(lapply(fact.combns,FUN=function(x){ 113 | do.call("paste",as.list(use.dat[,x]))})) 114 | factor.interaction.terms=unlist(lapply(fact.combns,FUN=paste,collapse=".I.")) 115 | colnames(tt)=factor.interaction.terms 116 | 117 | use.dat=cbind(use.dat,tt) 118 | pred.vars.fact=c(pred.vars.fact,factor.interaction.terms) 119 | } 120 | } 121 | # make only specified interactions between factors 122 | if(class(factor.factor.interactions)=="character"){ 123 | if(length(factor.factor.interactions)<2){ 124 | stop("You specified less than 2 factors as factor.factor.interactions.")} 125 | if(max(is.na(match(factor.factor.interactions,colnames(use.dat))))==1){ 126 | stop("Not all specified factor.factor.interactions are supplied in use.dat")} 127 | factor.correlations=check.correlations(use.dat[,factor.factor.interactions]) 128 | #if(min(factor.correlations,na.rm=T)>cov.cutoff){ 129 | # stop("All factors have a correlation higher than your cutoff value")} 130 | if(length(which(factor.correlations1){ 131 | fact.combns=list() 132 | fact.cmbns.max.predictors=max.predictors 133 | if(max.predictors>length(factor.factor.interactions)){fact.cmbns.max.predictors=length(factor.factor.interactions)} 134 | for(i in 2:fact.cmbns.max.predictors){ 135 | if(i<=length(factor.factor.interactions)){ 136 | fact.combns=c(fact.combns, 137 | combn(factor.factor.interactions,i,simplify=F)) }} 138 | # check which were correlated 139 | fact.combns=lapply(fact.combns,FUN=function(x){ 140 | row.index=which(match(rownames(factor.correlations),x)>0) 141 | col.index=which(match(colnames(factor.correlations),x)>0) 142 | cor.mat.m=factor.correlations[row.index,col.index] 143 | out=x 144 | if(max(abs(cor.mat.m[upper.tri(cor.mat.m)]))>cov.cutoff){out=NA} 145 | return(out)}) 146 | fact.combns[which(is.na(fact.combns))]=NULL 147 | tt=data.frame(lapply(fact.combns,FUN=function(x){ 148 | do.call("paste",as.list(use.dat[,x]))})) 149 | factor.interaction.terms=unlist(lapply(fact.combns,FUN=paste,collapse=".I.")) 150 | colnames(tt)=factor.interaction.terms 151 | 152 | use.dat=cbind(use.dat,tt) 153 | pred.vars.fact=c(pred.vars.fact,factor.interaction.terms) 154 | } 155 | } 156 | } 157 | # make sure the factors are factors 158 | for(f in 1:length(pred.vars.fact)){ 159 | use.dat[,pred.vars.fact[f]]=factor(use.dat[,pred.vars.fact[f]])} 160 | 161 | 162 | # check which factors should be included as interactions with the smoothers 163 | # for if only factors are specified (including default) 164 | if(class(factor.smooth.interactions)=="character"){ 165 | 166 | factor.smooth.interactions=pred.vars.fact[which(unlist(lapply(strsplit(pred.vars.fact, 167 | split=".I."),function(x){ 168 | max(is.na(match(x,factor.smooth.interactions)))}))==0)] 169 | # make the interaction terms between the factors and continuous predictors 170 | 171 | if(length(na.omit(factor.smooth.interactions))>0){ 172 | all.interactions=expand.grid(pred.vars.cont,factor.smooth.interactions) 173 | interaction.terms=paste(all.interactions$Var1,all.interactions$Var2,sep=".by.") 174 | 175 | # now interactions between linear continous predictors and factors 176 | if(length(na.omit(linear.vars))>0){ 177 | linear.interactions=expand.grid(linear.vars,factor.smooth.interactions) 178 | linear.interaction.terms=paste(linear.interactions$Var1,linear.interactions$Var2, 179 | sep=".t.")} 180 | } 181 | } 182 | if(class(factor.smooth.interactions)=="list"){ 183 | cont.var.interactions=factor.smooth.interactions$cont.vars 184 | linear.var.interactions=factor.smooth.interactions$linear.vars 185 | factor.smooth.interactions=factor.smooth.interactions$fact.vars 186 | 187 | factor.smooth.interactions=pred.vars.fact[which(unlist(lapply(strsplit(pred.vars.fact, 188 | split=".I."),function(x){ 189 | max(is.na(match(x,factor.smooth.interactions)))}))==0)] 190 | # make the interaction terms between the factors and continuous predictors 191 | 192 | if(length(na.omit(factor.smooth.interactions))>0){ 193 | all.interactions=expand.grid(cont.var.interactions,factor.smooth.interactions) 194 | interaction.terms=paste(all.interactions$Var1,all.interactions$Var2,sep=".by.") 195 | 196 | # now interactions between linear continous predictors and factors 197 | if(length(na.omit(linear.var.interactions))>0){ 198 | linear.interactions=expand.grid(linear.var.interactions,factor.smooth.interactions) 199 | linear.interaction.terms=paste(linear.interactions$Var1,linear.interactions$Var2, 200 | sep=".t.")} 201 | } 202 | } 203 | 204 | } 205 | 206 | # if we want smooth.smooth interactions 207 | smooth.smooth.interaction.terms=NA 208 | # for interactions amonst all continuous predictors 209 | if(class(smooth.smooth.interactions)=="logical"){ 210 | if(smooth.smooth.interactions==T){ 211 | if(length(pred.vars.cont)<2){ 212 | stop("You have less than 2 continuous predictors you wish interactions for. 213 | Please reset 'smooth.smooth.interactions' to 'False'")} 214 | continuous.correlations=check.correlations(use.dat[,pred.vars.cont]) 215 | cont.combns=list() 216 | cont.cmbns.max.predictors=max.predictors 217 | if(max.predictors>length(pred.vars.cont)){cont.cmbns.max.predictors=length(pred.vars.cont)} 218 | for(i in 2:cont.cmbns.max.predictors){ 219 | if(i<=length(pred.vars.cont)){ 220 | cont.combns=c(cont.combns, 221 | combn(pred.vars.cont,i,simplify=F)) }} 222 | # check which were correlated 223 | cont.combns=lapply(cont.combns,FUN=function(x){ 224 | row.index=which(match(rownames(continuous.correlations),x)>0) 225 | col.index=which(match(colnames(continuous.correlations),x)>0) 226 | cor.mat.m=continuous.correlations[row.index,col.index] 227 | out=x 228 | if(max(abs(cor.mat.m[upper.tri(cor.mat.m)]))>cov.cutoff){out=NA} 229 | return(out)}) 230 | cont.combns[which(is.na(cont.combns))]=NULL 231 | tt=data.frame(lapply(cont.combns,FUN=function(x){ 232 | do.call("paste",as.list(use.dat[,x]))})) 233 | smooth.smooth.interaction.terms=unlist(lapply(cont.combns,FUN=paste,collapse=".te.")) 234 | colnames(tt)=smooth.smooth.interaction.terms 235 | } 236 | } 237 | # for only specific interactions amonst continuous predictors 238 | if(class(smooth.smooth.interactions)=="character"){ 239 | if(length(smooth.smooth.interactions)<2){ 240 | stop("You specified less than 2 variables as smooth.smooth.interactions.")} 241 | if(max(is.na(match(smooth.smooth.interactions,colnames(use.dat))))==1){ 242 | stop("Not all specified smooth.smooth.interactions are supplied in use.dat")} 243 | continuous.correlations=check.correlations(use.dat[,smooth.smooth.interactions]) 244 | cont.combns=list() 245 | cont.cmbns.max.predictors=max.predictors 246 | if(max.predictors>length(smooth.smooth.interactions)){cont.cmbns.max.predictors=length(smooth.smooth.interactions)} 247 | for(i in 2:cont.cmbns.max.predictors){ 248 | if(i<=length(smooth.smooth.interactions)){ 249 | cont.combns=c(cont.combns, 250 | combn(smooth.smooth.interactions,i,simplify=F)) }} 251 | # check which were correlated 252 | cont.combns=lapply(cont.combns,FUN=function(x){ 253 | row.index=which(match(rownames(continuous.correlations),x)>0) 254 | col.index=which(match(colnames(continuous.correlations),x)>0) 255 | cor.mat.m=continuous.correlations[row.index,col.index] 256 | out=x 257 | if(max(abs(cor.mat.m[upper.tri(cor.mat.m)]))>cov.cutoff){out=NA} 258 | return(out)}) 259 | cont.combns[which(is.na(cont.combns))]=NULL 260 | tt=data.frame(lapply(cont.combns,FUN=function(x){ 261 | do.call("paste",as.list(use.dat[,x]))})) 262 | smooth.smooth.interaction.terms=unlist(lapply(cont.combns,FUN=paste,collapse=".te.")) 263 | colnames(tt)=smooth.smooth.interaction.terms 264 | } 265 | 266 | all.predictors=na.omit(unique(c(all.predictors,pred.vars.fact))) 267 | # calculate a correlation matrix between all predictors 268 | cc=check.correlations(use.dat[,all.predictors],parallel=parallel,n.cores=n.cores) 269 | if(length(cor.matrix)==1){ 270 | cor.matrix=cc 271 | # replace NA's with zero. 272 | cor.matrix[which(cor.matrix=="NaN")]=0 273 | cor.matrix[which(is.na(cor.matrix)==T)]=0}else{ 274 | # check if the user defined matrix has the same rownames and colnames 275 | check.predictors=c(match(all.predictors,colnames(cor.matrix)), 276 | match(all.predictors,rownames(cor.matrix))) 277 | missing.predictors=unique(rep(all.predictors,2)[which(is.na(check.predictors))]) 278 | if(length(missing.predictors)>0){ 279 | stop(paste("Supplied cor.matrix is missing required predictors: ", 280 | paste(missing.predictors,collapse=", "),".",sep=""))} 281 | } 282 | 283 | # make all possible combinations 284 | if(length(na.omit(c(pred.vars.cont, 285 | pred.vars.fact)))0){ 317 | # check that any "by" factor vars are accompanied by a + term in its owns right 318 | if(max(is.na(match(fact.vars,mod.m)))==1){use.mods[[m]]=NA}} 319 | 320 | # remove the model if the predictors are correlated 321 | if(length(mod.terms)>1){ 322 | row.index=which(match(rownames(cor.matrix),unique(mod.terms))>0) 323 | col.index=which(match(colnames(cor.matrix),unique(mod.terms))>0) 324 | cor.mat.m=cor.matrix[row.index,col.index] 325 | if(max(abs(cor.mat.m[upper.tri(cor.mat.m)]))>cov.cutoff){use.mods[[m]]=NA} 326 | if(max(abs(cor.mat.m[lower.tri(cor.mat.m)]))>cov.cutoff){use.mods[[m]]=NA} 327 | 328 | } 329 | 330 | # remove the model if there are more than the number of terms specified in "max.predictors" 331 | if(length(n.vars.m)>max.predictors){use.mods[[m]]=NA} 332 | 333 | # remove the models if a continuous predictor occurs as a by, or a te, and as a single term 334 | if(length(cont.vars)>length(unique(cont.vars))){use.mods[[m]]=NA} 335 | 336 | } 337 | 338 | use.mods[which(is.na(use.mods))]=NULL 339 | 340 | # now make the models into gamm formula 341 | if(nchar(null.terms)==0){# if there is no bs='re' random effect random effect 342 | # or other null term in the null model 343 | mod.formula=list(as.formula("~ intercept-1"))} 344 | if(nchar(null.terms)>0){# to add a bs='re' random effect 345 | mod.formula=list(null.formula)} 346 | 347 | for(m in 1:length(use.mods)){ 348 | mod.m=use.mods[[m]] 349 | cont.smooths=mod.m[which(match(mod.m,setdiff(pred.vars.cont,linear.vars))>0)] 350 | by.smooths=mod.m[grep(".by.",mod.m,fixed=T)] 351 | te.smooths=mod.m[grep(".te.",mod.m,fixed=T)] 352 | factor.terms=mod.m[which(match(mod.m,pred.vars.fact)>0)] 353 | linear.terms=mod.m[which(match(mod.m,linear.vars)>0)] 354 | linear.interaction.terms=mod.m[grep(paste(linear.vars,".t.",sep=""),mod.m,fixed=T)] 355 | all.terms.vec=character() 356 | 357 | if(length(cont.smooths>0)){all.terms.vec=c(all.terms.vec, 358 | paste("s(",cont.smooths,",k=",k,",bs=",bs.arg,")",sep=""))} 359 | if(length(by.smooths>0)){all.terms.vec=c(all.terms.vec, 360 | paste("s(",gsub(".by.",",by=",by.smooths,fixed=T),",k=",k,",bs=",bs.arg,")",sep=""))} 361 | if(length(te.smooths>0) & class(test.fit)[[1]]!="gamm4"){all.terms.vec=c(all.terms.vec, 362 | paste("te(",gsub(".te.",",",te.smooths,fixed=T),",k=",k,",bs=",bs.arg,")",sep=""))} 363 | if(length(te.smooths>0) & class(test.fit)[[1]]=="gamm4"){all.terms.vec=c(all.terms.vec, 364 | paste("t2(",gsub(".te.",",",te.smooths,fixed=T),",k=",k,",bs=",bs.arg,")",sep=""))} 365 | if(length(linear.interaction.terms>0)){all.terms.vec=c(all.terms.vec, 366 | gsub(".t.","*",linear.interaction.terms,fixed=T))} 367 | if(length(factor.terms>0)){all.terms.vec=c(all.terms.vec,factor.terms)} 368 | if(length(linear.terms>0)){all.terms.vec=c(all.terms.vec,linear.terms)} 369 | if(max(is.na(cyclic.vars))!=1){ 370 | for(r in 1:length(cyclic.vars)){ 371 | for(v in 1:length(all.terms.vec)){ 372 | if(length(grep(cyclic.vars[r],all.terms.vec[v]))>0){ 373 | all.terms.vec[v]=gsub(paste("bs=",bs.arg,sep=""),"bs='cc'",all.terms.vec[v]) 374 | }}}} 375 | for(v in 1:length(all.terms.vec)){ 376 | if(length(grep("te(",all.terms.vec[v],fixed=T))>0){ 377 | bs.arg.v=c("","") 378 | smooth.vars.v=unlist(strsplit(gsub("te(","",all.terms.vec[v],fixed=T),split=","))[1:2] 379 | var.type.vec=unlist(lapply(smooth.vars.v,FUN=function(x){match(x,cyclic.vars)})) 380 | bs.arg.v[which(is.na(var.type.vec))]=bs.arg 381 | bs.arg.v[which(var.type.vec>0)]="'cc'" 382 | bs.arg.v=paste("bs=c(",paste0(bs.arg.v,collapse=","),")",sep="") 383 | all.terms.vec[v]=gsub("bs='cc'",bs.arg.v,all.terms.vec[v]) 384 | all.terms.vec[v]=gsub(paste("bs=",bs.arg,sep=""),bs.arg.v,all.terms.vec[v]) 385 | } 386 | } 387 | 388 | if(nchar(null.terms)==0){# if there is no bs='re' random effect 389 | # or other null term in the null model 390 | formula.m=as.formula(paste("~", 391 | paste(all.terms.vec,collapse="+")))} 392 | if(nchar(null.terms)>0){# 393 | formula.m=as.formula(paste("~", 394 | paste(c(all.terms.vec,null.terms),collapse="+")))} 395 | mod.formula=c(mod.formula,list(formula.m)) 396 | } 397 | 398 | names(mod.formula)=c("null",lapply(use.mods,FUN=paste,collapse="+")) 399 | 400 | # Is this too many models? 401 | n.mods=length(mod.formula) 402 | time.to.run=round(system.time(try(update(test.fit,formula=mod.formula[[n.mods]],data=use.dat),silent=T))[3]*n.mods/60) 403 | test.mod=try(update(test.fit,formula=mod.formula[[n.mods]],data=use.dat),silent=T) 404 | mod.gbs=round(object.size(test.mod)/1073741824*n.mods,1) 405 | if(n.mods>max.models){ 406 | stop(paste("You have ",n.mods," models. If you want to fit all of these you need to 407 | increase 'max.models' from ",max.models,". Otherwise, if the model set 408 | is larger than you can realistically fit, try reducing the number of predictors, 409 | setting the covariance 'cov.cutoff' argument to less than ", cov.cutoff, 410 | " 411 | or setting 'factor.factor.interactions' to FALSE (if you have factors).",sep="")) 412 | } 413 | 414 | # now fit the models by updating the test fit (with or without parallel) 415 | pb <- txtProgressBar(max = length(mod.formula), style = 3) 416 | progress <- function(n) setTxtProgressBar(pb, n) 417 | if(parallel==T){ 418 | require(doSNOW) 419 | cl=makeCluster(n.cores) 420 | registerDoSNOW(cl) 421 | opts <- list(progress = progress) 422 | out.dat<-foreach(l = 1:length(mod.formula), 423 | .packages=c('mgcv','gamm4','MuMIn'), 424 | .errorhandling='pass', 425 | .options.snow = opts)%dopar%{ 426 | if(length(grep("dsm",class(test.fit)))>0){ 427 | out=update(test.fit,formula=mod.formula[[l]])} 428 | if(length(grep("dsm",class(test.fit)))==0){ 429 | out=update(test.fit,formula=mod.formula[[l]],data=use.dat)} 430 | } 431 | close(pb) 432 | stopCluster(cl) 433 | registerDoSEQ() 434 | }else{ 435 | out.dat=list() 436 | for(l in 1:length(mod.formula)){ 437 | if(length(grep("dsm",class(test.fit)))>0){ 438 | out=try(update(test.fit,formula=mod.formula[[l]]),silent=T)} 439 | if(length(grep("dsm",class(test.fit)))==0){ 440 | out=try(update(test.fit,formula=mod.formula[[l]],data=use.dat),silent=T)} 441 | out.dat=c(out.dat,list(out)) 442 | setTxtProgressBar(pb,l) 443 | 444 | } 445 | } 446 | close(pb) 447 | names(out.dat)=names(mod.formula[1:n.mods]) 448 | 449 | # find all the models that didn't fit and extract the error messages 450 | # model.success=lapply(lapply(out.dat,FUN=class),FUN=function(x){ 451 | # x[1]!="try-error"}) 452 | model.success=lapply(lapply(out.dat,FUN=class),FUN=function(x){ 453 | length(grep("gam",x))>0}) 454 | 455 | failed.models=mod.formula[which(model.success==F)] 456 | success.models=out.dat[which(model.success==T)] 457 | if(length(success.models)==0){ 458 | stop("None of your models fitted successfully. Please check your input objects.")} 459 | 460 | # some functions for extracting model information 461 | require(MuMIn) 462 | wi<<-function(AIC.vals){# This function calculate the Aikaike weights: 463 | # wi=(exp(-1/2*AICc.vals.adj))/Sum.wi=1 to r (exp(-1/2*AICc.vals.adj)) 464 | AICc.vals.adj=AIC.vals-min(na.omit(AIC.vals)) 465 | wi.den=rep(NA,length(AICc.vals.adj)) 466 | for(i in 1:length(AICc.vals.adj)){ 467 | wi.den[i]=exp(-1/2*AICc.vals.adj[i])} 468 | wi.den.sum=sum(na.omit(wi.den)) 469 | wi=wi.den/wi.den.sum 470 | return(wi)} 471 | 472 | # of the successful models, make a table indicating which variables are included 473 | var.inclusions=matrix(0,ncol=length(included.vars),length(success.models)) 474 | colnames(var.inclusions)=c(included.vars) 475 | 476 | for(m in 1:length(success.models)){ 477 | pred.vars.m=unique( 478 | unlist(strsplit(unlist(strsplit(unlist(strsplit(unlist(strsplit(unlist(strsplit(unlist(strsplit(names(success.models)[m], 479 | split="+",fixed=T)), 480 | split=".by.",fixed=T)), 481 | split=".I.",fixed=T)), 482 | split="*",fixed=T)), 483 | split=".t.",fixed=T)), 484 | split=".te.",fixed=T))) 485 | if(pred.vars.m[1]!="null"){var.inclusions[m,pred.vars.m]=1}} 486 | 487 | # now make a table of all the model summary data 488 | mod.data.out=data.frame("modname"=names(success.models)) 489 | mod.data.out$formula=unlist(lapply(success.models,FUN=function(x){as.character(formula(x)[3])})) 490 | mod.data.out$AICc=unlist(lapply(success.models,FUN=MuMIn::AICc)) 491 | mod.data.out$BIC=unlist(lapply(success.models,FUN=BIC)) 492 | mod.data.out$delta.AICc=round(mod.data.out$AICc-min(mod.data.out$AICc),3) 493 | mod.data.out$delta.BIC=round(mod.data.out$BIC-min(mod.data.out$BIC),3) 494 | mod.data.out$wi.AICc=round(wi(mod.data.out$AICc),3) 495 | mod.data.out$wi.BIC=round(wi(mod.data.out$BIC),3) 496 | mod.data.out$r2.vals=round(unlist(lapply(success.models,FUN=function(x){ 497 | out=NA 498 | if(class(x)[1]=="gam" & r2.type=="dev"){out=summary(x)$dev.expl} 499 | if(class(x)[1]=="gam" & r2.type=="r2"){out=summary(x)$r.sq} 500 | if(class(x)[1]=="gam" & r2.type=="r2.lm.est"){ 501 | out=summary(lm(x$y~predict(x)))$r.sq} 502 | if(class(x)[[1]]=="gamm4" & r2.type=="dev"){ 503 | out=summary(x$gam)$dev.expl 504 | if(length(out)==0){out=NA}} 505 | if(class(x)[[1]]=="gamm4" & r2.type=="r2"){out=summary(x$gam)$r.sq} 506 | if(class(x)[[1]]=="gamm4" & r2.type=="r2.lm.est"){ 507 | out=summary(lm(attributes(x$mer)$frame$y~ 508 | predict(x[[1]],re.form=NA,type="response")))$r.sq} 509 | if(is.null(out)){out=NA} 510 | return(out)})),3) 511 | 512 | # substract the null model r2 value from each model r2 value 513 | if(report.unique.r2==T){ 514 | null.r2=mod.data.out$r2.vals[which(mod.data.out$modname=="null")] 515 | mod.data.out$r2.vals.unique=mod.data.out$r2.vals-null.r2} 516 | 517 | # now calculate the summed edf 518 | mod.data.out$edf=round(unlist(lapply(success.models,FUN=function(x){ 519 | if(class(x)[1]=="gam"){ 520 | edf.m=summary(x)$edf 521 | p.coeff.m=summary(x)$p.coeff}else{ 522 | #edf.m=summary(x$gam)$edf 523 | #p.coeff.m=summary(x$gam)$p.coeff 524 | edf.m=x$gam$edf 525 | p.coeff.m=x$gam$p.coeff 526 | } 527 | edf.m[which(edf.m<1)]=1 # any edf<0 are reset to 1 to ensure proper 528 | # parameter count when there is shrinkage (bs='cc') 529 | return(sum(c(edf.m,length(p.coeff.m))))})),2) 530 | # count the edf values less than 0.25 to check for serious shrinkage 531 | mod.data.out$edf.less.1=unlist(lapply(success.models,FUN=function(x){ 532 | #if(class(x)[1]=="gam"){edf.m=summary(x)$edf}else{edf.m=summary(x$gam)$edf} 533 | if(class(x)[1]=="gam"){edf.m=summary(x)$edf}else{edf.m=x$gam$edf} 534 | return(length(which(edf.m<0.25)))})) 535 | # now add columns for the included predictors to the dataframe 536 | mod.data.out=cbind(mod.data.out,var.inclusions) 537 | 538 | # now calculate the variable importance 539 | # find the min number of models for each variable 540 | min.mods=min(colSums(mod.data.out[,included.vars])) 541 | # first for AICc 542 | var.weights=unlist(lapply(included.vars,FUN=function(x){ 543 | sum(sort(mod.data.out$wi.AICc[which(mod.data.out[,x]==1)],decreasing=T)[1:min.mods])})) 544 | names(var.weights)=included.vars 545 | variable.weights.raw=var.weights 546 | #variable.weights.raw=colSums(mod.data.out[,included.vars]*mod.data.out$wi.AICc) 547 | aic.var.weights=list(variable.weights.raw=variable.weights.raw) 548 | # next for BIC 549 | var.weights=unlist(lapply(included.vars,FUN=function(x){ 550 | sum(sort(mod.data.out$wi.BIC[which(mod.data.out[,x]==1)],decreasing=T)[1:min.mods])})) 551 | names(var.weights)=included.vars 552 | variable.weights.raw=var.weights 553 | #variable.weights.raw=colSums(mod.data.out[,included.vars]*mod.data.out$wi.BIC) 554 | bic.var.weights=list(variable.weights.raw=variable.weights.raw) 555 | # now return the list of outputs 556 | return(list(mod.data.out=mod.data.out, 557 | used.data=use.dat, 558 | predictor.correlations=cor.matrix, 559 | #mod.formula=mod.formula, 560 | failed.models=failed.models, 561 | success.models=success.models, 562 | variable.importance= 563 | list(aic=aic.var.weights,bic=bic.var.weights))) 564 | } #------------------ end function --------------------------------------------# -------------------------------------------------------------------------------- /case_study2_dataset.csv: -------------------------------------------------------------------------------- 1 | "","X","sediment","Location","Status","Site","Distance","depth","X4mm","X2mm","X1mm","X500um","X250um","X125um","X63um","fetch","org","snapper","lobster","InPreds","BioTurb","Taxa","Abundance" 2 | "1",1,-3.26250047120576,"Hahei","Fished","Cooks Beach Inner",2,12,3.16462,1.41119,3.88962,8.69694,70.31984,6.19663,6.25038,2232582.478,3.45785,0,0,0,0.166666667,"BDS",0 3 | "2",2,-3.48382799871854,"Hahei","Fished","Cooks Beach Inner",5,12,1.69129,1.62811,4.86726,9.92831,69.18594,5.70317,6.92941,2232582.478,3.19104,0,0,0,0.166666667,"BDS",1 4 | "3",3,-4.68556023608562,"Hahei","Fished","Cooks Beach Inner",15,12,1.67228,1.01193,3.9718,21.37884,64.74207,2.75041,4.42267,2232582.478,2.80046,0,0,0,0.833333333,"BDS",0 5 | "4",4,-3.24865363208507,"Hahei","Fished","Cooks Beach Inner",30,12,0.7967,0.77126,1.82919,7.81927,78.20548,5.26789,5.27693,2232582.478,2.78881,0,0,0.333333333,0.333333333,"BDS",1 6 | "5",5,-3.43280045392667,"Hahei","Fished","Cooks Beach Outer",2,9,0.03768,0.25556,2.09768,15.76419,67.41767,7.21756,7.08857,1027166.867,2.4751,0,0.2,0,0.333333333,"BDS",6 7 | "6",6,-3.61029674834709,"Hahei","Fished","Cooks Beach Outer",5,9,0.23887,0.57024,3.42348,18.22572,62.7775,7.48086,7.17101,1027166.867,2.52552,0,0.2,1,0.166666667,"BDS",5 8 | "7",8,-4.68083976068393,"Hahei","Fished","Cooks Beach Outer",30,9,0.05118,0.41971,2.96787,19.90608,70.82593,2.31633,3.47006,1027166.867,2.30917,0,0.2,0,0.333333333,"BDS",1 9 | "8",9,-2.52024747566287,"Hahei","Fished","Darens Glove",2,10,0.28782,0.61595,4.71152,28.53734,41.755,21.44334,2.59654,2924764.739,0.89349,0,0,0.333333333,0.166666667,"BDS",0 10 | "9",10,-3.76275946979601,"Hahei","Fished","Darens Glove",5,10,0.02412,0.36928,3.84234,35.47341,47.43604,11.88242,0.94092,2924764.739,2.53218,0,0,0.166666667,0,"BDS",0 11 | "10",11,-2.73005031072124,"Hahei","Fished","Darens Glove",15,12,0.1138,0.29654,4.30909,28.38553,45.81894,19.27934,1.69096,2924764.739,1.9994,0,0,0.333333333,0.166666667,"BDS",0 12 | "11",12,-2.5951236391731,"Hahei","Fished","Darens Glove",30,12,0.02907,0.40319,4.49215,28.0394,44.06893,20.4063,2.38205,2924764.739,1.35509,0,0,0.166666667,0.166666667,"BDS",0 13 | "12",13,0.902300815961495,"Hahei","Fished","Hahei Beach",2,10,0,0.10243,0.35882,2.13453,57.49768,38.02565,1.79672,1586607.555,0.89349,0,0,1,0.666666667,"BDS",0 14 | "13",14,1.18945310431574,"Hahei","Fished","Hahei Beach",5,10,0,0.08951,0.4494,1.83101,54.66213,41.28873,1.60292,1586607.555,2.53218,0,0,0.5,1.166666667,"BDS",0 15 | "14",15,0.607427342493815,"Hahei","Fished","Hahei Beach",15,11,0.08406,0.16368,0.62516,2.39488,58.95227,35.41736,2.16995,1586607.555,1.9994,0,0,0.166666667,1.333333333,"BDS",1 16 | "15",16,2.43397161322605,"Hahei","Fished","Hahei Beach",30,11,0.02435,0.1215,0.36851,1.15492,40.06436,55.9278,2.21731,1586607.555,1.35509,0,0,0.5,1,"BDS",3 17 | "16",17,1.76634675159096,"Hahei","No-take","Cooks Bluff",2,11,0.02577,0.14764,0.27863,0.85935,51.62622,45.75875,1.28493,1891848.683,3.45785,1,5.2,5,0.666666667,"BDS",0 18 | "17",18,4.26560226112301,"Hahei","No-take","Cooks Bluff",5,10,0.484,0.1518,0.26047,0.57701,17.05321,77.95432,3.48185,1891848.683,3.19104,1,5.2,2.833333333,0.5,"BDS",4 19 | "18",19,4.44916079552009,"Hahei","No-take","Cooks Bluff",15,11,0.29139,0.26949,0.35137,0.69191,13.91155,81.14862,3.29827,1891848.683,2.80046,1,5.2,2.666666667,1.833333333,"BDS",0 20 | "19",20,1.51204481202269,"Hahei","No-take","Cooks Bluff",30,10,0.13563,0.07506,0.10935,0.67739,56.4404,40.8114,1.7303,1891848.683,2.78881,1,5.2,2,3,"BDS",2 21 | "20",21,2.66281813929873,"Hahei","No-take","Gemstone Bay",2,10,0.12925,0.25934,0.4553,0.92908,37.45427,58.79215,1.96145,714179.309,2.4751,3,3.1,0.166666667,0.333333333,"BDS",0 22 | "21",22,2.97744565376185,"Hahei","No-take","Gemstone Bay",5,10,0.09885,0.16337,0.33261,1.02094,32.97139,62.97884,2.3959,714179.309,2.62516,3,3.1,0.166666667,0.833333333,"BDS",0 23 | "22",23,3.93757042934683,"Hahei","No-take","Gemstone Bay",15,12,0.31471,0.2989,0.38652,0.68277,20.48376,74.76174,3.02879,714179.309,1.46117,3,3.1,0,0.5,"BDS",0 24 | "23",24,2.7924345819529,"Hahei","No-take","Gemstone Bay",30,12,0.38099,0.25801,0.2917,0.49269,38.05801,58.04893,2.44488,714179.309,2.43254,3,3.1,0.166666667,0.166666667,"BDS",0 25 | "24",25,-0.635229212715005,"Hahei","No-take","Small Beach",2,10,0.02319,0.18835,1.7116,13.78138,46.50742,33.25779,4.45335,1287001.874,2.11598,3.5,3.4,3.166666667,0,"BDS",0 26 | "25",26,1.73495808103966,"Hahei","No-take","Small Beach",5,10,0.12589,0.28788,0.84551,2.19563,41.37843,49.12646,5.9772,1287001.874,1.79838,3.5,3.4,5.666666667,0,"BDS",0 27 | "26",27,-0.146778821245627,"Hahei","No-take","Small Beach",15,12,0.33404,0.28913,2.49682,12.51038,38.59031,38.11938,7.56874,1287001.874,1.89852,3.5,3.4,3.166666667,0.666666667,"BDS",0 28 | "27",28,2.13587035941396,"Hahei","No-take","Small Beach",30,10,1.71054,0.63942,1.06989,2.39598,29.64741,53.25704,11.17147,1287001.874,1.45875,3.5,3.4,1.5,2.333333333,"BDS",1 29 | "28",29,-0.635229212715005,"Hahei","No-take","Sting Ray Bay",2,10,0.02319,0.18835,1.7116,13.78138,46.50742,33.25779,4.45335,1859264.29,1.69359,2.5,4.2,2,0.333333333,"BDS",1 30 | "29",30,-0.528400588173357,"Hahei","No-take","Sting Ray Bay",5,9,0.14163,0.35636,2.62002,15.33047,40.86696,36.40414,4.21072,1859264.29,1.58063,2.5,4.2,0.833333333,0.666666667,"BDS",0 31 | "30",31,-1.12264470649672,"Hahei","No-take","Sting Ray Bay",15,10,0.75194,0.75227,3.56621,15.54908,45.62314,30.44547,3.26138,1859264.29,1.34382,2.5,4.2,1.333333333,0.166666667,"BDS",0 32 | "31",32,-1.54913423238378,"Hahei","No-take","Sting Ray Bay",30,10,0.03504,0.30468,2.44575,17.12,51.71877,25.89944,2.44507,1859264.29,1.46188,2.5,4.2,0.166666667,0.333333333,"BDS",0 33 | "32",33,0.196887270736938,"Leigh","Fished","Back Beach Inner",2,10,2.13619,0.94687,2.60188,5.79221,46.98246,37.32462,4.16881,1359605.598,1.65099,0,0,1,0,"BDS",5 34 | "33",34,0.0588924509361409,"Leigh","Fished","Back Beach Inner",5,10,1.1385,1.07565,3.21485,6.59121,46.34551,37.00222,4.58774,1359605.598,1.41871,0,0,0.833333333,0,"BDS",8 35 | "34",35,-1.44135201679684,"Leigh","Fished","Back Beach Inner",15,10,1.05895,0.67031,3.05217,17.94499,46.40404,27.86951,2.96514,1359605.598,1.41097,0,0,0.833333333,0,"BDS",7 36 | "35",36,0.0576192166234346,"Leigh","Fished","Back Beach Inner",30,11,0.55617,0.5318,1.26098,5.41276,54.3806,34.17531,3.65923,1359605.598,1.49807,0,0,0.5,0,"BDS",7 37 | "36",37,0.144043883766072,"Leigh","Fished","Back Beach Outer",2,11,0.0172,0.16441,1.60389,13.46422,38.48872,42.82638,3.37621,1368031.691,2.25229,0,0.2,0.166666667,0,"BDS",0 38 | "37",38,0.0702526769607567,"Leigh","Fished","Back Beach Outer",5,11,0.11489,0.29905,2.44809,14.91019,35.14357,43.63288,3.39309,1368031.691,2.1347,0,0.2,1,0,"BDS",1 39 | "38",39,-1.12264470649672,"Leigh","Fished","Back Beach Outer",15,11,0.75194,0.75227,3.56621,15.54908,45.62314,30.44547,3.26138,1368031.691,1.77443,0,0.2,1,0,"BDS",2 40 | "39",40,-1.54913423238378,"Leigh","Fished","Back Beach Outer",30,11,0.03504,0.30468,2.44575,17.12,51.71877,25.89944,2.44507,1368031.691,1.68326,0,0.2,1.333333333,0,"BDS",3 41 | "40",41,2.52988910136934,"Leigh","Fished","Kemps Beach",2,9,0.06032,0.11541,0.35386,1.34381,37.76823,57.75811,2.38763,1724690.26,2.11598,0.25,0.2,1.333333333,0.166666667,"BDS",1 42 | "41",42,2.71544214580469,"Leigh","Fished","Kemps Beach",5,9,0.0267,0.05602,0.27818,2.00025,33.93311,62.25413,1.34575,1724690.26,1.79838,0.25,0.2,2.833333333,0,"BDS",4 43 | "42",43,1.85911876365729,"Leigh","Fished","Kemps Beach",15,9,0.03187,0.09429,0.57329,3.12982,41.00127,53.51028,1.53533,1724690.26,1.89852,0.25,0.2,5.333333333,0.166666667,"BDS",1 44 | "43",44,4.38791771379999,"Leigh","Fished","Kemps Beach",30,9,0.0296,0.07963,0.24881,0.9705,14.53564,81.20583,2.73175,1724690.26,1.45875,0.25,0.2,2.666666667,0.5,"BDS",19 45 | "44",45,0.372730083146206,"Leigh","Fished","Okakari Point",2,11,0,0.06541,0.21854,1.25939,68.13207,28.95217,1.31392,2171727.514,1.69359,2.5,0.2,1.833333333,1,"BDS",9 46 | "45",46,0.893331150540912,"Leigh","Fished","Okakari Point",5,11,0,0.05269,0.24186,1.0379,62.66552,34.70308,1.2284,2171727.514,1.58063,2.5,0.2,2.5,0,"BDS",6 47 | "46",47,-1.18917401378654,"Leigh","Fished","Okakari Point",15,11,0.03408,0.06391,0.23056,0.86855,85.93579,12.03784,0.76024,2171727.514,1.34382,2.5,0.2,4,0,"BDS",8 48 | "47",48,2.02051421815913,"Leigh","Fished","Okakari Point",30,12,0.02035,0.10552,0.31355,0.97941,47.03216,49.51637,1.92334,2171727.514,1.46188,2.5,0.2,5.333333333,0.166666667,"BDS",10 49 | "48",49,-2.52024747566287,"Leigh","No-take","Martins Rock",2,10,0.28782,0.61595,4.71152,28.53734,41.755,21.44334,2.59654,2056208.157,1.5686,6.25,3,0.166666667,0,"BDS",0 50 | "49",50,-3.76275946979601,"Leigh","No-take","Martins Rock",5,10,0.02412,0.36928,3.84234,35.47341,47.43604,11.88242,0.94092,2056208.157,2.02301,6.25,3,0,0,"BDS",0 51 | "50",51,-2.73005031072124,"Leigh","No-take","Martins Rock",15,11,0.1138,0.29654,4.30909,28.38553,45.81894,19.27934,1.69096,2056208.157,1.96729,6.25,3,0.5,0,"BDS",0 52 | "51",52,-2.5951236391731,"Leigh","No-take","Martins Rock",30,11,0.02907,0.40319,4.49215,28.0394,44.06893,20.4063,2.38205,2056208.157,1.78247,6.25,3,1.666666667,0,"BDS",1 53 | "52",53,-1.06464679909333,"Leigh","No-take","North Te Rere",2,11,0.27939,0.56593,3.50791,18.00861,42.15767,32.48522,2.93661,2360452.152,1.19221,6,6.5,0,0.333333333,"BDS",3 54 | "53",54,-0.653160258065491,"Leigh","No-take","North Te Rere",5,11,0.41073,0.27185,2.51406,15.33177,43.7236,35.31977,2.39786,2360452.152,1.28087,6,6.5,0.5,0,"BDS",0 55 | "54",55,-0.619585462360303,"Leigh","No-take","North Te Rere",15,11,0.13323,0.42549,3.23406,16.07044,40.6862,36.53973,2.85588,2360452.152,1.29972,6,6.5,1,0,"BDS",0 56 | "55",56,-2.77402835693954,"Leigh","No-take","North Te Rere",30,11,0.05078,0.41631,4.72783,29.49734,43.99494,19.31496,1.90023,2360452.152,0.93746,6,6.5,2,0,"BDS",0 57 | "56",57,0.355390254044881,"Leigh","No-take","Waterfall Reef Inner",2,9,0.03553,0.14945,1.69934,8.43427,45.50632,41.89384,2.24519,2508895.523,3.45785,16.5,2.2,0.333333333,0,"BDS",0 58 | "57",58,0.568538691214557,"Leigh","No-take","Waterfall Reef Inner",5,10,0.12963,0.31,2.02569,8.88818,40.12067,45.20053,3.28078,2508895.523,3.19104,16.5,2.2,1,0,"BDS",0 59 | "58",59,-1.48627311528894,"Leigh","No-take","Waterfall Reef Inner",15,9,0.22897,0.89488,5.77361,18.70931,43.13467,29.3059,1.9192,2508895.523,2.80046,16.5,2.2,0,0,"BDS",0 60 | "59",60,-0.807393905757062,"Leigh","No-take","Waterfall Reef Inner",30,10,0.2148,0.63722,4.10023,15.38552,42.20047,34.36158,3.05975,2508895.523,2.78881,16.5,2.2,0.833333333,0,"BDS",0 61 | "60",61,-3.84367434699655,"Leigh","No-take","Waterfall Reef Outer",2,11,0.58359,2.68652,16.51745,33.93586,32.69129,12.99919,0.53339,3011093.187,2.4751,18,6.4,0,0.166666667,"BDS",0 62 | "61",62,-3.90920623658696,"Leigh","No-take","Waterfall Reef Outer",5,11,0.52679,1.92446,13.51472,33.49262,37.6966,12.24732,0.57682,3011093.187,2.62516,18,6.4,0,0.166666667,"BDS",0 63 | "62",63,-0.55533227568735,"Leigh","No-take","Waterfall Reef Outer",15,11,0.05234,0.46582,2.78059,12.73163,46.03989,34.8855,2.83876,3011093.187,1.46117,18,6.4,1,0,"BDS",0 64 | "63",64,-1.50796707046511,"Leigh","No-take","Waterfall Reef Outer",30,11,0.36938,1.12547,6.40814,18.58155,41.45276,28.91518,2.72931,3011093.187,2.43254,18,6.4,0.666666667,0,"BDS",0 65 | "64",65,-2.5847942552301,"Tawharanui","Fished","Fairchilds Reef Inner",2,9,0.05201,0.22015,2.55153,12.67586,67.95722,13.10877,3.37822,1533714.168,1.2051,0,0,0.166666667,0.166666667,"BDS",5 66 | "65",66,-1.43582029568098,"Tawharanui","Fished","Fairchilds Reef Inner",5,11,0.18094,0.42987,2.8099,12.3398,55.46995,24.155,4.55345,1533714.168,1.23181,0,0,0.666666667,0,"BDS",3 67 | "66",67,-2.97934304949557,"Tawharanui","Fished","Fairchilds Reef Inner",15,11,0.27946,1.06845,6.86791,22.15775,51.51732,15.75039,2.32076,1533714.168,1.08227,0,0,0.833333333,0,"BDS",1 68 | "67",68,-2.70088138350947,"Tawharanui","Fished","Fairchilds Reef Inner",30,10,0.28121,0.79511,5.16448,19.48284,53.83944,16.43393,3.95071,1533714.168,1.25514,0,0,1.666666667,0.666666667,"BDS",6 69 | "68",69,-3.84367434699655,"Tawharanui","Fished","Fairchilds Reef Outer ",2,9,0.58359,2.68652,16.51745,33.93586,32.69129,12.99919,0.53339,1605362.745,1.44733,0.5,0,0.666666667,0.166666667,"BDS",4 70 | "69",70,-3.90920623658696,"Tawharanui","Fished","Fairchilds Reef Outer ",5,9,0.52679,1.92446,13.51472,33.49262,37.6966,12.24732,0.57682,1605362.745,1.76953,0.5,0,1.166666667,0,"BDS",0 71 | "70",71,-3.48529768339847,"Tawharanui","Fished","Fairchilds Reef Outer ",15,9,0.07846,0.67026,3.9659,17.63501,64.43407,8.70986,4.17644,1605362.745,1.47504,0.5,0,0.333333333,0,"BDS",1 72 | "71",72,-4.65224862167955,"Tawharanui","Fished","Fairchilds Reef Outer ",30,9,0.50249,1.50349,8.58356,24.98219,55.7242,4.40805,3.7108,1605362.745,1.52358,0.5,0,1,0,"BDS",4 73 | "72",73,5.08128947354295,"Tawharanui","Fished","Omaha P Point",2,10,0.03667,0.08838,0.09621,0.21445,11.10529,86.23807,2.22093,1507785.068,1.2051,0,0.2,2.333333333,0,"BDS",2 74 | "73",74,5.19767578539045,"Tawharanui","Fished","Omaha P Point",5,10,0.03406,0.17169,0.17102,0.26617,8.74041,87.93246,2.67043,1507785.068,1.23181,0,0.2,1.5,0,"BDS",3 75 | "74",75,4.07832818371075,"Tawharanui","Fished","Omaha P Point",15,12,0.19966,0.23035,0.21109,0.69201,19.50415,76.23381,2.92894,1507785.068,1.08227,0,0.2,0.666666667,0.833333333,"BDS",15 76 | "75",76,4.52768610858022,"Tawharanui","Fished","Omaha P Point",30,12,0.25133,0.24386,0.18812,0.27687,16.19131,79.88318,2.94479,1507785.068,1.25514,0,0.2,0,1.333333333,"BDS",11 77 | "76",77,1.895429556155,"Tawharanui","Fished","P Point",2,10,0.2021,0.27843,0.55002,1.20313,46.24932,49.28501,2.21166,1765896.24,1.44733,0.25,0,2.5,0.333333333,"BDS",0 78 | "77",78,2.10786665931251,"Tawharanui","Fished","P Point",5,11,0.05175,0.13214,0.3174,1.06947,45.45778,51.17633,1.76478,1765896.24,1.76953,0.25,0,2.333333333,0.166666667,"BDS",2 79 | "78",79,2.67542076183547,"Tawharanui","Fished","P Point",15,11,0.31045,0.24707,0.38791,0.51053,39.49584,56.87626,2.14601,1765896.24,1.47504,0.25,0,1,2.333333333,"BDS",7 80 | "79",80,3.5618067862818,"Tawharanui","Fished","P Point",30,10,0.34917,0.32516,0.34537,0.45115,27.21525,68.64224,2.62259,1765896.24,1.52358,0.25,0,0.666666667,3.333333333,"BDS",10 81 | "80",81,0.144043883766072,"Tawharanui","No-take","Anchor Bay Inner",2,9,0.0172,0.16441,1.60389,13.46422,38.48872,42.82638,3.37621,1578079.695,1.47032,11.5,2.3,0.833333333,0.166666667,"BDS",1 82 | "81",82,2.60866104398857,"Tawharanui","No-take","Anchor Bay Inner",5,9,0.09914,0.22669,0.66584,1.7289,32.5699,59.95517,4.70474,1578079.695,1.57182,11.5,2.3,1.5,0,"BDS",0 83 | "82",83,0.28958452201254,"Tawharanui","No-take","Anchor Bay Inner",15,9,0.21641,0.25552,2.4296,12.2583,35.94351,44.23642,4.59424,1578079.695,1.45182,11.5,2.3,0.833333333,0.166666667,"BDS",0 84 | "83",84,3.00728780921828,"Tawharanui","No-take","Anchor Bay Inner",30,11,0.89275,0.38038,0.72234,1.9072,24.56114,65.2652,6.21025,1578079.695,1.60961,11.5,2.3,1.5,0.833333333,"BDS",7 85 | "84",85,0.144043883766072,"Tawharanui","No-take","Anchor Bay Outer",2,9,0.0172,0.16441,1.60389,13.46422,38.48872,42.82638,3.37621,1673795.392,2.25229,14.75,2.7,2.333333333,0,"BDS",0 86 | "85",86,0.0702526769607567,"Tawharanui","No-take","Anchor Bay Outer",5,11,0.11489,0.29905,2.44809,14.91019,35.14357,43.63288,3.39309,1673795.392,2.1347,14.75,2.7,1,0.333333333,"BDS",1 87 | "86",87,-1.12264470649672,"Tawharanui","No-take","Anchor Bay Outer",15,11,0.75194,0.75227,3.56621,15.54908,45.62314,30.44547,3.26138,1673795.392,1.77443,14.75,2.7,1,0,"BDS",2 88 | "87",88,-1.54913423238378,"Tawharanui","No-take","Anchor Bay Outer",30,11,0.03504,0.30468,2.44575,17.12,51.71877,25.89944,2.44507,1673795.392,1.68326,14.75,2.7,1.5,0.166666667,"BDS",2 89 | "88",89,1.76634675159096,"Tawharanui","No-take","Comet Rocks East",2,10,0.02577,0.14764,0.27863,0.85935,51.62622,45.75875,1.28493,167069.126,0.89349,13.25,4.4,0.333333333,0.166666667,"BDS",0 90 | "89",90,4.26560226112301,"Tawharanui","No-take","Comet Rocks East",5,10,0.484,0.1518,0.26047,0.57701,17.05321,77.95432,3.48185,167069.126,2.53218,13.25,4.4,2.666666667,0.166666667,"BDS",1 91 | "90",91,4.44916079552009,"Tawharanui","No-take","Comet Rocks East",15,10,0.29139,0.26949,0.35137,0.69191,13.91155,81.14862,3.29827,167069.126,1.9994,13.25,4.4,2.5,0,"BDS",1 92 | "91",92,1.51204481202269,"Tawharanui","No-take","Comet Rocks East",30,10,0.13563,0.07506,0.10935,0.67739,56.4404,40.8114,1.7303,167069.126,1.35509,13.25,4.4,1.666666667,0,"BDS",8 93 | "92",93,2.66281813929873,"Tawharanui","No-take","Comet Rocks West",2,9,0.12925,0.25934,0.4553,0.92908,37.45427,58.79215,1.96145,1764328.193,0.89349,13.5,1,0.333333333,0,"BDS",2 94 | "93",94,2.97744565376185,"Tawharanui","No-take","Comet Rocks West",5,9,0.09885,0.16337,0.33261,1.02094,32.97139,62.97884,2.3959,1764328.193,2.53218,13.5,1,0.666666667,0,"BDS",10 95 | "94",95,3.93757042934683,"Tawharanui","No-take","Comet Rocks West",15,9,0.31471,0.2989,0.38652,0.68277,20.48376,74.76174,3.02879,1764328.193,1.9994,13.5,1,1.666666667,0.666666667,"BDS",14 96 | "95",96,2.7924345819529,"Tawharanui","No-take","Comet Rocks West",30,9,0.38099,0.25801,0.2917,0.49269,38.05801,58.04893,2.44488,1764328.193,1.35509,13.5,1,1.666666667,0.666666667,"BDS",20 97 | "96",1,-3.26250047120576,"Hahei","Fished","Cooks Beach Inner",2,12,3.16462,1.41119,3.88962,8.69694,70.31984,6.19663,6.25038,2232582.478,3.45785,0,0,0,0.166666667,"BMS",6 98 | "97",2,-3.48382799871854,"Hahei","Fished","Cooks Beach Inner",5,12,1.69129,1.62811,4.86726,9.92831,69.18594,5.70317,6.92941,2232582.478,3.19104,0,0,0,0.166666667,"BMS",4 99 | "98",3,-4.68556023608562,"Hahei","Fished","Cooks Beach Inner",15,12,1.67228,1.01193,3.9718,21.37884,64.74207,2.75041,4.42267,2232582.478,2.80046,0,0,0,0.833333333,"BMS",2 100 | "99",4,-3.24865363208507,"Hahei","Fished","Cooks Beach Inner",30,12,0.7967,0.77126,1.82919,7.81927,78.20548,5.26789,5.27693,2232582.478,2.78881,0,0,0.333333333,0.333333333,"BMS",6 101 | "100",5,-3.43280045392667,"Hahei","Fished","Cooks Beach Outer",2,9,0.03768,0.25556,2.09768,15.76419,67.41767,7.21756,7.08857,1027166.867,2.4751,0,0.2,0,0.333333333,"BMS",2 102 | "101",6,-3.61029674834709,"Hahei","Fished","Cooks Beach Outer",5,9,0.23887,0.57024,3.42348,18.22572,62.7775,7.48086,7.17101,1027166.867,2.52552,0,0.2,1,0.166666667,"BMS",4 103 | "102",8,-4.68083976068393,"Hahei","Fished","Cooks Beach Outer",30,9,0.05118,0.41971,2.96787,19.90608,70.82593,2.31633,3.47006,1027166.867,2.30917,0,0.2,0,0.333333333,"BMS",3 104 | "103",9,-2.52024747566287,"Hahei","Fished","Darens Glove",2,10,0.28782,0.61595,4.71152,28.53734,41.755,21.44334,2.59654,2924764.739,0.89349,0,0,0.333333333,0.166666667,"BMS",0 105 | "104",10,-3.76275946979601,"Hahei","Fished","Darens Glove",5,10,0.02412,0.36928,3.84234,35.47341,47.43604,11.88242,0.94092,2924764.739,2.53218,0,0,0.166666667,0,"BMS",0 106 | "105",11,-2.73005031072124,"Hahei","Fished","Darens Glove",15,12,0.1138,0.29654,4.30909,28.38553,45.81894,19.27934,1.69096,2924764.739,1.9994,0,0,0.333333333,0.166666667,"BMS",0 107 | "106",12,-2.5951236391731,"Hahei","Fished","Darens Glove",30,12,0.02907,0.40319,4.49215,28.0394,44.06893,20.4063,2.38205,2924764.739,1.35509,0,0,0.166666667,0.166666667,"BMS",0 108 | "107",13,0.902300815961495,"Hahei","Fished","Hahei Beach",2,10,0,0.10243,0.35882,2.13453,57.49768,38.02565,1.79672,1586607.555,0.89349,0,0,1,0.666666667,"BMS",2 109 | "108",14,1.18945310431574,"Hahei","Fished","Hahei Beach",5,10,0,0.08951,0.4494,1.83101,54.66213,41.28873,1.60292,1586607.555,2.53218,0,0,0.5,1.166666667,"BMS",1 110 | "109",15,0.607427342493815,"Hahei","Fished","Hahei Beach",15,11,0.08406,0.16368,0.62516,2.39488,58.95227,35.41736,2.16995,1586607.555,1.9994,0,0,0.166666667,1.333333333,"BMS",0 111 | "110",16,2.43397161322605,"Hahei","Fished","Hahei Beach",30,11,0.02435,0.1215,0.36851,1.15492,40.06436,55.9278,2.21731,1586607.555,1.35509,0,0,0.5,1,"BMS",1 112 | "111",17,1.76634675159096,"Hahei","No-take","Cooks Bluff",2,11,0.02577,0.14764,0.27863,0.85935,51.62622,45.75875,1.28493,1891848.683,3.45785,1,5.2,5,0.666666667,"BMS",1 113 | "112",18,4.26560226112301,"Hahei","No-take","Cooks Bluff",5,10,0.484,0.1518,0.26047,0.57701,17.05321,77.95432,3.48185,1891848.683,3.19104,1,5.2,2.833333333,0.5,"BMS",0 114 | "113",19,4.44916079552009,"Hahei","No-take","Cooks Bluff",15,11,0.29139,0.26949,0.35137,0.69191,13.91155,81.14862,3.29827,1891848.683,2.80046,1,5.2,2.666666667,1.833333333,"BMS",0 115 | "114",20,1.51204481202269,"Hahei","No-take","Cooks Bluff",30,10,0.13563,0.07506,0.10935,0.67739,56.4404,40.8114,1.7303,1891848.683,2.78881,1,5.2,2,3,"BMS",0 116 | "115",21,2.66281813929873,"Hahei","No-take","Gemstone Bay",2,10,0.12925,0.25934,0.4553,0.92908,37.45427,58.79215,1.96145,714179.309,2.4751,3,3.1,0.166666667,0.333333333,"BMS",0 117 | "116",22,2.97744565376185,"Hahei","No-take","Gemstone Bay",5,10,0.09885,0.16337,0.33261,1.02094,32.97139,62.97884,2.3959,714179.309,2.62516,3,3.1,0.166666667,0.833333333,"BMS",0 118 | "117",23,3.93757042934683,"Hahei","No-take","Gemstone Bay",15,12,0.31471,0.2989,0.38652,0.68277,20.48376,74.76174,3.02879,714179.309,1.46117,3,3.1,0,0.5,"BMS",0 119 | "118",24,2.7924345819529,"Hahei","No-take","Gemstone Bay",30,12,0.38099,0.25801,0.2917,0.49269,38.05801,58.04893,2.44488,714179.309,2.43254,3,3.1,0.166666667,0.166666667,"BMS",0 120 | "119",25,-0.635229212715005,"Hahei","No-take","Small Beach",2,10,0.02319,0.18835,1.7116,13.78138,46.50742,33.25779,4.45335,1287001.874,2.11598,3.5,3.4,3.166666667,0,"BMS",0 121 | "120",26,1.73495808103966,"Hahei","No-take","Small Beach",5,10,0.12589,0.28788,0.84551,2.19563,41.37843,49.12646,5.9772,1287001.874,1.79838,3.5,3.4,5.666666667,0,"BMS",0 122 | "121",27,-0.146778821245627,"Hahei","No-take","Small Beach",15,12,0.33404,0.28913,2.49682,12.51038,38.59031,38.11938,7.56874,1287001.874,1.89852,3.5,3.4,3.166666667,0.666666667,"BMS",0 123 | "122",28,2.13587035941396,"Hahei","No-take","Small Beach",30,10,1.71054,0.63942,1.06989,2.39598,29.64741,53.25704,11.17147,1287001.874,1.45875,3.5,3.4,1.5,2.333333333,"BMS",0 124 | "123",29,-0.635229212715005,"Hahei","No-take","Sting Ray Bay",2,10,0.02319,0.18835,1.7116,13.78138,46.50742,33.25779,4.45335,1859264.29,1.69359,2.5,4.2,2,0.333333333,"BMS",0 125 | "124",30,-0.528400588173357,"Hahei","No-take","Sting Ray Bay",5,9,0.14163,0.35636,2.62002,15.33047,40.86696,36.40414,4.21072,1859264.29,1.58063,2.5,4.2,0.833333333,0.666666667,"BMS",1 126 | "125",31,-1.12264470649672,"Hahei","No-take","Sting Ray Bay",15,10,0.75194,0.75227,3.56621,15.54908,45.62314,30.44547,3.26138,1859264.29,1.34382,2.5,4.2,1.333333333,0.166666667,"BMS",0 127 | "126",32,-1.54913423238378,"Hahei","No-take","Sting Ray Bay",30,10,0.03504,0.30468,2.44575,17.12,51.71877,25.89944,2.44507,1859264.29,1.46188,2.5,4.2,0.166666667,0.333333333,"BMS",0 128 | "127",33,0.196887270736938,"Leigh","Fished","Back Beach Inner",2,10,2.13619,0.94687,2.60188,5.79221,46.98246,37.32462,4.16881,1359605.598,1.65099,0,0,1,0,"BMS",1 129 | "128",34,0.0588924509361409,"Leigh","Fished","Back Beach Inner",5,10,1.1385,1.07565,3.21485,6.59121,46.34551,37.00222,4.58774,1359605.598,1.41871,0,0,0.833333333,0,"BMS",0 130 | "129",35,-1.44135201679684,"Leigh","Fished","Back Beach Inner",15,10,1.05895,0.67031,3.05217,17.94499,46.40404,27.86951,2.96514,1359605.598,1.41097,0,0,0.833333333,0,"BMS",1 131 | "130",36,0.0576192166234346,"Leigh","Fished","Back Beach Inner",30,11,0.55617,0.5318,1.26098,5.41276,54.3806,34.17531,3.65923,1359605.598,1.49807,0,0,0.5,0,"BMS",2 132 | "131",37,0.144043883766072,"Leigh","Fished","Back Beach Outer",2,11,0.0172,0.16441,1.60389,13.46422,38.48872,42.82638,3.37621,1368031.691,2.25229,0,0.2,0.166666667,0,"BMS",0 133 | "132",38,0.0702526769607567,"Leigh","Fished","Back Beach Outer",5,11,0.11489,0.29905,2.44809,14.91019,35.14357,43.63288,3.39309,1368031.691,2.1347,0,0.2,1,0,"BMS",0 134 | "133",39,-1.12264470649672,"Leigh","Fished","Back Beach Outer",15,11,0.75194,0.75227,3.56621,15.54908,45.62314,30.44547,3.26138,1368031.691,1.77443,0,0.2,1,0,"BMS",0 135 | "134",40,-1.54913423238378,"Leigh","Fished","Back Beach Outer",30,11,0.03504,0.30468,2.44575,17.12,51.71877,25.89944,2.44507,1368031.691,1.68326,0,0.2,1.333333333,0,"BMS",0 136 | "135",41,2.52988910136934,"Leigh","Fished","Kemps Beach",2,9,0.06032,0.11541,0.35386,1.34381,37.76823,57.75811,2.38763,1724690.26,2.11598,0.25,0.2,1.333333333,0.166666667,"BMS",2 137 | "136",42,2.71544214580469,"Leigh","Fished","Kemps Beach",5,9,0.0267,0.05602,0.27818,2.00025,33.93311,62.25413,1.34575,1724690.26,1.79838,0.25,0.2,2.833333333,0,"BMS",1 138 | "137",43,1.85911876365729,"Leigh","Fished","Kemps Beach",15,9,0.03187,0.09429,0.57329,3.12982,41.00127,53.51028,1.53533,1724690.26,1.89852,0.25,0.2,5.333333333,0.166666667,"BMS",1 139 | "138",44,4.38791771379999,"Leigh","Fished","Kemps Beach",30,9,0.0296,0.07963,0.24881,0.9705,14.53564,81.20583,2.73175,1724690.26,1.45875,0.25,0.2,2.666666667,0.5,"BMS",3 140 | "139",45,0.372730083146206,"Leigh","Fished","Okakari Point",2,11,0,0.06541,0.21854,1.25939,68.13207,28.95217,1.31392,2171727.514,1.69359,2.5,0.2,1.833333333,1,"BMS",3 141 | "140",46,0.893331150540912,"Leigh","Fished","Okakari Point",5,11,0,0.05269,0.24186,1.0379,62.66552,34.70308,1.2284,2171727.514,1.58063,2.5,0.2,2.5,0,"BMS",3 142 | "141",47,-1.18917401378654,"Leigh","Fished","Okakari Point",15,11,0.03408,0.06391,0.23056,0.86855,85.93579,12.03784,0.76024,2171727.514,1.34382,2.5,0.2,4,0,"BMS",9 143 | "142",48,2.02051421815913,"Leigh","Fished","Okakari Point",30,12,0.02035,0.10552,0.31355,0.97941,47.03216,49.51637,1.92334,2171727.514,1.46188,2.5,0.2,5.333333333,0.166666667,"BMS",9 144 | "143",49,-2.52024747566287,"Leigh","No-take","Martins Rock",2,10,0.28782,0.61595,4.71152,28.53734,41.755,21.44334,2.59654,2056208.157,1.5686,6.25,3,0.166666667,0,"BMS",0 145 | "144",50,-3.76275946979601,"Leigh","No-take","Martins Rock",5,10,0.02412,0.36928,3.84234,35.47341,47.43604,11.88242,0.94092,2056208.157,2.02301,6.25,3,0,0,"BMS",0 146 | "145",51,-2.73005031072124,"Leigh","No-take","Martins Rock",15,11,0.1138,0.29654,4.30909,28.38553,45.81894,19.27934,1.69096,2056208.157,1.96729,6.25,3,0.5,0,"BMS",0 147 | "146",52,-2.5951236391731,"Leigh","No-take","Martins Rock",30,11,0.02907,0.40319,4.49215,28.0394,44.06893,20.4063,2.38205,2056208.157,1.78247,6.25,3,1.666666667,0,"BMS",0 148 | "147",53,-1.06464679909333,"Leigh","No-take","North Te Rere",2,11,0.27939,0.56593,3.50791,18.00861,42.15767,32.48522,2.93661,2360452.152,1.19221,6,6.5,0,0.333333333,"BMS",0 149 | "148",54,-0.653160258065491,"Leigh","No-take","North Te Rere",5,11,0.41073,0.27185,2.51406,15.33177,43.7236,35.31977,2.39786,2360452.152,1.28087,6,6.5,0.5,0,"BMS",0 150 | "149",55,-0.619585462360303,"Leigh","No-take","North Te Rere",15,11,0.13323,0.42549,3.23406,16.07044,40.6862,36.53973,2.85588,2360452.152,1.29972,6,6.5,1,0,"BMS",0 151 | "150",56,-2.77402835693954,"Leigh","No-take","North Te Rere",30,11,0.05078,0.41631,4.72783,29.49734,43.99494,19.31496,1.90023,2360452.152,0.93746,6,6.5,2,0,"BMS",0 152 | "151",57,0.355390254044881,"Leigh","No-take","Waterfall Reef Inner",2,9,0.03553,0.14945,1.69934,8.43427,45.50632,41.89384,2.24519,2508895.523,3.45785,16.5,2.2,0.333333333,0,"BMS",0 153 | "152",58,0.568538691214557,"Leigh","No-take","Waterfall Reef Inner",5,10,0.12963,0.31,2.02569,8.88818,40.12067,45.20053,3.28078,2508895.523,3.19104,16.5,2.2,1,0,"BMS",0 154 | "153",59,-1.48627311528894,"Leigh","No-take","Waterfall Reef Inner",15,9,0.22897,0.89488,5.77361,18.70931,43.13467,29.3059,1.9192,2508895.523,2.80046,16.5,2.2,0,0,"BMS",0 155 | "154",60,-0.807393905757062,"Leigh","No-take","Waterfall Reef Inner",30,10,0.2148,0.63722,4.10023,15.38552,42.20047,34.36158,3.05975,2508895.523,2.78881,16.5,2.2,0.833333333,0,"BMS",0 156 | "155",61,-3.84367434699655,"Leigh","No-take","Waterfall Reef Outer",2,11,0.58359,2.68652,16.51745,33.93586,32.69129,12.99919,0.53339,3011093.187,2.4751,18,6.4,0,0.166666667,"BMS",0 157 | "156",62,-3.90920623658696,"Leigh","No-take","Waterfall Reef Outer",5,11,0.52679,1.92446,13.51472,33.49262,37.6966,12.24732,0.57682,3011093.187,2.62516,18,6.4,0,0.166666667,"BMS",0 158 | "157",63,-0.55533227568735,"Leigh","No-take","Waterfall Reef Outer",15,11,0.05234,0.46582,2.78059,12.73163,46.03989,34.8855,2.83876,3011093.187,1.46117,18,6.4,1,0,"BMS",0 159 | "158",64,-1.50796707046511,"Leigh","No-take","Waterfall Reef Outer",30,11,0.36938,1.12547,6.40814,18.58155,41.45276,28.91518,2.72931,3011093.187,2.43254,18,6.4,0.666666667,0,"BMS",0 160 | "159",65,-2.5847942552301,"Tawharanui","Fished","Fairchilds Reef Inner",2,9,0.05201,0.22015,2.55153,12.67586,67.95722,13.10877,3.37822,1533714.168,1.2051,0,0,0.166666667,0.166666667,"BMS",0 161 | "160",66,-1.43582029568098,"Tawharanui","Fished","Fairchilds Reef Inner",5,11,0.18094,0.42987,2.8099,12.3398,55.46995,24.155,4.55345,1533714.168,1.23181,0,0,0.666666667,0,"BMS",3 162 | "161",67,-2.97934304949557,"Tawharanui","Fished","Fairchilds Reef Inner",15,11,0.27946,1.06845,6.86791,22.15775,51.51732,15.75039,2.32076,1533714.168,1.08227,0,0,0.833333333,0,"BMS",0 163 | "162",68,-2.70088138350947,"Tawharanui","Fished","Fairchilds Reef Inner",30,10,0.28121,0.79511,5.16448,19.48284,53.83944,16.43393,3.95071,1533714.168,1.25514,0,0,1.666666667,0.666666667,"BMS",1 164 | "163",69,-3.84367434699655,"Tawharanui","Fished","Fairchilds Reef Outer ",2,9,0.58359,2.68652,16.51745,33.93586,32.69129,12.99919,0.53339,1605362.745,1.44733,0.5,0,0.666666667,0.166666667,"BMS",1 165 | "164",70,-3.90920623658696,"Tawharanui","Fished","Fairchilds Reef Outer ",5,9,0.52679,1.92446,13.51472,33.49262,37.6966,12.24732,0.57682,1605362.745,1.76953,0.5,0,1.166666667,0,"BMS",1 166 | "165",71,-3.48529768339847,"Tawharanui","Fished","Fairchilds Reef Outer ",15,9,0.07846,0.67026,3.9659,17.63501,64.43407,8.70986,4.17644,1605362.745,1.47504,0.5,0,0.333333333,0,"BMS",0 167 | "166",72,-4.65224862167955,"Tawharanui","Fished","Fairchilds Reef Outer ",30,9,0.50249,1.50349,8.58356,24.98219,55.7242,4.40805,3.7108,1605362.745,1.52358,0.5,0,1,0,"BMS",5 168 | "167",73,5.08128947354295,"Tawharanui","Fished","Omaha P Point",2,10,0.03667,0.08838,0.09621,0.21445,11.10529,86.23807,2.22093,1507785.068,1.2051,0,0.2,2.333333333,0,"BMS",0 169 | "168",74,5.19767578539045,"Tawharanui","Fished","Omaha P Point",5,10,0.03406,0.17169,0.17102,0.26617,8.74041,87.93246,2.67043,1507785.068,1.23181,0,0.2,1.5,0,"BMS",2 170 | "169",75,4.07832818371075,"Tawharanui","Fished","Omaha P Point",15,12,0.19966,0.23035,0.21109,0.69201,19.50415,76.23381,2.92894,1507785.068,1.08227,0,0.2,0.666666667,0.833333333,"BMS",5 171 | "170",76,4.52768610858022,"Tawharanui","Fished","Omaha P Point",30,12,0.25133,0.24386,0.18812,0.27687,16.19131,79.88318,2.94479,1507785.068,1.25514,0,0.2,0,1.333333333,"BMS",3 172 | "171",77,1.895429556155,"Tawharanui","Fished","P Point",2,10,0.2021,0.27843,0.55002,1.20313,46.24932,49.28501,2.21166,1765896.24,1.44733,0.25,0,2.5,0.333333333,"BMS",0 173 | "172",78,2.10786665931251,"Tawharanui","Fished","P Point",5,11,0.05175,0.13214,0.3174,1.06947,45.45778,51.17633,1.76478,1765896.24,1.76953,0.25,0,2.333333333,0.166666667,"BMS",2 174 | "173",79,2.67542076183547,"Tawharanui","Fished","P Point",15,11,0.31045,0.24707,0.38791,0.51053,39.49584,56.87626,2.14601,1765896.24,1.47504,0.25,0,1,2.333333333,"BMS",6 175 | "174",80,3.5618067862818,"Tawharanui","Fished","P Point",30,10,0.34917,0.32516,0.34537,0.45115,27.21525,68.64224,2.62259,1765896.24,1.52358,0.25,0,0.666666667,3.333333333,"BMS",4 176 | "175",81,0.144043883766072,"Tawharanui","No-take","Anchor Bay Inner",2,9,0.0172,0.16441,1.60389,13.46422,38.48872,42.82638,3.37621,1578079.695,1.47032,11.5,2.3,0.833333333,0.166666667,"BMS",2 177 | "176",82,2.60866104398857,"Tawharanui","No-take","Anchor Bay Inner",5,9,0.09914,0.22669,0.66584,1.7289,32.5699,59.95517,4.70474,1578079.695,1.57182,11.5,2.3,1.5,0,"BMS",0 178 | "177",83,0.28958452201254,"Tawharanui","No-take","Anchor Bay Inner",15,9,0.21641,0.25552,2.4296,12.2583,35.94351,44.23642,4.59424,1578079.695,1.45182,11.5,2.3,0.833333333,0.166666667,"BMS",1 179 | "178",84,3.00728780921828,"Tawharanui","No-take","Anchor Bay Inner",30,11,0.89275,0.38038,0.72234,1.9072,24.56114,65.2652,6.21025,1578079.695,1.60961,11.5,2.3,1.5,0.833333333,"BMS",2 180 | "179",85,0.144043883766072,"Tawharanui","No-take","Anchor Bay Outer",2,9,0.0172,0.16441,1.60389,13.46422,38.48872,42.82638,3.37621,1673795.392,2.25229,14.75,2.7,2.333333333,0,"BMS",1 181 | "180",86,0.0702526769607567,"Tawharanui","No-take","Anchor Bay Outer",5,11,0.11489,0.29905,2.44809,14.91019,35.14357,43.63288,3.39309,1673795.392,2.1347,14.75,2.7,1,0.333333333,"BMS",3 182 | "181",87,-1.12264470649672,"Tawharanui","No-take","Anchor Bay Outer",15,11,0.75194,0.75227,3.56621,15.54908,45.62314,30.44547,3.26138,1673795.392,1.77443,14.75,2.7,1,0,"BMS",0 183 | "182",88,-1.54913423238378,"Tawharanui","No-take","Anchor Bay Outer",30,11,0.03504,0.30468,2.44575,17.12,51.71877,25.89944,2.44507,1673795.392,1.68326,14.75,2.7,1.5,0.166666667,"BMS",2 184 | "183",89,1.76634675159096,"Tawharanui","No-take","Comet Rocks East",2,10,0.02577,0.14764,0.27863,0.85935,51.62622,45.75875,1.28493,167069.126,0.89349,13.25,4.4,0.333333333,0.166666667,"BMS",0 185 | "184",90,4.26560226112301,"Tawharanui","No-take","Comet Rocks East",5,10,0.484,0.1518,0.26047,0.57701,17.05321,77.95432,3.48185,167069.126,2.53218,13.25,4.4,2.666666667,0.166666667,"BMS",0 186 | "185",91,4.44916079552009,"Tawharanui","No-take","Comet Rocks East",15,10,0.29139,0.26949,0.35137,0.69191,13.91155,81.14862,3.29827,167069.126,1.9994,13.25,4.4,2.5,0,"BMS",0 187 | "186",92,1.51204481202269,"Tawharanui","No-take","Comet Rocks East",30,10,0.13563,0.07506,0.10935,0.67739,56.4404,40.8114,1.7303,167069.126,1.35509,13.25,4.4,1.666666667,0,"BMS",0 188 | "187",93,2.66281813929873,"Tawharanui","No-take","Comet Rocks West",2,9,0.12925,0.25934,0.4553,0.92908,37.45427,58.79215,1.96145,1764328.193,0.89349,13.5,1,0.333333333,0,"BMS",0 189 | "188",94,2.97744565376185,"Tawharanui","No-take","Comet Rocks West",5,9,0.09885,0.16337,0.33261,1.02094,32.97139,62.97884,2.3959,1764328.193,2.53218,13.5,1,0.666666667,0,"BMS",6 190 | "189",95,3.93757042934683,"Tawharanui","No-take","Comet Rocks West",15,9,0.31471,0.2989,0.38652,0.68277,20.48376,74.76174,3.02879,1764328.193,1.9994,13.5,1,1.666666667,0.666666667,"BMS",2 191 | "190",96,2.7924345819529,"Tawharanui","No-take","Comet Rocks West",30,9,0.38099,0.25801,0.2917,0.49269,38.05801,58.04893,2.44488,1764328.193,1.35509,13.5,1,1.666666667,0.666666667,"BMS",2 192 | "191",1,-3.26250047120576,"Hahei","Fished","Cooks Beach Inner",2,12,3.16462,1.41119,3.88962,8.69694,70.31984,6.19663,6.25038,2232582.478,3.45785,0,0,0,0.166666667,"CPN",3 193 | "192",2,-3.48382799871854,"Hahei","Fished","Cooks Beach Inner",5,12,1.69129,1.62811,4.86726,9.92831,69.18594,5.70317,6.92941,2232582.478,3.19104,0,0,0,0.166666667,"CPN",11 194 | "193",3,-4.68556023608562,"Hahei","Fished","Cooks Beach Inner",15,12,1.67228,1.01193,3.9718,21.37884,64.74207,2.75041,4.42267,2232582.478,2.80046,0,0,0,0.833333333,"CPN",0 195 | "194",4,-3.24865363208507,"Hahei","Fished","Cooks Beach Inner",30,12,0.7967,0.77126,1.82919,7.81927,78.20548,5.26789,5.27693,2232582.478,2.78881,0,0,0.333333333,0.333333333,"CPN",3 196 | "195",5,-3.43280045392667,"Hahei","Fished","Cooks Beach Outer",2,9,0.03768,0.25556,2.09768,15.76419,67.41767,7.21756,7.08857,1027166.867,2.4751,0,0.2,0,0.333333333,"CPN",3 197 | "196",6,-3.61029674834709,"Hahei","Fished","Cooks Beach Outer",5,9,0.23887,0.57024,3.42348,18.22572,62.7775,7.48086,7.17101,1027166.867,2.52552,0,0.2,1,0.166666667,"CPN",4 198 | "197",8,-4.68083976068393,"Hahei","Fished","Cooks Beach Outer",30,9,0.05118,0.41971,2.96787,19.90608,70.82593,2.31633,3.47006,1027166.867,2.30917,0,0.2,0,0.333333333,"CPN",1 199 | "198",9,-2.52024747566287,"Hahei","Fished","Darens Glove",2,10,0.28782,0.61595,4.71152,28.53734,41.755,21.44334,2.59654,2924764.739,0.89349,0,0,0.333333333,0.166666667,"CPN",6 200 | "199",10,-3.76275946979601,"Hahei","Fished","Darens Glove",5,10,0.02412,0.36928,3.84234,35.47341,47.43604,11.88242,0.94092,2924764.739,2.53218,0,0,0.166666667,0,"CPN",5 201 | "200",11,-2.73005031072124,"Hahei","Fished","Darens Glove",15,12,0.1138,0.29654,4.30909,28.38553,45.81894,19.27934,1.69096,2924764.739,1.9994,0,0,0.333333333,0.166666667,"CPN",1 202 | "201",12,-2.5951236391731,"Hahei","Fished","Darens Glove",30,12,0.02907,0.40319,4.49215,28.0394,44.06893,20.4063,2.38205,2924764.739,1.35509,0,0,0.166666667,0.166666667,"CPN",1 203 | "202",13,0.902300815961495,"Hahei","Fished","Hahei Beach",2,10,0,0.10243,0.35882,2.13453,57.49768,38.02565,1.79672,1586607.555,0.89349,0,0,1,0.666666667,"CPN",1 204 | "203",14,1.18945310431574,"Hahei","Fished","Hahei Beach",5,10,0,0.08951,0.4494,1.83101,54.66213,41.28873,1.60292,1586607.555,2.53218,0,0,0.5,1.166666667,"CPN",2 205 | "204",15,0.607427342493815,"Hahei","Fished","Hahei Beach",15,11,0.08406,0.16368,0.62516,2.39488,58.95227,35.41736,2.16995,1586607.555,1.9994,0,0,0.166666667,1.333333333,"CPN",1 206 | "205",16,2.43397161322605,"Hahei","Fished","Hahei Beach",30,11,0.02435,0.1215,0.36851,1.15492,40.06436,55.9278,2.21731,1586607.555,1.35509,0,0,0.5,1,"CPN",6 207 | "206",17,1.76634675159096,"Hahei","No-take","Cooks Bluff",2,11,0.02577,0.14764,0.27863,0.85935,51.62622,45.75875,1.28493,1891848.683,3.45785,1,5.2,5,0.666666667,"CPN",1 208 | "207",18,4.26560226112301,"Hahei","No-take","Cooks Bluff",5,10,0.484,0.1518,0.26047,0.57701,17.05321,77.95432,3.48185,1891848.683,3.19104,1,5.2,2.833333333,0.5,"CPN",1 209 | "208",19,4.44916079552009,"Hahei","No-take","Cooks Bluff",15,11,0.29139,0.26949,0.35137,0.69191,13.91155,81.14862,3.29827,1891848.683,2.80046,1,5.2,2.666666667,1.833333333,"CPN",3 210 | "209",20,1.51204481202269,"Hahei","No-take","Cooks Bluff",30,10,0.13563,0.07506,0.10935,0.67739,56.4404,40.8114,1.7303,1891848.683,2.78881,1,5.2,2,3,"CPN",1 211 | "210",21,2.66281813929873,"Hahei","No-take","Gemstone Bay",2,10,0.12925,0.25934,0.4553,0.92908,37.45427,58.79215,1.96145,714179.309,2.4751,3,3.1,0.166666667,0.333333333,"CPN",9 212 | "211",22,2.97744565376185,"Hahei","No-take","Gemstone Bay",5,10,0.09885,0.16337,0.33261,1.02094,32.97139,62.97884,2.3959,714179.309,2.62516,3,3.1,0.166666667,0.833333333,"CPN",16 213 | "212",23,3.93757042934683,"Hahei","No-take","Gemstone Bay",15,12,0.31471,0.2989,0.38652,0.68277,20.48376,74.76174,3.02879,714179.309,1.46117,3,3.1,0,0.5,"CPN",12 214 | "213",24,2.7924345819529,"Hahei","No-take","Gemstone Bay",30,12,0.38099,0.25801,0.2917,0.49269,38.05801,58.04893,2.44488,714179.309,2.43254,3,3.1,0.166666667,0.166666667,"CPN",11 215 | "214",25,-0.635229212715005,"Hahei","No-take","Small Beach",2,10,0.02319,0.18835,1.7116,13.78138,46.50742,33.25779,4.45335,1287001.874,2.11598,3.5,3.4,3.166666667,0,"CPN",3 216 | "215",26,1.73495808103966,"Hahei","No-take","Small Beach",5,10,0.12589,0.28788,0.84551,2.19563,41.37843,49.12646,5.9772,1287001.874,1.79838,3.5,3.4,5.666666667,0,"CPN",2 217 | "216",27,-0.146778821245627,"Hahei","No-take","Small Beach",15,12,0.33404,0.28913,2.49682,12.51038,38.59031,38.11938,7.56874,1287001.874,1.89852,3.5,3.4,3.166666667,0.666666667,"CPN",0 218 | "217",28,2.13587035941396,"Hahei","No-take","Small Beach",30,10,1.71054,0.63942,1.06989,2.39598,29.64741,53.25704,11.17147,1287001.874,1.45875,3.5,3.4,1.5,2.333333333,"CPN",0 219 | "218",29,-0.635229212715005,"Hahei","No-take","Sting Ray Bay",2,10,0.02319,0.18835,1.7116,13.78138,46.50742,33.25779,4.45335,1859264.29,1.69359,2.5,4.2,2,0.333333333,"CPN",4 220 | "219",30,-0.528400588173357,"Hahei","No-take","Sting Ray Bay",5,9,0.14163,0.35636,2.62002,15.33047,40.86696,36.40414,4.21072,1859264.29,1.58063,2.5,4.2,0.833333333,0.666666667,"CPN",1 221 | "220",31,-1.12264470649672,"Hahei","No-take","Sting Ray Bay",15,10,0.75194,0.75227,3.56621,15.54908,45.62314,30.44547,3.26138,1859264.29,1.34382,2.5,4.2,1.333333333,0.166666667,"CPN",8 222 | "221",32,-1.54913423238378,"Hahei","No-take","Sting Ray Bay",30,10,0.03504,0.30468,2.44575,17.12,51.71877,25.89944,2.44507,1859264.29,1.46188,2.5,4.2,0.166666667,0.333333333,"CPN",12 223 | "222",33,0.196887270736938,"Leigh","Fished","Back Beach Inner",2,10,2.13619,0.94687,2.60188,5.79221,46.98246,37.32462,4.16881,1359605.598,1.65099,0,0,1,0,"CPN",3 224 | "223",34,0.0588924509361409,"Leigh","Fished","Back Beach Inner",5,10,1.1385,1.07565,3.21485,6.59121,46.34551,37.00222,4.58774,1359605.598,1.41871,0,0,0.833333333,0,"CPN",12 225 | "224",35,-1.44135201679684,"Leigh","Fished","Back Beach Inner",15,10,1.05895,0.67031,3.05217,17.94499,46.40404,27.86951,2.96514,1359605.598,1.41097,0,0,0.833333333,0,"CPN",12 226 | "225",36,0.0576192166234346,"Leigh","Fished","Back Beach Inner",30,11,0.55617,0.5318,1.26098,5.41276,54.3806,34.17531,3.65923,1359605.598,1.49807,0,0,0.5,0,"CPN",24 227 | "226",37,0.144043883766072,"Leigh","Fished","Back Beach Outer",2,11,0.0172,0.16441,1.60389,13.46422,38.48872,42.82638,3.37621,1368031.691,2.25229,0,0.2,0.166666667,0,"CPN",14 228 | "227",38,0.0702526769607567,"Leigh","Fished","Back Beach Outer",5,11,0.11489,0.29905,2.44809,14.91019,35.14357,43.63288,3.39309,1368031.691,2.1347,0,0.2,1,0,"CPN",14 229 | "228",39,-1.12264470649672,"Leigh","Fished","Back Beach Outer",15,11,0.75194,0.75227,3.56621,15.54908,45.62314,30.44547,3.26138,1368031.691,1.77443,0,0.2,1,0,"CPN",4 230 | "229",40,-1.54913423238378,"Leigh","Fished","Back Beach Outer",30,11,0.03504,0.30468,2.44575,17.12,51.71877,25.89944,2.44507,1368031.691,1.68326,0,0.2,1.333333333,0,"CPN",0 231 | "230",41,2.52988910136934,"Leigh","Fished","Kemps Beach",2,9,0.06032,0.11541,0.35386,1.34381,37.76823,57.75811,2.38763,1724690.26,2.11598,0.25,0.2,1.333333333,0.166666667,"CPN",18 232 | "231",42,2.71544214580469,"Leigh","Fished","Kemps Beach",5,9,0.0267,0.05602,0.27818,2.00025,33.93311,62.25413,1.34575,1724690.26,1.79838,0.25,0.2,2.833333333,0,"CPN",16 233 | "232",43,1.85911876365729,"Leigh","Fished","Kemps Beach",15,9,0.03187,0.09429,0.57329,3.12982,41.00127,53.51028,1.53533,1724690.26,1.89852,0.25,0.2,5.333333333,0.166666667,"CPN",6 234 | "233",44,4.38791771379999,"Leigh","Fished","Kemps Beach",30,9,0.0296,0.07963,0.24881,0.9705,14.53564,81.20583,2.73175,1724690.26,1.45875,0.25,0.2,2.666666667,0.5,"CPN",1 235 | "234",45,0.372730083146206,"Leigh","Fished","Okakari Point",2,11,0,0.06541,0.21854,1.25939,68.13207,28.95217,1.31392,2171727.514,1.69359,2.5,0.2,1.833333333,1,"CPN",2 236 | "235",46,0.893331150540912,"Leigh","Fished","Okakari Point",5,11,0,0.05269,0.24186,1.0379,62.66552,34.70308,1.2284,2171727.514,1.58063,2.5,0.2,2.5,0,"CPN",8 237 | "236",47,-1.18917401378654,"Leigh","Fished","Okakari Point",15,11,0.03408,0.06391,0.23056,0.86855,85.93579,12.03784,0.76024,2171727.514,1.34382,2.5,0.2,4,0,"CPN",1 238 | "237",48,2.02051421815913,"Leigh","Fished","Okakari Point",30,12,0.02035,0.10552,0.31355,0.97941,47.03216,49.51637,1.92334,2171727.514,1.46188,2.5,0.2,5.333333333,0.166666667,"CPN",8 239 | "238",49,-2.52024747566287,"Leigh","No-take","Martins Rock",2,10,0.28782,0.61595,4.71152,28.53734,41.755,21.44334,2.59654,2056208.157,1.5686,6.25,3,0.166666667,0,"CPN",2 240 | "239",50,-3.76275946979601,"Leigh","No-take","Martins Rock",5,10,0.02412,0.36928,3.84234,35.47341,47.43604,11.88242,0.94092,2056208.157,2.02301,6.25,3,0,0,"CPN",7 241 | "240",51,-2.73005031072124,"Leigh","No-take","Martins Rock",15,11,0.1138,0.29654,4.30909,28.38553,45.81894,19.27934,1.69096,2056208.157,1.96729,6.25,3,0.5,0,"CPN",2 242 | "241",52,-2.5951236391731,"Leigh","No-take","Martins Rock",30,11,0.02907,0.40319,4.49215,28.0394,44.06893,20.4063,2.38205,2056208.157,1.78247,6.25,3,1.666666667,0,"CPN",0 243 | "242",53,-1.06464679909333,"Leigh","No-take","North Te Rere",2,11,0.27939,0.56593,3.50791,18.00861,42.15767,32.48522,2.93661,2360452.152,1.19221,6,6.5,0,0.333333333,"CPN",1 244 | "243",54,-0.653160258065491,"Leigh","No-take","North Te Rere",5,11,0.41073,0.27185,2.51406,15.33177,43.7236,35.31977,2.39786,2360452.152,1.28087,6,6.5,0.5,0,"CPN",3 245 | "244",55,-0.619585462360303,"Leigh","No-take","North Te Rere",15,11,0.13323,0.42549,3.23406,16.07044,40.6862,36.53973,2.85588,2360452.152,1.29972,6,6.5,1,0,"CPN",3 246 | "245",56,-2.77402835693954,"Leigh","No-take","North Te Rere",30,11,0.05078,0.41631,4.72783,29.49734,43.99494,19.31496,1.90023,2360452.152,0.93746,6,6.5,2,0,"CPN",0 247 | "246",57,0.355390254044881,"Leigh","No-take","Waterfall Reef Inner",2,9,0.03553,0.14945,1.69934,8.43427,45.50632,41.89384,2.24519,2508895.523,3.45785,16.5,2.2,0.333333333,0,"CPN",5 248 | "247",58,0.568538691214557,"Leigh","No-take","Waterfall Reef Inner",5,10,0.12963,0.31,2.02569,8.88818,40.12067,45.20053,3.28078,2508895.523,3.19104,16.5,2.2,1,0,"CPN",4 249 | "248",59,-1.48627311528894,"Leigh","No-take","Waterfall Reef Inner",15,9,0.22897,0.89488,5.77361,18.70931,43.13467,29.3059,1.9192,2508895.523,2.80046,16.5,2.2,0,0,"CPN",4 250 | "249",60,-0.807393905757062,"Leigh","No-take","Waterfall Reef Inner",30,10,0.2148,0.63722,4.10023,15.38552,42.20047,34.36158,3.05975,2508895.523,2.78881,16.5,2.2,0.833333333,0,"CPN",6 251 | "250",61,-3.84367434699655,"Leigh","No-take","Waterfall Reef Outer",2,11,0.58359,2.68652,16.51745,33.93586,32.69129,12.99919,0.53339,3011093.187,2.4751,18,6.4,0,0.166666667,"CPN",1 252 | "251",62,-3.90920623658696,"Leigh","No-take","Waterfall Reef Outer",5,11,0.52679,1.92446,13.51472,33.49262,37.6966,12.24732,0.57682,3011093.187,2.62516,18,6.4,0,0.166666667,"CPN",0 253 | "252",63,-0.55533227568735,"Leigh","No-take","Waterfall Reef Outer",15,11,0.05234,0.46582,2.78059,12.73163,46.03989,34.8855,2.83876,3011093.187,1.46117,18,6.4,1,0,"CPN",0 254 | "253",64,-1.50796707046511,"Leigh","No-take","Waterfall Reef Outer",30,11,0.36938,1.12547,6.40814,18.58155,41.45276,28.91518,2.72931,3011093.187,2.43254,18,6.4,0.666666667,0,"CPN",0 255 | "254",65,-2.5847942552301,"Tawharanui","Fished","Fairchilds Reef Inner",2,9,0.05201,0.22015,2.55153,12.67586,67.95722,13.10877,3.37822,1533714.168,1.2051,0,0,0.166666667,0.166666667,"CPN",3 256 | "255",66,-1.43582029568098,"Tawharanui","Fished","Fairchilds Reef Inner",5,11,0.18094,0.42987,2.8099,12.3398,55.46995,24.155,4.55345,1533714.168,1.23181,0,0,0.666666667,0,"CPN",3 257 | "256",67,-2.97934304949557,"Tawharanui","Fished","Fairchilds Reef Inner",15,11,0.27946,1.06845,6.86791,22.15775,51.51732,15.75039,2.32076,1533714.168,1.08227,0,0,0.833333333,0,"CPN",2 258 | "257",68,-2.70088138350947,"Tawharanui","Fished","Fairchilds Reef Inner",30,10,0.28121,0.79511,5.16448,19.48284,53.83944,16.43393,3.95071,1533714.168,1.25514,0,0,1.666666667,0.666666667,"CPN",0 259 | "258",69,-3.84367434699655,"Tawharanui","Fished","Fairchilds Reef Outer ",2,9,0.58359,2.68652,16.51745,33.93586,32.69129,12.99919,0.53339,1605362.745,1.44733,0.5,0,0.666666667,0.166666667,"CPN",1 260 | "259",70,-3.90920623658696,"Tawharanui","Fished","Fairchilds Reef Outer ",5,9,0.52679,1.92446,13.51472,33.49262,37.6966,12.24732,0.57682,1605362.745,1.76953,0.5,0,1.166666667,0,"CPN",0 261 | "260",71,-3.48529768339847,"Tawharanui","Fished","Fairchilds Reef Outer ",15,9,0.07846,0.67026,3.9659,17.63501,64.43407,8.70986,4.17644,1605362.745,1.47504,0.5,0,0.333333333,0,"CPN",0 262 | "261",72,-4.65224862167955,"Tawharanui","Fished","Fairchilds Reef Outer ",30,9,0.50249,1.50349,8.58356,24.98219,55.7242,4.40805,3.7108,1605362.745,1.52358,0.5,0,1,0,"CPN",0 263 | "262",73,5.08128947354295,"Tawharanui","Fished","Omaha P Point",2,10,0.03667,0.08838,0.09621,0.21445,11.10529,86.23807,2.22093,1507785.068,1.2051,0,0.2,2.333333333,0,"CPN",17 264 | "263",74,5.19767578539045,"Tawharanui","Fished","Omaha P Point",5,10,0.03406,0.17169,0.17102,0.26617,8.74041,87.93246,2.67043,1507785.068,1.23181,0,0.2,1.5,0,"CPN",4 265 | "264",75,4.07832818371075,"Tawharanui","Fished","Omaha P Point",15,12,0.19966,0.23035,0.21109,0.69201,19.50415,76.23381,2.92894,1507785.068,1.08227,0,0.2,0.666666667,0.833333333,"CPN",4 266 | "265",76,4.52768610858022,"Tawharanui","Fished","Omaha P Point",30,12,0.25133,0.24386,0.18812,0.27687,16.19131,79.88318,2.94479,1507785.068,1.25514,0,0.2,0,1.333333333,"CPN",4 267 | "266",77,1.895429556155,"Tawharanui","Fished","P Point",2,10,0.2021,0.27843,0.55002,1.20313,46.24932,49.28501,2.21166,1765896.24,1.44733,0.25,0,2.5,0.333333333,"CPN",2 268 | "267",78,2.10786665931251,"Tawharanui","Fished","P Point",5,11,0.05175,0.13214,0.3174,1.06947,45.45778,51.17633,1.76478,1765896.24,1.76953,0.25,0,2.333333333,0.166666667,"CPN",1 269 | "268",79,2.67542076183547,"Tawharanui","Fished","P Point",15,11,0.31045,0.24707,0.38791,0.51053,39.49584,56.87626,2.14601,1765896.24,1.47504,0.25,0,1,2.333333333,"CPN",1 270 | "269",80,3.5618067862818,"Tawharanui","Fished","P Point",30,10,0.34917,0.32516,0.34537,0.45115,27.21525,68.64224,2.62259,1765896.24,1.52358,0.25,0,0.666666667,3.333333333,"CPN",1 271 | "270",81,0.144043883766072,"Tawharanui","No-take","Anchor Bay Inner",2,9,0.0172,0.16441,1.60389,13.46422,38.48872,42.82638,3.37621,1578079.695,1.47032,11.5,2.3,0.833333333,0.166666667,"CPN",0 272 | "271",82,2.60866104398857,"Tawharanui","No-take","Anchor Bay Inner",5,9,0.09914,0.22669,0.66584,1.7289,32.5699,59.95517,4.70474,1578079.695,1.57182,11.5,2.3,1.5,0,"CPN",4 273 | "272",83,0.28958452201254,"Tawharanui","No-take","Anchor Bay Inner",15,9,0.21641,0.25552,2.4296,12.2583,35.94351,44.23642,4.59424,1578079.695,1.45182,11.5,2.3,0.833333333,0.166666667,"CPN",1 274 | "273",84,3.00728780921828,"Tawharanui","No-take","Anchor Bay Inner",30,11,0.89275,0.38038,0.72234,1.9072,24.56114,65.2652,6.21025,1578079.695,1.60961,11.5,2.3,1.5,0.833333333,"CPN",0 275 | "274",85,0.144043883766072,"Tawharanui","No-take","Anchor Bay Outer",2,9,0.0172,0.16441,1.60389,13.46422,38.48872,42.82638,3.37621,1673795.392,2.25229,14.75,2.7,2.333333333,0,"CPN",1 276 | "275",86,0.0702526769607567,"Tawharanui","No-take","Anchor Bay Outer",5,11,0.11489,0.29905,2.44809,14.91019,35.14357,43.63288,3.39309,1673795.392,2.1347,14.75,2.7,1,0.333333333,"CPN",0 277 | "276",87,-1.12264470649672,"Tawharanui","No-take","Anchor Bay Outer",15,11,0.75194,0.75227,3.56621,15.54908,45.62314,30.44547,3.26138,1673795.392,1.77443,14.75,2.7,1,0,"CPN",3 278 | "277",88,-1.54913423238378,"Tawharanui","No-take","Anchor Bay Outer",30,11,0.03504,0.30468,2.44575,17.12,51.71877,25.89944,2.44507,1673795.392,1.68326,14.75,2.7,1.5,0.166666667,"CPN",3 279 | "278",89,1.76634675159096,"Tawharanui","No-take","Comet Rocks East",2,10,0.02577,0.14764,0.27863,0.85935,51.62622,45.75875,1.28493,167069.126,0.89349,13.25,4.4,0.333333333,0.166666667,"CPN",9 280 | "279",90,4.26560226112301,"Tawharanui","No-take","Comet Rocks East",5,10,0.484,0.1518,0.26047,0.57701,17.05321,77.95432,3.48185,167069.126,2.53218,13.25,4.4,2.666666667,0.166666667,"CPN",0 281 | "280",91,4.44916079552009,"Tawharanui","No-take","Comet Rocks East",15,10,0.29139,0.26949,0.35137,0.69191,13.91155,81.14862,3.29827,167069.126,1.9994,13.25,4.4,2.5,0,"CPN",1 282 | "281",92,1.51204481202269,"Tawharanui","No-take","Comet Rocks East",30,10,0.13563,0.07506,0.10935,0.67739,56.4404,40.8114,1.7303,167069.126,1.35509,13.25,4.4,1.666666667,0,"CPN",1 283 | "282",93,2.66281813929873,"Tawharanui","No-take","Comet Rocks West",2,9,0.12925,0.25934,0.4553,0.92908,37.45427,58.79215,1.96145,1764328.193,0.89349,13.5,1,0.333333333,0,"CPN",10 284 | "283",94,2.97744565376185,"Tawharanui","No-take","Comet Rocks West",5,9,0.09885,0.16337,0.33261,1.02094,32.97139,62.97884,2.3959,1764328.193,2.53218,13.5,1,0.666666667,0,"CPN",6 285 | "284",95,3.93757042934683,"Tawharanui","No-take","Comet Rocks West",15,9,0.31471,0.2989,0.38652,0.68277,20.48376,74.76174,3.02879,1764328.193,1.9994,13.5,1,1.666666667,0.666666667,"CPN",0 286 | "285",96,2.7924345819529,"Tawharanui","No-take","Comet Rocks West",30,9,0.38099,0.25801,0.2917,0.49269,38.05801,58.04893,2.44488,1764328.193,1.35509,13.5,1,1.666666667,0.666666667,"CPN",2 287 | --------------------------------------------------------------------------------