├── test.txt ├── inst ├── doc │ ├── .gitignore │ └── manuscript.pdf └── extdata │ ├── nla_lakes.shp │ ├── nla_lakes.shx │ ├── wsa9_low48.shp │ ├── wsa9_low48.shx │ ├── wsa9_low48.prj │ ├── nla_lakes.prj │ ├── process_wsa.R │ ├── wsa9_low48.dbf │ └── data_def.csv ├── .Rbuildignore ├── vignettes ├── fws_submission │ ├── .remake │ │ ├── objects │ │ │ ├── all__hash │ │ │ ├── manuscript.docx__hash │ │ │ ├── all │ │ │ └── manuscript.docx │ │ └── db │ │ │ ├── 52736a65e967b5bbeb8e7a8383edfcc4.rds │ │ │ ├── 5a558d2c342206783ef8c1a8b5bd298e.rds │ │ │ ├── d7200c880b79ed11e6c70db6f483cb8a.rds │ │ │ ├── fba69498d892305bb982b4d098e8932f.rds │ │ │ └── ff8a254ccf47adaee64dda330cfaa6ff.rds │ ├── fws_reject.pdf │ ├── manuscript.docx │ ├── manuscript.pdf │ ├── cover_letter.pdf │ ├── epa_letterhead.jpg │ ├── components │ │ ├── template.docx │ │ ├── elsarticle.latex │ │ ├── plos.csl │ │ ├── ecology.csl │ │ ├── freshwater-science.csl │ │ ├── default_jwh.latex │ │ └── manuscript.latex │ ├── figure │ │ ├── fig1_nlaMap-1.jpeg │ │ ├── fig8_condProbFig-1.jpeg │ │ ├── fig12_scatterplot-1.jpeg │ │ ├── fig9_ts_4_cyano_cdf-1.jpeg │ │ ├── fig10_ts_3_cyano_cdf-1.jpeg │ │ ├── fig11_ts_2_cyano_cdf-1.jpeg │ │ ├── fig2_Importance_Model1-1.jpeg │ │ ├── fig3_Importance_Model2-1.jpeg │ │ ├── fig4_Importance_Model3-1.jpeg │ │ ├── fig5_Importance_Model4-1.jpeg │ │ ├── fig6_Importance_Model5-1.jpeg │ │ └── fig7_Importance_Model6-1.jpeg │ ├── fws_reject_20150609_bjk.pdf │ ├── cat-pushing-watermelon-out-of-lake.jpg │ ├── hollister_milstead_kreakie_submitted.docx │ ├── open_sign_4344960203_821cb56ec9_o_resize.jpg │ ├── remake.yml │ ├── prepare_submission.R │ └── cover_letter.Rmd ├── manuscript.pdf ├── figure │ ├── eu_prob.jpg │ ├── meso_prob.jpg │ ├── nlaMap-1.jpeg │ ├── all_prob_map.jpg │ ├── gis_prob_map.jpg │ ├── hyper_prob.jpg │ ├── oligo_prob.jpg │ ├── condProbFig-1.jpeg │ ├── scatterplot-1.jpeg │ ├── ts_2_cyano_cdf-1.jpeg │ ├── ts_3_cyano_cdf-1.jpeg │ ├── ts_4_cyano_cdf-1.jpeg │ ├── varsel_all_plot.pdf │ ├── Importance_Model1-1.jpeg │ ├── Importance_Model2-1.jpeg │ ├── Importance_Model3-1.jpeg │ ├── Importance_Model4-1.jpeg │ ├── Importance_Model5-1.jpeg │ └── Importance_Model6-1.jpeg ├── manuscript_peerj.pdf ├── components │ ├── template.docx │ ├── elsarticle.latex │ ├── plos.csl │ ├── ecology.csl │ ├── freshwater-science.csl │ └── default_jwh.latex ├── ecosphere_final │ ├── ecs2_1321.pdf │ ├── ecs2_1321_jwh.pdf │ ├── manuscript.docx │ ├── manuscriptAppendix.docx │ ├── ecs21321-sup-0001-AppendixS1.pdf │ ├── hollisterES15-00703R_fig1.tiff │ ├── hollisterES15-00703R_fig10.tiff │ ├── hollisterES15-00703R_fig11.tiff │ ├── hollisterES15-00703R_fig2.tiff │ ├── hollisterES15-00703R_fig3.tiff │ ├── hollisterES15-00703R_fig4.tiff │ ├── hollisterES15-00703R_fig5.tiff │ ├── hollisterES15-00703R_fig6.tiff │ ├── hollisterES15-00703R_fig7.tiff │ ├── hollisterES15-00703R_fig8.tiff │ └── hollisterES15-00703R_fig9.tiff ├── ecosphere_submission │ ├── response.pdf │ ├── manuscript.pdf │ ├── cover_letter.pdf │ ├── epa_letterhead.jpg │ ├── cover_letter_resubmit.pdf │ ├── cover_letter_resubmit.Rmd │ ├── cover_letter.Rmd │ └── review_first_submission.txt ├── sessioninfo.txt ├── sessionInfo.txt └── manuscript_peerj.R ├── R ├── LakeTrophicModelling-package.r ├── table_to_df.R ├── ecdf_ks_ci.R ├── sumTable.R ├── varImportance.R ├── getLakeIDs.R ├── varsel_plot.R ├── density_plot.R ├── runRandomForest.R ├── ecor_map.R ├── varsel_regression_rf.R ├── prob_cdf.R ├── getCyanoAbund.R ├── scatterPlot.R ├── pred_prob_map.R ├── crossval_rf.R ├── partial_plot.R ├── nlaMap.R ├── multiplot.R ├── plotCdf.R ├── condAccuracy.R ├── importancePlot.R ├── class_prob_rf.R ├── ts_prob_map.R └── iterVarSelRF.R ├── .gitignore ├── data └── LakeTrophicModelling.rda ├── man ├── ltm.Rd ├── table_to_df.Rd ├── varsel_plot.Rd ├── density_plot.Rd ├── ecdf_ks_ci.Rd ├── varImportance.Rd ├── partial_plot.Rd ├── sumTable.Rd ├── make_ts_map.Rd ├── ecor_map.Rd ├── condAccuracy.Rd ├── getLakeIDs.Rd ├── getCyanoAbund.Rd ├── scatterPlot.Rd ├── prob_cdf.Rd ├── importancePlot.Rd ├── nlaMap.Rd ├── varsel_regression_rf.Rd ├── runRandomForest.Rd ├── ts_prob_map.Rd ├── pred_prob_map.Rd ├── crossval_rf.Rd ├── class_prob_rf.Rd ├── multiplot.Rd ├── plotCdf.Rd └── iterVarSelRF.Rd ├── LakeTrophicModelling.Rproj ├── .travis.yml ├── NAMESPACE ├── DESCRIPTION └── README.md /test.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /inst/doc/.gitignore: -------------------------------------------------------------------------------- 1 | techReviews.pdf 2 | qa tech rev.pdf 3 | -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^\.travis\.yml$ 2 | ^packrat/ 3 | ^.*\.Rproj$ 4 | ^\.Rproj\.user$ 5 | -------------------------------------------------------------------------------- /vignettes/fws_submission/.remake/objects/all__hash: -------------------------------------------------------------------------------- 1 | 72f531d1a36ddd6b5cbc433c29147817 2 | -------------------------------------------------------------------------------- /R/LakeTrophicModelling-package.r: -------------------------------------------------------------------------------- 1 | #' ltm. 2 | #' 3 | #' @name ltm 4 | #' @docType package 5 | NULL 6 | -------------------------------------------------------------------------------- /vignettes/fws_submission/.remake/objects/manuscript.docx__hash: -------------------------------------------------------------------------------- 1 | b40cd5325c4455abc415615c562ce3f2 2 | -------------------------------------------------------------------------------- /inst/doc/manuscript.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/inst/doc/manuscript.pdf -------------------------------------------------------------------------------- /vignettes/manuscript.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/manuscript.pdf -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | packrat/lib*/ 5 | vignettes/manuscript_cache/* 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /inst/extdata/nla_lakes.shp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/inst/extdata/nla_lakes.shp -------------------------------------------------------------------------------- /inst/extdata/nla_lakes.shx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/inst/extdata/nla_lakes.shx -------------------------------------------------------------------------------- /inst/extdata/wsa9_low48.shp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/inst/extdata/wsa9_low48.shp -------------------------------------------------------------------------------- /inst/extdata/wsa9_low48.shx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/inst/extdata/wsa9_low48.shx -------------------------------------------------------------------------------- /vignettes/figure/eu_prob.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/figure/eu_prob.jpg -------------------------------------------------------------------------------- /data/LakeTrophicModelling.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/data/LakeTrophicModelling.rda -------------------------------------------------------------------------------- /vignettes/figure/meso_prob.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/figure/meso_prob.jpg -------------------------------------------------------------------------------- /vignettes/figure/nlaMap-1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/figure/nlaMap-1.jpeg -------------------------------------------------------------------------------- /vignettes/manuscript_peerj.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/manuscript_peerj.pdf -------------------------------------------------------------------------------- /vignettes/figure/all_prob_map.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/figure/all_prob_map.jpg -------------------------------------------------------------------------------- /vignettes/figure/gis_prob_map.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/figure/gis_prob_map.jpg -------------------------------------------------------------------------------- /vignettes/figure/hyper_prob.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/figure/hyper_prob.jpg -------------------------------------------------------------------------------- /vignettes/figure/oligo_prob.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/figure/oligo_prob.jpg -------------------------------------------------------------------------------- /vignettes/components/template.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/components/template.docx -------------------------------------------------------------------------------- /vignettes/figure/condProbFig-1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/figure/condProbFig-1.jpeg -------------------------------------------------------------------------------- /vignettes/figure/scatterplot-1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/figure/scatterplot-1.jpeg -------------------------------------------------------------------------------- /vignettes/figure/ts_2_cyano_cdf-1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/figure/ts_2_cyano_cdf-1.jpeg -------------------------------------------------------------------------------- /vignettes/figure/ts_3_cyano_cdf-1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/figure/ts_3_cyano_cdf-1.jpeg -------------------------------------------------------------------------------- /vignettes/figure/ts_4_cyano_cdf-1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/figure/ts_4_cyano_cdf-1.jpeg -------------------------------------------------------------------------------- /vignettes/figure/varsel_all_plot.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/figure/varsel_all_plot.pdf -------------------------------------------------------------------------------- /vignettes/ecosphere_final/ecs2_1321.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/ecosphere_final/ecs2_1321.pdf -------------------------------------------------------------------------------- /vignettes/fws_submission/fws_reject.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/fws_submission/fws_reject.pdf -------------------------------------------------------------------------------- /vignettes/fws_submission/manuscript.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/fws_submission/manuscript.docx -------------------------------------------------------------------------------- /vignettes/fws_submission/manuscript.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/fws_submission/manuscript.pdf -------------------------------------------------------------------------------- /vignettes/ecosphere_final/ecs2_1321_jwh.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/ecosphere_final/ecs2_1321_jwh.pdf -------------------------------------------------------------------------------- /vignettes/ecosphere_final/manuscript.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/ecosphere_final/manuscript.docx -------------------------------------------------------------------------------- /vignettes/ecosphere_submission/response.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/ecosphere_submission/response.pdf -------------------------------------------------------------------------------- /vignettes/figure/Importance_Model1-1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/figure/Importance_Model1-1.jpeg -------------------------------------------------------------------------------- /vignettes/figure/Importance_Model2-1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/figure/Importance_Model2-1.jpeg -------------------------------------------------------------------------------- /vignettes/figure/Importance_Model3-1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/figure/Importance_Model3-1.jpeg -------------------------------------------------------------------------------- /vignettes/figure/Importance_Model4-1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/figure/Importance_Model4-1.jpeg -------------------------------------------------------------------------------- /vignettes/figure/Importance_Model5-1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/figure/Importance_Model5-1.jpeg -------------------------------------------------------------------------------- /vignettes/figure/Importance_Model6-1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/figure/Importance_Model6-1.jpeg -------------------------------------------------------------------------------- /vignettes/fws_submission/cover_letter.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/fws_submission/cover_letter.pdf -------------------------------------------------------------------------------- /vignettes/fws_submission/epa_letterhead.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/fws_submission/epa_letterhead.jpg -------------------------------------------------------------------------------- /vignettes/ecosphere_submission/manuscript.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/ecosphere_submission/manuscript.pdf -------------------------------------------------------------------------------- /vignettes/fws_submission/.remake/objects/all: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/fws_submission/.remake/objects/all -------------------------------------------------------------------------------- /vignettes/ecosphere_submission/cover_letter.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/ecosphere_submission/cover_letter.pdf -------------------------------------------------------------------------------- /vignettes/ecosphere_final/manuscriptAppendix.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/ecosphere_final/manuscriptAppendix.docx -------------------------------------------------------------------------------- /vignettes/ecosphere_submission/epa_letterhead.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/ecosphere_submission/epa_letterhead.jpg -------------------------------------------------------------------------------- /vignettes/fws_submission/components/template.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/fws_submission/components/template.docx -------------------------------------------------------------------------------- /vignettes/fws_submission/figure/fig1_nlaMap-1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/fws_submission/figure/fig1_nlaMap-1.jpeg -------------------------------------------------------------------------------- /vignettes/fws_submission/fws_reject_20150609_bjk.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/fws_submission/fws_reject_20150609_bjk.pdf -------------------------------------------------------------------------------- /inst/extdata/wsa9_low48.prj: -------------------------------------------------------------------------------- 1 | GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]] -------------------------------------------------------------------------------- /vignettes/fws_submission/figure/fig8_condProbFig-1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/fws_submission/figure/fig8_condProbFig-1.jpeg -------------------------------------------------------------------------------- /vignettes/ecosphere_final/ecs21321-sup-0001-AppendixS1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/ecosphere_final/ecs21321-sup-0001-AppendixS1.pdf -------------------------------------------------------------------------------- /vignettes/ecosphere_final/hollisterES15-00703R_fig1.tiff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/ecosphere_final/hollisterES15-00703R_fig1.tiff -------------------------------------------------------------------------------- /vignettes/ecosphere_final/hollisterES15-00703R_fig10.tiff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/ecosphere_final/hollisterES15-00703R_fig10.tiff -------------------------------------------------------------------------------- /vignettes/ecosphere_final/hollisterES15-00703R_fig11.tiff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/ecosphere_final/hollisterES15-00703R_fig11.tiff -------------------------------------------------------------------------------- /vignettes/ecosphere_final/hollisterES15-00703R_fig2.tiff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/ecosphere_final/hollisterES15-00703R_fig2.tiff -------------------------------------------------------------------------------- /vignettes/ecosphere_final/hollisterES15-00703R_fig3.tiff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/ecosphere_final/hollisterES15-00703R_fig3.tiff -------------------------------------------------------------------------------- /vignettes/ecosphere_final/hollisterES15-00703R_fig4.tiff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/ecosphere_final/hollisterES15-00703R_fig4.tiff -------------------------------------------------------------------------------- /vignettes/ecosphere_final/hollisterES15-00703R_fig5.tiff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/ecosphere_final/hollisterES15-00703R_fig5.tiff -------------------------------------------------------------------------------- /vignettes/ecosphere_final/hollisterES15-00703R_fig6.tiff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/ecosphere_final/hollisterES15-00703R_fig6.tiff -------------------------------------------------------------------------------- /vignettes/ecosphere_final/hollisterES15-00703R_fig7.tiff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/ecosphere_final/hollisterES15-00703R_fig7.tiff -------------------------------------------------------------------------------- /vignettes/ecosphere_final/hollisterES15-00703R_fig8.tiff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/ecosphere_final/hollisterES15-00703R_fig8.tiff -------------------------------------------------------------------------------- /vignettes/ecosphere_final/hollisterES15-00703R_fig9.tiff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/ecosphere_final/hollisterES15-00703R_fig9.tiff -------------------------------------------------------------------------------- /vignettes/ecosphere_submission/cover_letter_resubmit.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/ecosphere_submission/cover_letter_resubmit.pdf -------------------------------------------------------------------------------- /vignettes/fws_submission/.remake/objects/manuscript.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/fws_submission/.remake/objects/manuscript.docx -------------------------------------------------------------------------------- /vignettes/fws_submission/figure/fig12_scatterplot-1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/fws_submission/figure/fig12_scatterplot-1.jpeg -------------------------------------------------------------------------------- /vignettes/fws_submission/figure/fig9_ts_4_cyano_cdf-1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/fws_submission/figure/fig9_ts_4_cyano_cdf-1.jpeg -------------------------------------------------------------------------------- /vignettes/fws_submission/figure/fig10_ts_3_cyano_cdf-1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/fws_submission/figure/fig10_ts_3_cyano_cdf-1.jpeg -------------------------------------------------------------------------------- /vignettes/fws_submission/figure/fig11_ts_2_cyano_cdf-1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/fws_submission/figure/fig11_ts_2_cyano_cdf-1.jpeg -------------------------------------------------------------------------------- /vignettes/fws_submission/cat-pushing-watermelon-out-of-lake.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/fws_submission/cat-pushing-watermelon-out-of-lake.jpg -------------------------------------------------------------------------------- /vignettes/fws_submission/figure/fig2_Importance_Model1-1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/fws_submission/figure/fig2_Importance_Model1-1.jpeg -------------------------------------------------------------------------------- /vignettes/fws_submission/figure/fig3_Importance_Model2-1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/fws_submission/figure/fig3_Importance_Model2-1.jpeg -------------------------------------------------------------------------------- /vignettes/fws_submission/figure/fig4_Importance_Model3-1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/fws_submission/figure/fig4_Importance_Model3-1.jpeg -------------------------------------------------------------------------------- /vignettes/fws_submission/figure/fig5_Importance_Model4-1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/fws_submission/figure/fig5_Importance_Model4-1.jpeg -------------------------------------------------------------------------------- /vignettes/fws_submission/figure/fig6_Importance_Model5-1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/fws_submission/figure/fig6_Importance_Model5-1.jpeg -------------------------------------------------------------------------------- /vignettes/fws_submission/figure/fig7_Importance_Model6-1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/fws_submission/figure/fig7_Importance_Model6-1.jpeg -------------------------------------------------------------------------------- /man/ltm.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/LakeTrophicModelling-package.r 3 | \docType{package} 4 | \name{ltm} 5 | \alias{ltm} 6 | \title{ltm.} 7 | -------------------------------------------------------------------------------- /vignettes/fws_submission/hollister_milstead_kreakie_submitted.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/fws_submission/hollister_milstead_kreakie_submitted.docx -------------------------------------------------------------------------------- /vignettes/fws_submission/open_sign_4344960203_821cb56ec9_o_resize.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/fws_submission/open_sign_4344960203_821cb56ec9_o_resize.jpg -------------------------------------------------------------------------------- /vignettes/fws_submission/.remake/db/52736a65e967b5bbeb8e7a8383edfcc4.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/fws_submission/.remake/db/52736a65e967b5bbeb8e7a8383edfcc4.rds -------------------------------------------------------------------------------- /vignettes/fws_submission/.remake/db/5a558d2c342206783ef8c1a8b5bd298e.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/fws_submission/.remake/db/5a558d2c342206783ef8c1a8b5bd298e.rds -------------------------------------------------------------------------------- /vignettes/fws_submission/.remake/db/d7200c880b79ed11e6c70db6f483cb8a.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/fws_submission/.remake/db/d7200c880b79ed11e6c70db6f483cb8a.rds -------------------------------------------------------------------------------- /vignettes/fws_submission/.remake/db/fba69498d892305bb982b4d098e8932f.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/fws_submission/.remake/db/fba69498d892305bb982b4d098e8932f.rds -------------------------------------------------------------------------------- /vignettes/fws_submission/.remake/db/ff8a254ccf47adaee64dda330cfaa6ff.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USEPA/LakeTrophicModelling/HEAD/vignettes/fws_submission/.remake/db/ff8a254ccf47adaee64dda330cfaa6ff.rds -------------------------------------------------------------------------------- /vignettes/fws_submission/remake.yml: -------------------------------------------------------------------------------- 1 | sources: 2 | - prepare_submission.R 3 | 4 | targets: 5 | all: 6 | depends: 7 | - manuscript.docx 8 | 9 | manuscript.Rmd: 10 | command: copy("../manuscript.Rmd") 11 | 12 | manuscript.docx: 13 | command: render_doc("manuscript.Rmd") 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /man/table_to_df.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/table_to_df.R 3 | \name{table_to_df} 4 | \alias{table_to_df} 5 | \title{convert table to df} 6 | \usage{ 7 | table_to_df(cm_tab) 8 | } 9 | \arguments{ 10 | \item{cm_tab}{a table class with confusion matrix} 11 | } 12 | \description{ 13 | convert table to df 14 | } 15 | -------------------------------------------------------------------------------- /R/table_to_df.R: -------------------------------------------------------------------------------- 1 | #' convert table to df 2 | #' 3 | #' @param cm_tab a table class with confusion matrix 4 | #' 5 | #' @export 6 | table_to_df <- function(cm_tab){ 7 | nc <- ncol(cm_tab) 8 | nr <- nrow(cm_tab) 9 | df<-data.frame(matrix(cm_tab[1:(nc*nr)],ncol=nc,nrow=nr)) 10 | names(df)<-attributes(cm_tab)[[2]][[1]] 11 | row.names(df)<-names(df) 12 | return(df) 13 | } 14 | -------------------------------------------------------------------------------- /vignettes/fws_submission/prepare_submission.R: -------------------------------------------------------------------------------- 1 | # Function to copy manuscript.Rmd from vignette into submission 2 | copy<-function(file){ 3 | file.copy(file,"manuscript.Rmd",overwrite=TRUE) 4 | #system("cp ../manuscript.Rmd .") 5 | system("cp -r ../components .") 6 | } 7 | 8 | render_doc<-function(file){ 9 | rmarkdown::render(file,output_file = "manuscript.docx", output_format = "all") 10 | } -------------------------------------------------------------------------------- /man/varsel_plot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/varsel_plot.R 3 | \name{varsel_plot} 4 | \alias{varsel_plot} 5 | \title{Plot varsel_regression output} 6 | \usage{ 7 | varsel_plot(vs_reg_obj) 8 | } 9 | \arguments{ 10 | \item{vs_reg_obj}{Object from output of \link{varsel_regression_rf}.} 11 | } 12 | \description{ 13 | Plot varsel_regression output 14 | } 15 | -------------------------------------------------------------------------------- /man/density_plot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/density_plot.R 3 | \name{density_plot} 4 | \alias{density_plot} 5 | \title{density plot for lake trophic modeling paper} 6 | \usage{ 7 | density_plot(df, xvar, ...) 8 | } 9 | \description{ 10 | Produces a density plot via ggplot 11 | } 12 | \examples{ 13 | density_plot(gis_rf_ts_prob,xvar="max",x="Predicted Probability") 14 | } 15 | -------------------------------------------------------------------------------- /inst/extdata/nla_lakes.prj: -------------------------------------------------------------------------------- 1 | PROJCS["unknown",GEOGCS["GCS_unknown",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Albers"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-96.0],PARAMETER["Standard_Parallel_1",29.5],PARAMETER["Standard_Parallel_2",45.5],PARAMETER["Latitude_Of_Origin",37.5],UNIT["Meter",1.0]] -------------------------------------------------------------------------------- /man/ecdf_ks_ci.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ecdf_ks_ci.R 3 | \name{ecdf_ks_ci} 4 | \alias{ecdf_ks_ci} 5 | \title{Kolmogrov-Smirnoff CIs for a ecdf} 6 | \usage{ 7 | ecdf_ks_ci(x) 8 | } 9 | \description{ 10 | Code from sfsmisc::ecdf.KSci. Ammended here to simply output the xy for both upper and 11 | lower for use as input to ggplot 12 | } 13 | \examples{ 14 | ecdf_ks_ci(all_pred_prob) 15 | } 16 | -------------------------------------------------------------------------------- /man/varImportance.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/varImportance.R 3 | \name{varImportance} 4 | \alias{varImportance} 5 | \title{Variable Importance Summary} 6 | \usage{ 7 | varImportance(rf_imp, label = NULL) 8 | } 9 | \arguments{ 10 | \item{rf_imp}{a Random Forest Importance Object} 11 | 12 | \item{label}{A label for the model} 13 | } 14 | \description{ 15 | Variable Importance Summary 16 | } 17 | -------------------------------------------------------------------------------- /man/partial_plot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/partial_plot.R 3 | \name{partial_plot} 4 | \alias{partial_plot} 5 | \title{Create parital dependence plot} 6 | \usage{ 7 | partial_plot(pd, xl, yl, ...) 8 | } 9 | \arguments{ 10 | \item{pd}{partial dependence from randomForest::partialPlot()} 11 | } 12 | \description{ 13 | This function takes the output of randomForest::paritalPlot() and 14 | generates a plot via ggplot. 15 | } 16 | -------------------------------------------------------------------------------- /LakeTrophicModelling.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 | 15 | BuildType: Package 16 | PackageUseDevtools: Yes 17 | PackageInstallArgs: --no-multiarch --with-keep.source 18 | PackageCheckArgs: --as-cran 19 | PackageRoxygenize: rd,collate,namespace,vignette 20 | -------------------------------------------------------------------------------- /man/sumTable.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sumTable.R 3 | \name{sumTable} 4 | \alias{sumTable} 5 | \title{sumTable} 6 | \usage{ 7 | sumTable(tsList) 8 | } 9 | \arguments{ 10 | \item{tsList}{list of just the selected variable (i.e. truncate list by 5 if time=T in 11 | iterVarSelRF)} 12 | } 13 | \description{ 14 | Function to summarize the output of iterVarSelRF into a percentage of the time a given 15 | variable was selected by varSelRF. Outputs md via kable 16 | } 17 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Sample .travis.yml for R projects from https://github.com/craigcitro/r-travis 2 | 3 | language: c 4 | 5 | before_install: 6 | - curl -OL http://raw.github.com/craigcitro/r-travis/master/scripts/travis-tool.sh 7 | - chmod 755 ./travis-tool.sh 8 | - ./travis-tool.sh bootstrap 9 | 10 | install: 11 | - ./travis-tool.sh install_deps 12 | 13 | script: ./travis-tool.sh run_tests 14 | 15 | on_failure: 16 | - ./travis-tool.sh dump_logs 17 | 18 | notifications: 19 | email: 20 | on_success: change 21 | on_failure: change 22 | -------------------------------------------------------------------------------- /man/make_ts_map.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ts_prob_map.R 3 | \name{make_ts_map} 4 | \alias{make_ts_map} 5 | \title{helper function to generate each map} 6 | \usage{ 7 | make_ts_map(states, lake_prob, title, low, high) 8 | } 9 | \arguments{ 10 | \item{states}{the states} 11 | 12 | \item{lake_prob}{merged lake and prob data} 13 | 14 | \item{title}{title of map} 15 | 16 | \item{low}{lower color} 17 | 18 | \item{high}{higher color} 19 | } 20 | \description{ 21 | helper function to generate each map 22 | } 23 | -------------------------------------------------------------------------------- /man/ecor_map.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ecor_map.R 3 | \name{ecor_map} 4 | \alias{ecor_map} 5 | \title{Create map of Ecoregions} 6 | \usage{ 7 | ecor_map(ecor) 8 | } 9 | \arguments{ 10 | \item{states}{data for states, as data.frame} 11 | 12 | \item{lakes}{point locations for lake samples as data.frame} 13 | 14 | \item{myColor}{vector of length 3 with colors for fill, lines, and points in that order} 15 | } 16 | \description{ 17 | Function to generate Map 1 in hkm2014ESA poster 18 | } 19 | \examples{ 20 | wsa9<-readOGR("../inst/extdata/","wsa9_low48") 21 | ecor_map(wsa9) 22 | } 23 | -------------------------------------------------------------------------------- /R/ecdf_ks_ci.R: -------------------------------------------------------------------------------- 1 | #' Kolmogrov-Smirnoff CIs for a ecdf 2 | #' 3 | #' Code from sfsmisc::ecdf.KSci. Ammended here to simply output the xy for both upper and 4 | #' lower for use as input to ggplot 5 | #' @export 6 | #' @examples 7 | #' ecdf_ks_ci(all_pred_prob) 8 | ecdf_ks_ci <- function(x){ 9 | n <- length(x) 10 | ec <- ecdf(x) 11 | xx <- get("x", envir = environment(ec)) 12 | yy <- get("y", envir = environment(ec)) 13 | D <- sfsmisc::KSd(n) 14 | yyu <- pmin(yy + D, 1) 15 | yyl <- pmax(yy - D, 0) 16 | ecu <- stepfun(xx, c(yyu, 1)) 17 | ecl <- stepfun(xx, c(yyl, yyl[n])) 18 | return(list(x=x, upper=ecu(x),lower=ecl(x))) 19 | } -------------------------------------------------------------------------------- /R/sumTable.R: -------------------------------------------------------------------------------- 1 | #' sumTable 2 | #' 3 | #' Function to summarize the output of iterVarSelRF into a percentage of the time a given 4 | #' variable was selected by varSelRF. Outputs md via kable 5 | #' 6 | #' @param tsList list of just the selected variable (i.e. truncate list by 5 if time=T in 7 | #' iterVarSelRF) 8 | #' 9 | #' @export 10 | 11 | sumTable <- function(tsList) { 12 | summDF <- data.frame() 13 | uniqueVar <- unique(unlist(tsList)) 14 | for (i in uniqueVar) { 15 | summDF <- rbind(summDF, data.frame(Variable = i, 16 | Percent = sum(unlist(tsList) %in% i)/length(tsList))) 17 | } 18 | summDF <- summDF[order(summDF$Percent, decreasing = T), 19 | ] 20 | return(summDF) 21 | } 22 | -------------------------------------------------------------------------------- /R/varImportance.R: -------------------------------------------------------------------------------- 1 | #' Variable Importance Summary 2 | #' 3 | #' @param rf_imp a Random Forest Importance Object 4 | #' @param label A label for the model 5 | #' @export 6 | varImportance<-function(rf_imp,label=NULL){ 7 | 8 | if(!is.null(label)){ 9 | xdf<-data.frame(model_id=rep(label,nrow(rf_imp)), 10 | variable_names=row.names(rf_imp), 11 | mean_decrease_acc=rf_imp[,1], 12 | mean_decrease_gini=rf_imp[,2]) 13 | } else { 14 | xdf<-data.frame(model_id=rep(NA,nrow(rf_imp)), 15 | variable_names=row.names(rf_imp), 16 | mean_decrease_acc=rf_imp[,1], 17 | mean_decrease_gini=rf_imp[,2]) 18 | } 19 | return(xdf) 20 | } -------------------------------------------------------------------------------- /man/condAccuracy.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/condAccuracy.R 3 | \name{condAccuracy} 4 | \alias{condAccuracy} 5 | \title{Plot conditional accuracy} 6 | \usage{ 7 | condAccuracy(pred_prob1, pred_prob2, xlab = "x", ...) 8 | } 9 | \arguments{ 10 | \item{...}{parameters to be passed to condprob} 11 | 12 | \item{rf}{A random forest object} 13 | } 14 | \description{ 15 | This function plots the total accuracy as a function of maximum probability. 16 | We determine the maximum probability for each lake for a given random forest 17 | object and then plot the total accuracy for lakes at each value of x or greater 18 | } 19 | \examples{ 20 | condAccuracy(all_rf_ts_prob,gis_rf_ts_prob,xImpair=0,R=1,xlab="Xc >= Prediction Probability") 21 | } 22 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(class_prob_rf) 4 | export(condAccuracy) 5 | export(crossval_rf) 6 | export(density_plot) 7 | export(ecdf_ks_ci) 8 | export(ecor_map) 9 | export(getCyanoAbund) 10 | export(getLakeIDs) 11 | export(importancePlot) 12 | export(iterVarSelRF) 13 | export(make_ts_map) 14 | export(multiplot) 15 | export(nlaMap) 16 | export(partial_plot) 17 | export(plotCdf) 18 | export(pred_prob_map) 19 | export(prob_cdf) 20 | export(runRandomForest) 21 | export(scatterPlot) 22 | export(sumTable) 23 | export(table_to_df) 24 | export(ts_prob_map) 25 | export(varImportance) 26 | export(varsel_plot) 27 | export(varsel_regression_rf) 28 | import(broom) 29 | import(ggplot2) 30 | import(party) 31 | import(randomForest) 32 | import(snowfall) 33 | import(varSelRF) 34 | -------------------------------------------------------------------------------- /man/getLakeIDs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/getLakeIDs.R 3 | \name{getLakeIDs} 4 | \alias{getLakeIDs} 5 | \title{getLakeIDs} 6 | \usage{ 7 | getLakeIDs(indVar, depVar, id) 8 | } 9 | \arguments{ 10 | \item{indVar}{independent variables} 11 | 12 | \item{depVar}{dependent variable} 13 | 14 | \item{id}{vector of IDS, same length and order as indVar and} 15 | } 16 | \description{ 17 | This function retrieves the lake IDs for each of the rf objects 18 | } 19 | \examples{ 20 | data(LakeTrophicModelling) 21 | x2<-iterVarSelRF(ltmData[predictors_gis],ltmData$TS_CHLA_4,10,4,ntree=10,ntreeIterat=5, 22 | vars.drop.frac=NULL,vars.drop.num=1,time=FALSE) 23 | x2_vars<-unique(unlist(x2)) 24 | gis_ts4_rf<-runRandomForest(ltmData[x2_vars],ltmData$TS_CHLA_4) 25 | } 26 | -------------------------------------------------------------------------------- /inst/extdata/process_wsa.R: -------------------------------------------------------------------------------- 1 | 2 | wsa9<-readOGR(".","wsa9_low48") 3 | wsa9@data$id <- rownames(wsa9@data) 4 | wsa9_f <- fortify(wsa9, region="WSA_9") 5 | names(wsa9_f)[which(names(wsa9_f)=="id")] = "WSA_9" 6 | wsa9_df = plyr::join(wsa9_f, wsa9@data, by="WSA_9") 7 | 8 | 9 | a<-ggplot(wsa9_df, aes(long,lat,group=group,fill=id)) + 10 | geom_polygon(data=subset(wsa9_df,WSA_9!="WMT")) + 11 | geom_polygon(data=subset(wsa9_df,WSA_9=="WMT")) + 12 | geom_path(color="white") + 13 | coord_equal() + 14 | coord_map("albers", lat2 = 45.5, lat1 = 29.5)+ 15 | theme(panel.background = element_rect(fill="white"), panel.grid = element_blank(), 16 | panel.border = element_blank(), #legend.position = "none", 17 | axis.text = element_blank(),axis.ticks = element_blank()) + 18 | ylab("") + 19 | xlab("") 20 | a 21 | -------------------------------------------------------------------------------- /man/getCyanoAbund.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/getCyanoAbund.R 3 | \name{getCyanoAbund} 4 | \alias{getCyanoAbund} 5 | \title{Pulls down cyano abundance from NLA website} 6 | \usage{ 7 | getCyanoAbund() 8 | } 9 | \value{ 10 | a data.frame with four fields: SITE_ID=the NLA site id for the lake, 11 | cyanoCellsPerML=for each SITE_ID the sum of abundance (cells/ml) 12 | of all phytoplankton for Division='Cyanophyta', 13 | cyanoCat=cyano abundance category based on quartile distribution of cyanoCellsPerML 14 | ('LOW'<= Q1; 'MED' >Q1 and =Q4), and 15 | mcyst_conc in ug/l 16 | } 17 | \description{ 18 | This function downloads the NLA2007 phytoplankton data and calculates the 19 | abundance (cells/ml) of cyanobacteria by lake 20 | } 21 | -------------------------------------------------------------------------------- /man/scatterPlot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/scatterPlot.R 3 | \name{scatterPlot} 4 | \alias{scatterPlot} 5 | \title{Scatterplot for hkm2014esa poster} 6 | \usage{ 7 | scatterPlot(df, xvar, yvar, pt_col, ln_col, cl_col, ...) 8 | } 9 | \description{ 10 | Produces a scatterplot via ggplot 11 | } 12 | \examples{ 13 | devtools::install_github("wesanderson","jhollist") 14 | library('wesanderson') 15 | data(LakeTrophicModelling) 16 | mydf<-data.frame(chla=ltmData[["CHLA"]],biovp1=ltmData[["sumBioV"]]+1) 17 | zissou2<-wes.palette(5,"Zissou2") 18 | scatterPlot(mydf,xvar="chla",yvar="biovp1",zissou2[3],zissou2[2],zissou2[1], 19 | title="Chlorophyll and Cyanobacterai Relationship", 20 | x=expression(paste('Log10(Chl ', italic("a"),')')), 21 | y="Log10(Cyanobaterial Abundance + 1)") 22 | } 23 | -------------------------------------------------------------------------------- /man/prob_cdf.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/prob_cdf.R 3 | \name{prob_cdf} 4 | \alias{prob_cdf} 5 | \title{Function to create CDFs of probability for each trophic state prediction} 6 | \usage{ 7 | prob_cdf(probs1, probs2, ...) 8 | } 9 | \arguments{ 10 | \item{probs1}{prediction probabilities for one of the models} 11 | 12 | \item{probs2}{prediction probabilities for the other model} 13 | 14 | \item{...}{pass additional parameters to labs (e.g. set titles, axis labels, etc.)} 15 | } 16 | \description{ 17 | This functions produces CDF plots from predicted trophic state probabilities 18 | } 19 | \examples{ 20 | devtools::install_github('wesanderson','karthik') 21 | library(wesanderson) 22 | data(LakeTrophicModelling) 23 | prob_cdf(all_rf_ts_prob, gis_rf_ts_prob,x="Prediction Probability",y="Proportion of Samples") 24 | } 25 | -------------------------------------------------------------------------------- /R/getLakeIDs.R: -------------------------------------------------------------------------------- 1 | #' getLakeIDs 2 | #' 3 | #' This function retrieves the lake IDs for each of the rf objects 4 | #' 5 | #' @param indVar independent variables 6 | #' @param depVar dependent variable 7 | #' @param id vector of IDS, same length and order as indVar and 8 | #' 9 | #' @examples 10 | #' data(LakeTrophicModelling) 11 | #' x2<-iterVarSelRF(ltmData[predictors_gis],ltmData$TS_CHLA_4,10,4,ntree=10,ntreeIterat=5, 12 | #' vars.drop.frac=NULL,vars.drop.num=1,time=FALSE) 13 | #' x2_vars<-unique(unlist(x2)) 14 | #' gis_ts4_rf<-runRandomForest(ltmData[x2_vars],ltmData$TS_CHLA_4) 15 | #' @export 16 | #' 17 | getLakeIDs <- function(indVar, depVar, id) { 18 | 19 | # Only Pass Complete Cases 20 | comp_case <- complete.cases(indVar, depVar) 21 | if (length(indVar) > 1) { 22 | indVar <- indVar[comp_case, ] 23 | } else { 24 | indVar <- indVar[comp_case] 25 | } 26 | depVar <- depVar[comp_case] 27 | 28 | 29 | return(id[comp_case]) 30 | 31 | } 32 | -------------------------------------------------------------------------------- /inst/extdata/wsa9_low48.dbf: -------------------------------------------------------------------------------- 1 | _ 2 | a[WcatN 3 | WSA_9CP 1 2CPL 3NAP 4NPL 5SAP 6SPL 7TPL 8UMW 9WMT 10XER -------------------------------------------------------------------------------- /man/importancePlot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/importancePlot.R 3 | \name{importancePlot} 4 | \alias{importancePlot} 5 | \title{Random Forest Variable Importance Plotting} 6 | \usage{ 7 | importancePlot( 8 | rf, 9 | sumtbl = NULL, 10 | data_def = NULL, 11 | type = c("acc", "gini"), 12 | ... 13 | ) 14 | } 15 | \arguments{ 16 | \item{rf}{a randomForest object} 17 | 18 | \item{type}{the type of importance to plot "acc" for Mean Decrease Accuracy, and 19 | "gini for Mean Decrease Gini.} 20 | 21 | \item{...}{any items that can be passed to geom_point. Mostly used to control size 22 | and color of points.} 23 | } 24 | \description{ 25 | Random Forest Variable Importance Plotting 26 | } 27 | \examples{ 28 | require(wesanderson) 29 | data(iris) 30 | iris_rf<-randomForest(iris[,1:4],iris[,5],importance=T,proximity=T) 31 | importancePlot(iris_rf,'acc',size=10,aes(colour=wes.palette(4, 'GrandBudapest'))) 32 | importancePlot(iris_rf,'gini',size=10,aes(colour=wes.palette(4, 'GrandBudapest'))) 33 | } 34 | -------------------------------------------------------------------------------- /vignettes/ecosphere_submission/cover_letter_resubmit.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: pdf_document 3 | fontsize: 12pt 4 | geometry: 5 | - top=0.05in 6 | - right=0.5in 7 | - left=0.5in 8 | - bottom=0.1in 9 | --- 10 | 11 | ![letterhead](epa_letterhead.jpg) 12 | 13 | `r format(Sys.Date(), "%B %d, %Y")` \newline 14 | 15 | Debra Peters\newline 16 | Editor, *Ecosphere*\newline 17 | USDA ARS\newline 18 | Las Cruces, NM 88003\newline 19 | 20 | Dear Dr. Peters, 21 | 22 | Please accept for your review our resubmission, "Modelling Lake Trophic State: A Random Forest Approach." The manuscript number for the original submission was ES15-00549. We have caerfully reviewed the comments from that submission and have made changes to our manuscript accordingly. Included in this cover letter are an itemized list of both reviewers comments as well as details on how we updated the manuscript. 23 | 24 | 25 | Sincerely, 26 | 27 | Jeffrey W. Hollister 28 | 401 782 9655 29 | hollister.jeff@epa.gov 30 | 31 | W. Bryan Milstead 32 | milstead.bryan@epa.gov 33 | 34 | Betty J. Kreakie 35 | kreakie.betty@epa.gov 36 | -------------------------------------------------------------------------------- /R/varsel_plot.R: -------------------------------------------------------------------------------- 1 | #' Plot varsel_regression output 2 | #' 3 | #' @param vs_reg_obj Object from output of \link{varsel_regression_rf}. 4 | #' @export 5 | #' @import ggplot2 6 | varsel_plot <- function(vs_reg_obj){ 7 | dat <- data.frame(num = vs_reg_obj$num_var, mse = vs_reg_obj$mse) 8 | plot_out<-ggplot(dat, aes(x=num,y=mse))+geom_point(size=2.5)+ 9 | theme(text = element_text(family="sans"), 10 | panel.background = element_blank(), #panel.grid = element_blank(), 11 | panel.border = element_rect(fill = NA), 12 | plot.title = element_text(family="sans",size=15,face="bold",vjust=1.1), 13 | legend.key = element_rect(fill = 'white'), 14 | legend.text = element_text(family="sans",size=15), legend.title = element_text(size=15), 15 | axis.title.x = element_text(family="sans",vjust = -0.5, size = 12), 16 | axis.title.y = element_text(family="sans",vjust = 1.5, size = 12), 17 | axis.text.x = element_text(family="sans",size = 11), 18 | axis.text.y = element_text(family="sans",size = 11))+ 19 | labs(x="Number of variables in model", y="Root Mean Square Error") 20 | return(plot_out) 21 | } -------------------------------------------------------------------------------- /man/nlaMap.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/nlaMap.R 3 | \name{nlaMap} 4 | \alias{nlaMap} 5 | \title{Create map of NLA samples} 6 | \usage{ 7 | nlaMap(states, lakes, cats = F, myColor = 1:3, catColor = NULL) 8 | } 9 | \arguments{ 10 | \item{states}{data for states, as data.frame} 11 | 12 | \item{lakes}{point locations for lake samples as data.frame} 13 | 14 | \item{cats}{plot ts categories?} 15 | 16 | \item{myColor}{vector of length 3 with colors for fill, lines, and points in that order} 17 | } 18 | \description{ 19 | Function to generate Map 1 in hkm2014ESA poster 20 | } 21 | \examples{ 22 | state<-map_data('state') 23 | lakes_alb<-data.frame(ltmData[["AlbersX"]],ltmData[["AlbersY"]]) 24 | p4s<-"+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=37.5 +lon_0=-96 +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs" 25 | ll<-"+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs" 26 | lakes_alb_sp<-SpatialPoints(coordinates(lakes_alb),proj4string=CRS(p4s)) 27 | lakes_dd<-spTransform(lakes_alb_sp,CRS=CRS(ll)) 28 | lakes_dd<-data.frame(coordinates(lakes_dd)) 29 | names(lakes_dd)<-c("long","lat") 30 | nlaMap(state,lakes_dd) 31 | } 32 | -------------------------------------------------------------------------------- /R/density_plot.R: -------------------------------------------------------------------------------- 1 | #' density plot for lake trophic modeling paper 2 | #' 3 | #' Produces a density plot via ggplot 4 | #' 5 | #' @examples 6 | #' density_plot(gis_rf_ts_prob,xvar="max",x="Predicted Probability") 7 | #' @export 8 | #' @import ggplot2 9 | 10 | density_plot<-function(df,xvar,...){ 11 | options(scipen=5) 12 | xdf<-data.frame(xvar=df[[xvar]]) 13 | x <- ggplot(xdf,aes(x=xvar))+ 14 | geom_density() + 15 | theme(text = element_text(family="sans"), 16 | panel.background = element_blank(), 17 | panel.border = element_rect(fill = NA), 18 | plot.title = element_text(family="sans",size=12,face="bold",vjust=1.1), 19 | legend.position = "none", legend.key = element_rect(fill = 'white'), 20 | legend.text = element_text(family="sans",size=15), legend.title = element_text(size=11), 21 | axis.title.x = element_text(family="sans",vjust = -0.5, size = 12), 22 | axis.title.y = element_text(family="sans",vjust = 1.5, size = 12), 23 | axis.text.x = element_text(family="sans",size = 11), 24 | axis.text.y = element_text(family="sans",size = 11)) + 25 | labs(...) 26 | 27 | return(x) 28 | } -------------------------------------------------------------------------------- /man/varsel_regression_rf.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/varsel_regression_rf.R 3 | \name{varsel_regression_rf} 4 | \alias{varsel_regression_rf} 5 | \title{Variable Selection with Regression RF} 6 | \usage{ 7 | varsel_regression_rf(y, x, prog = F, ...) 8 | } 9 | \arguments{ 10 | \item{y}{response a vector} 11 | 12 | \item{x}{predictors a data.frame} 13 | 14 | \item{...}{options to pass to randomForest} 15 | } 16 | \description{ 17 | Similar approach to varSelRF, but for regresssion. Use full model to rank 18 | variables based on either %IncMSE or Gini. To use %IncMSE set 19 | imporatance = TRUE. It then steps through that sorted variable list with 20 | most important first and runs RF, store variables and %MSE of model. 21 | Note: this sorts on Gini, by default. importance = TRUE ensures %IncMSE. 22 | } 23 | \examples{ 24 | data(LakeTrophicModelling) 25 | predictors_all <- predictors_all[predictors_all!="DATE_COL"] 26 | all_dat <- data.frame(ltmData[predictors_all],LogCHLA=log10(ltmData$CHLA)) 27 | all_dat <- all_dat[complete.cases(all_dat),] 28 | x<-varsel_regression_rf(all_dat$LogCHLA,all_dat[,names(all_dat)!="LogCHLA"], 29 | ntree=100,prog=T, importance = TRUE) 30 | } 31 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: LakeTrophicModelling 2 | Title: Package to reproduce Hollister et al. (2015) Modeling Lake Trophic 3 | State: A Randrom Forest Approach. 4 | Version: 0.1 5 | Authors@R: 6 | c(person("Jeff","Hollister",role=c("aut","cre"),email="hollister.jeff@epa.gov"), 7 | person("Bryan","Milstead",role=c("aut"),email="milstead.bryan@epa.gov"), 8 | person("Betty","Kreakie",role=c("aut"),email="kreakie.betty@epa.gov")) 9 | Description: This package contains all the materials needed to reproduce 10 | Hollister *et al.* (2015) Modeling Lake Trophic State: A Randrom Forest 11 | Approach. These materials are presented as an R Package which contains code 12 | used for analyses, code used to develop figures, raw data used for all 13 | analyses, and a package vignette that contains the accepted, unformatted 14 | version of the manuscript in R markdown. 15 | Depends: 16 | R (>= 3.1.1) 17 | Suggests: 18 | knitr, 19 | rmarkdown 20 | Imports: 21 | randomForest, 22 | varSelRF, 23 | snowfall, 24 | parallel, 25 | knitr, 26 | ggplot2, 27 | grid, 28 | e1071, 29 | maps, 30 | mapproj, 31 | sfsmisc, 32 | party 33 | License: CC0 34 | LazyData: true 35 | VignetteBuilder: knitr 36 | RoxygenNote: 7.1.1 37 | -------------------------------------------------------------------------------- /man/runRandomForest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/runRandomForest.R 3 | \name{runRandomForest} 4 | \alias{runRandomForest} 5 | \title{runRandomForest} 6 | \usage{ 7 | runRandomForest( 8 | indVar, 9 | depVar, 10 | ntree = 100, 11 | importance = TRUE, 12 | proximity = TRUE 13 | ) 14 | } 15 | \arguments{ 16 | \item{indVar}{independent variables} 17 | 18 | \item{depVar}{dependent variable} 19 | 20 | \item{ntree}{to be passed to randomForest. Had trouble getting ... to work with the snowfall wrapper 21 | function. This was a quick hack.} 22 | 23 | \item{importance}{to be passed to randomForest. Had trouble getting ... to work with the snowfall wrapper 24 | function. This was a quick hack.} 25 | 26 | \item{proximity}{to be passed to randomForest. Had trouble getting ... to work with the snowfall wrapper 27 | function. This was a quick hack.} 28 | } 29 | \description{ 30 | This function takes the output of iterVarSelRF and runs a random forest. 31 | } 32 | \examples{ 33 | data(LakeTrophicModelling) 34 | x2<-iterVarSelRF(ltmData[predictors_gis],ltmData$TS_CHLA_4,10,4,ntree=10,ntreeIterat=5, 35 | vars.drop.frac=NULL,vars.drop.num=1,time=FALSE) 36 | x2_vars<-unique(unlist(x2)) 37 | gis_ts4_rf<-runRandomForest(ltmData[x2_vars],ltmData$TS_CHLA_4, ntree=10,importance=TRUE,proximity=TRUE) 38 | } 39 | -------------------------------------------------------------------------------- /man/ts_prob_map.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ts_prob_map.R 3 | \name{ts_prob_map} 4 | \alias{ts_prob_map} 5 | \title{Create map of trophic state probabilities} 6 | \usage{ 7 | ts_prob_map(states, lakes, probs, save_sep = FALSE) 8 | } 9 | \arguments{ 10 | \item{states}{data for states, as data.frame} 11 | 12 | \item{lakes}{point locations for lake samples as data.frame with NLA ID} 13 | 14 | \item{probs}{class probabilites with NLA ID} 15 | } 16 | \description{ 17 | This function takes the predicted class probabilites and maps them for each trophic 18 | state. 19 | } 20 | \examples{ 21 | state<-map_data('state') 22 | lakes_alb<-data.frame(ltmData[["AlbersX"]],ltmData[["AlbersY"]], 23 | ltmData[["NLA_ID"]]) 24 | p4s<-"+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=37.5 +lon_0=-96 +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs" 25 | ll<-"+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs" 26 | lakes_alb_sp<-SpatialPointsDataFrame(coordinates(lakes_alb[,1:2]),proj4string=CRS(p4s), 27 | data=data.frame(nla_id = as.character(lakes_alb[,3]))) 28 | lakes_dd<-spTransform(lakes_alb_sp,CRS=CRS(ll)) 29 | lakes_dd<-data.frame(coordinates(lakes_dd),lakes_dd$nla_id) 30 | names(lakes_dd)<-c("long","lat","nla_id") 31 | ts_prob_map(state,lakes_dd,gis_rf_ts_prob) 32 | } 33 | -------------------------------------------------------------------------------- /man/pred_prob_map.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pred_prob_map.R 3 | \name{pred_prob_map} 4 | \alias{pred_prob_map} 5 | \title{Create map of discrete predicted probabilities} 6 | \usage{ 7 | pred_prob_map(states, lakes, probs, save_sep = FALSE) 8 | } 9 | \arguments{ 10 | \item{states}{data for states, as data.frame} 11 | 12 | \item{lakes}{point locations for lake samples as data.frame with NLA ID} 13 | 14 | \item{probs}{class probabilites with NLA ID} 15 | } 16 | \description{ 17 | This function takes the predicted class probabilites and maps them for the 18 | predicted class 19 | } 20 | \examples{ 21 | state<-map_data('state') 22 | lakes_alb<-data.frame(ltmData[["AlbersX"]],ltmData[["AlbersY"]], 23 | ltmData[["NLA_ID"]]) 24 | p4s<-"+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=37.5 +lon_0=-96 +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs" 25 | ll<-"+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs" 26 | lakes_alb_sp<-SpatialPointsDataFrame(coordinates(lakes_alb[,1:2]),proj4string=CRS(p4s), 27 | data=data.frame(nla_id = as.character(lakes_alb[,3]))) 28 | lakes_dd<-spTransform(lakes_alb_sp,CRS=CRS(ll)) 29 | lakes_dd<-data.frame(coordinates(lakes_dd),lakes_dd$nla_id) 30 | names(lakes_dd)<-c("long","lat","nla_id") 31 | pred_prob_map(state,lakes_dd,gis_rf_ts_prob) 32 | } 33 | -------------------------------------------------------------------------------- /man/crossval_rf.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/crossval_rf.R 3 | \name{crossval_rf} 4 | \alias{crossval_rf} 5 | \title{Cross Validate Random Forests to get Categorical Accuracy} 6 | \usage{ 7 | crossval_rf(y, x, breaks, cat = NULL, split, n, ntree) 8 | } 9 | \arguments{ 10 | \item{y}{response a vector} 11 | 12 | \item{x}{predictors a data.frame} 13 | 14 | \item{breaks}{numeric vector of cut points} 15 | 16 | \item{cat}{categories of response} 17 | 18 | \item{split}{proportion to include in training datset. test set to inverse.} 19 | 20 | \item{n}{number of iterations} 21 | } 22 | \description{ 23 | Funtion to cross-validate categorical prediction accuracy from 24 | resultant chl a. A Random forest of forests... Used to get categorical 25 | accuracy. Also returns a cross-validated accuracy of % var explained. 26 | } 27 | \examples{ 28 | data(LakeTrophicModelling) 29 | predictors_all <- predictors_all[predictors_all!="DATE_COL"] 30 | all_cf_dat <- data.frame(ltmData[predictors_all],LogCHLA=log10(ltmData$CHLA)) 31 | all_cf_dat <- all_cf_dat[complete.cases(all_cf_dat),] 32 | ts_brks <- c(min(all_cf_dat$LogCHLA),log10(2),log10(7),log10(30),max(all_cf_dat$LogCHLA)) 33 | ts_cats <- c("oligo","meso","eu","hyper") 34 | x<-crossval_rf(all_cf_dat$LogCHLA,all_cf_dat[,names(all_cf_dat)!="LogCHLA"], 35 | ts_brks,ts_cats,0.8,1000,1000) 36 | } 37 | -------------------------------------------------------------------------------- /man/class_prob_rf.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class_prob_rf.R 3 | \name{class_prob_rf} 4 | \alias{class_prob_rf} 5 | \title{Get Class Prediction Probabilities} 6 | \usage{ 7 | class_prob_rf( 8 | rf_obj, 9 | newdata, 10 | breaks, 11 | labels, 12 | ordered = FALSE, 13 | type = c("probs", "votes") 14 | ) 15 | } 16 | \arguments{ 17 | \item{rf_obj}{a randomForest object of type regression} 18 | 19 | \item{newdata}{data frame used to make predictions. Can be same as original 20 | data.} 21 | 22 | \item{breaks}{a numeric vector of values used to turn predictions into classes} 23 | 24 | \item{labels}{a character vector of labels for the classes} 25 | 26 | \item{ordered}{logical indicating if categories are ordered (in order specified 27 | in labels)} 28 | 29 | \item{type}{a character vector indicating whether total votes or probabilites 30 | should be returned} 31 | } 32 | \value{ 33 | returns a dataframe of probabilites or number of votes for each class 34 | } 35 | \description{ 36 | This function takes a regression randomForest and returns class probabilities 37 | for a provided classifcation. These probabilities are based on a full, new dataset. 38 | If using the dataset used to build the random forest these are not out of 39 | bag estimates. The predicted classes that are output are directly from the random forest object, 40 | thus they are predictions resulting from the out of bag esimates. 41 | } 42 | -------------------------------------------------------------------------------- /man/multiplot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/multiplot.R 3 | \name{multiplot} 4 | \alias{multiplot} 5 | \title{Create Mulitple Plots with ggplots (from Winston Chang)} 6 | \usage{ 7 | multiplot(..., plotlist = NULL, cols = 1, layout = NULL) 8 | } 9 | \arguments{ 10 | \item{...}{can pass ggplot objects} 11 | 12 | \item{plotlist}{alternative to ..., list of ggplot objects} 13 | 14 | \item{cols}{Number of columns in layout} 15 | 16 | \item{layout}{A matrix specifying the layout. If present, 'cols' is ignored. 17 | If the layout is something like matrix(c(1,2,3,3), nrow=2, byrow=TRUE), 18 | then plot 1 will go in the upper left, 2 will go in the upper right, and 19 | 3 will go all the way across the bottom.} 20 | } 21 | \description{ 22 | This is the Multiple plot function from 23 | \href{http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_(ggplot2)}{R-Cookbook}. 24 | I have merely cleaned up some of the params for my use, added some documentation and examples. 25 | } 26 | \examples{ 27 | x<-rnorm(100) 28 | y<-jitter(x,10000) 29 | img <- readJPEG(system.file('img', 'Rlogo.jpg', package='jpeg')) 30 | xdf<-data.frame(x=x,y=y) 31 | firstplot<-ggplot(xdf,aes(x=x,y=y))+ geom_point() 32 | secondplot<-ggplot(xdf,aes(x=x))+ geom_bar() 33 | thirdplot<-ggplot(xdf, aes(x,y)) + 34 | annotation_custom(rasterGrob(img, width=unit(1,'npc'), height=unit(1,'npc')), 35 | -Inf, Inf, -Inf, Inf) 36 | thirdplot 37 | svg("test.svg",width=8) 38 | multiplot(thirdplot,secondplot,firstplot,firstplot,layout=matrix(c(1,2,3,4),ncol=4,byrow=F)) 39 | dev.off() 40 | 41 | } 42 | -------------------------------------------------------------------------------- /man/plotCdf.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plotCdf.R 3 | \name{plotCdf} 4 | \alias{plotCdf} 5 | \title{plotCDF Function to create CDFs of chla, ts, and cyano} 6 | \usage{ 7 | plotCdf(catVar, contVar, cdf_colors = 1:length(catVar), ...) 8 | } 9 | \arguments{ 10 | \item{catVar}{the categorical Variable such as-'bvCat', 'TS_CHLA_2', 'TS_CHLA_3', 'TS_CHLA_4'. 11 | Of same length as contVar} 12 | 13 | \item{contVar}{the continuous Variable such as-'sumBioV','CHLA', 'NTL', 'PTL', etc. Of same 14 | length as contVar} 15 | 16 | \item{cdf_colors}{colors for CDF plots and median line -should equal # of categories in catVar + 1} 17 | 18 | \item{...}{pass additional parameters to labs (e.g. set titles, axis labels, etc.)} 19 | } 20 | \description{ 21 | This functions produces CDF plots from the hkm2014Data. The implementation may be used more 22 | widely though to create cumulative distribution functions for multiple categories 23 | } 24 | \examples{ 25 | devtools::install_github('wesanderson','karthik') 26 | library(wesanderson) 27 | data(LakeTrophicModelling) 28 | plotCdf(ltmData$bvCat,ltmData$CHLA,cdf_colors=wes.palette(3,'Royal1'),y='Percent', 29 | x=expression(paste('Log10(Chl ', italic("a"),')')),title='CDF for category bvCat', 30 | color="Biovolume\nCategories") 31 | plotCdf(ltmData$TS_CHLA_3,ltmData$sumBioV+1,cdf_colors=wes.palette(3,'FantasticFox'), 32 | y='Percent',x='Log10(Cyanobacterial Biovolume)', 33 | title=expression(paste('CDF for Chlorophyll ', italic("a"),' Trophic States (3 Categories)')), 34 | color="Trophic State\nCategories") 35 | 36 | } 37 | -------------------------------------------------------------------------------- /R/runRandomForest.R: -------------------------------------------------------------------------------- 1 | #' runRandomForest 2 | #' 3 | #' This function takes the output of iterVarSelRF and runs a random forest. 4 | #' 5 | #' @param indVar independent variables 6 | #' @param depVar dependent variable 7 | #' @param ntree to be passed to randomForest. Had trouble getting ... to work with the snowfall wrapper 8 | #' function. This was a quick hack. 9 | #' @param importance to be passed to randomForest. Had trouble getting ... to work with the snowfall wrapper 10 | #' function. This was a quick hack. 11 | #' @param proximity to be passed to randomForest. Had trouble getting ... to work with the snowfall wrapper 12 | #' function. This was a quick hack. 13 | #' 14 | #' @examples 15 | #' data(LakeTrophicModelling) 16 | #' x2<-iterVarSelRF(ltmData[predictors_gis],ltmData$TS_CHLA_4,10,4,ntree=10,ntreeIterat=5, 17 | #' vars.drop.frac=NULL,vars.drop.num=1,time=FALSE) 18 | #' x2_vars<-unique(unlist(x2)) 19 | #' gis_ts4_rf<-runRandomForest(ltmData[x2_vars],ltmData$TS_CHLA_4, ntree=10,importance=TRUE,proximity=TRUE) 20 | #' @export 21 | #' @import randomForest 22 | runRandomForest <- function(indVar, depVar, ntree = 100, 23 | importance = TRUE, proximity = TRUE) { 24 | 25 | # Only Pass Complete Cases 26 | comp_case <- complete.cases(indVar, depVar) 27 | if (length(indVar) > 1) { 28 | indVar <- indVar[comp_case, ] 29 | } else { 30 | indVar <- indVar[comp_case] 31 | } 32 | depVar <- depVar[comp_case] 33 | 34 | 35 | return(randomForest(indVar, depVar, ntree = ntree, 36 | importance = importance, proximity = proximity)) 37 | 38 | } 39 | -------------------------------------------------------------------------------- /man/iterVarSelRF.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/iterVarSelRF.R 3 | \name{iterVarSelRF} 4 | \alias{iterVarSelRF} 5 | \title{iterVarSelRF} 6 | \usage{ 7 | iterVarSelRF( 8 | indVar, 9 | depVar, 10 | numRun = 10, 11 | numCore = 1, 12 | outStr = tempfile(tmpdir = getwd()), 13 | ntree = 10, 14 | ntreeIterat = 5, 15 | vars.drop.frac = NULL, 16 | vars.drop.num = 1, 17 | time = FALSE 18 | ) 19 | } 20 | \arguments{ 21 | \item{indVar}{independent variables} 22 | 23 | \item{depVar}{dependent variable} 24 | 25 | \item{numRun}{number of iterations. default is 10} 26 | 27 | \item{numCore}{number of cores to split runs across. defualt is 1} 28 | 29 | \item{outStr}{string to append to output files. Defaults to a tmp file} 30 | 31 | \item{time}{logical true will output overall time for the run.} 32 | } 33 | \description{ 34 | This function iterates the `varselRF` function to capture variability in the 35 | possibly selected variables. This process forms the basis of the analysis 36 | conducted in Hollister, Kreakie, and Milsted (2014). We us the proportion 37 | of iterations that a given variable is selected as a variable selection 38 | metric. A parallel implementation is possible using `snowfall`. User only need 39 | specify the number of cores to use. Function relies on knitr,snowfall,parallel, 40 | and varSelRF 41 | } 42 | \examples{ 43 | data(LakeTrophicModelling) 44 | x1<-iterVarSelRF(ltmData[predictors_gis],ltmData$TS_CHLA_4,10,ntree=10,ntreeIterat=5, 45 | vars.drop.frac=NULL,vars.drop.num=1,time=TRUE) 46 | x2<-iterVarSelRF(ltmData[predictors_gis],ltmData$TS_CHLA_4,10,4,ntree=10,ntreeIterat=5, 47 | vars.drop.frac=NULL,vars.drop.num=1,time=TRUE) 48 | } 49 | -------------------------------------------------------------------------------- /R/ecor_map.R: -------------------------------------------------------------------------------- 1 | #' Create map of Ecoregions 2 | #' 3 | #' Function to generate Map 1 in hkm2014ESA poster 4 | #' 5 | #' @param states data for states, as data.frame 6 | #' @param lakes point locations for lake samples as data.frame 7 | #' @param myColor vector of length 3 with colors for fill, lines, and points in that order 8 | #' 9 | #' @examples 10 | #' wsa9<-readOGR("../inst/extdata/","wsa9_low48") 11 | #' ecor_map(wsa9) 12 | #' @export 13 | #' @import ggplot2 14 | ecor_map<-function(ecor){ 15 | #borrowed from: https://github.com/hadley/ggplot2/wiki/plotting-polygon-shapefiles#workaround-forced-layering-of-geom_plot 16 | ecor@data$id <- rownames(ecor@data) 17 | ecor_f <- fortify(ecor, region="WSA_9") 18 | names(ecor_f)[which(names(ecor_f)=="id")] = "WSA_9" 19 | ecor_df <- plyr::join(ecor_f, ecor@data, by="WSA_9") 20 | gmap<-ggplot(ecor_df, aes(long,lat,group=group,fill=WSA_9)) + 21 | geom_polygon(data=subset(ecor_df,WSA_9!="Western\nMountains (WMT)")) + 22 | geom_polygon(data=subset(ecor_df,WSA_9=="Western\nMountains (WMT)")) + 23 | geom_path(color="lightgrey") + 24 | coord_equal() + 25 | coord_map("albers", lat2 = 45.5, lat1 = 29.5)+ 26 | theme(panel.background = element_rect(fill="white"), panel.grid = element_blank(), 27 | panel.border = element_blank(), 28 | axis.text = element_blank(),axis.ticks = element_blank(), 29 | legend.text = element_text(size=10), 30 | legend.position = c(0.96,0.5), 31 | #legend.justification = c(0,0), 32 | legend.key.width = unit(0.5, "line"), 33 | legend.key.height = unit(1.6, "line"), 34 | legend.margin = unit(0,"line"), 35 | plot.margin = unit(c(1,3,0.5,0.5),"line") 36 | ) + 37 | ylab("") + 38 | xlab("") + 39 | scale_fill_manual(name="",values=viridis(10)) 40 | 41 | return(gmap) 42 | } -------------------------------------------------------------------------------- /R/varsel_regression_rf.R: -------------------------------------------------------------------------------- 1 | #' Variable Selection with Regression RF 2 | #' 3 | #' Similar approach to varSelRF, but for regresssion. Use full model to rank 4 | #' variables based on either %IncMSE or Gini. To use %IncMSE set 5 | #' imporatance = TRUE. It then steps through that sorted variable list with 6 | #' most important first and runs RF, store variables and %MSE of model. 7 | #' Note: this sorts on Gini, by default. importance = TRUE ensures %IncMSE. 8 | #' @param y response a vector 9 | #' @param x predictors a data.frame 10 | #' @param ... options to pass to randomForest 11 | #' @export 12 | #' @import randomForest 13 | #' @examples 14 | #' data(LakeTrophicModelling) 15 | #' predictors_all <- predictors_all[predictors_all!="DATE_COL"] 16 | #' all_dat <- data.frame(ltmData[predictors_all],LogCHLA=log10(ltmData$CHLA)) 17 | #' all_dat <- all_dat[complete.cases(all_dat),] 18 | #' x<-varsel_regression_rf(all_dat$LogCHLA,all_dat[,names(all_dat)!="LogCHLA"], 19 | #' ntree=100,prog=T, importance = TRUE) 20 | varsel_regression_rf <- function(y,x,prog=F,...){ 21 | out <- list(mse=NULL,rsq=NULL,num_var=NULL,vars=NULL) 22 | dat <- data.frame(y=y,x) 23 | init_rf <- randomForest(y=dat$y,x=dat[,names(x)],...) 24 | init_imp <- importance(init_rf) 25 | var_sort <- rownames(init_imp)[order(init_imp[,1],decreasing = TRUE)] 26 | vars <- NULL 27 | for(i in var_sort){ 28 | if(is.null(vars)){ 29 | vars <- c(vars,i) 30 | idx <- 1 31 | } else { 32 | vars <- c(vars,i) 33 | vars_rf <- randomForest(y=dat$y,x=dat[,vars],...) 34 | out$mse[[idx]] <- vars_rf$mse[length(vars_rf$mse)] 35 | out$rsq[[idx]] <- vars_rf$rsq[length(vars_rf$rsq)] 36 | out$num_var[[idx]] <- length(vars) 37 | out$vars[[idx]] <- vars 38 | idx <- idx + 1 39 | } 40 | if(prog & idx%%3==0){ 41 | print(paste0(round(idx/length(var_sort)*100,1),"% completed")) 42 | } 43 | } 44 | return(out) 45 | } -------------------------------------------------------------------------------- /vignettes/ecosphere_submission/cover_letter.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: pdf_document 3 | fontsize: 12pt 4 | geometry: 5 | - top=0.05in 6 | - right=0.5in 7 | - left=0.5in 8 | - bottom=0.1in 9 | --- 10 | 11 | ![letterhead](epa_letterhead.jpg) 12 | 13 | September 03, 2015 \newline 14 | 15 | Debra Peters\newline 16 | Editor, *Ecosphere*\newline 17 | USDA ARS\newline 18 | Las Cruces, NM 88003\newline 19 | 20 | Dear Dr. Peters, 21 | 22 | Please accept for your review the submission, "Modelling Lake Trophic State: A Random Forest Approach" to be published in *Ecosphere*. In this article we detail our use of Random Forests to model chlorophyll *a* and trophic state in lakes across the United States. This research makes three important contributions. First, most prior studies of lake trophic state focus on a limited number of lakes that span local or regional extents. Our models are built for lakes that span the conterminous United States. Second, we compare models with and without *in situ* water quality data and find that models with only broadly available data still provide reliable predictions. This allows for predictions to be made in nearly every lakes in the U.S. Third, we utilize a data mining algorithm, Random Forests, to build our model. This approach provides accurate and unbiased predictions. Lastly, we are proponents of practicing open science and as such, use open source tools, open data, and open access publishing whenever possible. Towards that end all of the data and source code for this manuscript are availble as an R package via GitHub (https://github.com/USEPA/LakeTrophicModelling) and a pre-print of this manuscript has been submitted to the PeerJ Preprint server (https://peerj.com/preprints/1319/). We understand that according to ESA policy this does not count as prior publication. 23 | 24 | 25 | Sincerely, 26 | 27 | Jeffrey W. Hollister 28 | 401 782 9655 29 | hollister.jeff@epa.gov 30 | 31 | W. Bryan Milstead 32 | milstead.bryan@epa.gov 33 | 34 | Betty J. Kreakie 35 | kreakie.betty@epa.gov 36 | -------------------------------------------------------------------------------- /R/prob_cdf.R: -------------------------------------------------------------------------------- 1 | #' Function to create CDFs of probability for each trophic state prediction 2 | #' 3 | #' 4 | #' This functions produces CDF plots from predicted trophic state probabilities 5 | #' 6 | #' 7 | #' @param probs1 prediction probabilities for one of the models 8 | #' @param probs2 prediction probabilities for the other model 9 | #' @param ... pass additional parameters to labs (e.g. set titles, axis labels, etc.) 10 | #' 11 | #' @examples 12 | #' devtools::install_github('wesanderson','karthik') 13 | #' library(wesanderson) 14 | #' data(LakeTrophicModelling) 15 | #' prob_cdf(all_rf_ts_prob, gis_rf_ts_prob,x="Prediction Probability",y="Proportion of Samples") 16 | #' @export 17 | #' @import ggplot2 18 | 19 | prob_cdf <- function(probs1, probs2, ...) { 20 | 21 | df<-rbind(probs1,probs2) 22 | df <- na.omit(data.frame(df)) 23 | options(scipen = 5) #tell r not to use scientific notation on axis labels 24 | x <- ggplot(df,aes(x=max,colour=model)) + 25 | stat_ecdf(size=2) + 26 | geom_ribbon(aes(ymin = lower,ymax = upper,fill=model,show_guide=FALSE),alpha = 0.4) + 27 | theme(text = element_text(family="sans"), 28 | panel.background = element_blank(), #panel.grid = element_blank(), 29 | panel.border = element_rect(fill = NA), 30 | plot.title = element_text(family="sans",size=15,face="bold",vjust=1.1), 31 | legend.key = element_rect(fill = 'white'), 32 | legend.text = element_text(family="sans",size=15), legend.title = element_text(size=15), 33 | axis.title.x = element_text(family="sans",vjust = -0.5, size = 12), 34 | axis.title.y = element_text(family="sans",vjust = 1.5, size = 12), 35 | axis.text.x = element_text(family="sans",size = 11), 36 | axis.text.y = element_text(family="sans",size = 11), 37 | legend.position = c(0, 0.975), 38 | legend.justification = c(0, 1)) + 39 | geom_hline(linetype = 3, size = 1, colour = "gray", 40 | yintercept = c(0,0.5,1)) + 41 | labs(...) + 42 | scale_colour_manual(name='',values = viridis(2)) + 43 | scale_fill_manual(name='',values = viridis(2)) 44 | return(x) 45 | } 46 | -------------------------------------------------------------------------------- /R/getCyanoAbund.R: -------------------------------------------------------------------------------- 1 | #' Pulls down cyano abundance from NLA website 2 | #' 3 | #' This function downloads the NLA2007 phytoplankton data and calculates the 4 | #' abundance (cells/ml) of cyanobacteria by lake 5 | #' @return a data.frame with four fields: SITE_ID=the NLA site id for the lake, 6 | #' cyanoCellsPerML=for each SITE_ID the sum of abundance (cells/ml) 7 | #' of all phytoplankton for Division='Cyanophyta', 8 | #' cyanoCat=cyano abundance category based on quartile distribution of cyanoCellsPerML 9 | #' ('LOW'<= Q1; 'MED' >Q1 and =Q4), and 10 | #' mcyst_conc in ug/l 11 | #' 12 | #' 13 | #' @export 14 | 15 | getCyanoAbund<-function(){ 16 | #read the raw data from the EPA website 17 | Raw<-read.csv('http://www2.epa.gov/sites/production/files/2014-10/nla2007_phytoplankton_softalgaecount_20091023.csv') 18 | #subset data-VISIT_NO==1 and Taxonomic Division=='Cyanophyta' 19 | Cyano<-subset(Raw[,c('SITE_ID','DIVISION','OTU','ABUND')],Raw$VISIT_NO==1 & Raw$DIVISION=='Cyanophyta') 20 | #Sum cyano abundance across taxa by NLA SITE_ID 21 | cyanoAbund<-aggregate(Cyano$ABUND,by=list(Cyano$SITE_ID),sum) 22 | #rename fields and round to 1 decimal place 23 | names(cyanoAbund)<-c('SITE_ID','cyanoCellsPerML') 24 | cyanoAbund$cyanoCellsPerML<-round(cyanoAbund$cyanoCellsPerML,1) 25 | #add field for cyanoCat: 'LOW'<= Q1; 'MED' >Q1 and =Q4 26 | cyanoAbund$cyanoCat<-'MED' 27 | cyanoAbund$cyanoCat[cyanoAbund$cyanoCellsPerML<=quantile(cyanoAbund$cyanoCellsPerML,.25,na.rm=T)]<-'LOW' 28 | cyanoAbund$cyanoCat[cyanoAbund$cyanoCellsPerML>=quantile(cyanoAbund$cyanoCellsPerML,.75,na.rm=T)]<-'HIGH' 29 | cyanoAbund$cyanoCat[is.na(cyanoAbund$cyanoCellsPerML)]<-NA 30 | cyanoAbund$cyanoCat<-factor(cyanoAbund$cyanoCat,levels=c('LOW','MED','HIGH'),ordered=TRUE) 31 | #get microsystin data 32 | nla_rec<-read.csv("http://water.epa.gov/type/lakes/assessmonitor/lakessurvey/upload/NLA2007_Recreational_ConditionEstimates_20091123.csv") 33 | nla_rec<-subset(nla_rec,nla_rec$VISIT_NO==1) 34 | cyanoAbund<-merge(cyanoAbund,nla_rec[,c("SITE_ID","MCYST_TL_UGL")],by="SITE_ID",all.x=T) 35 | #output data 36 | return(cyanoAbund) 37 | } 38 | 39 | -------------------------------------------------------------------------------- /R/scatterPlot.R: -------------------------------------------------------------------------------- 1 | #' Scatterplot for hkm2014esa poster 2 | #' 3 | #' Produces a scatterplot via ggplot 4 | #' 5 | #' @examples 6 | #' devtools::install_github("wesanderson","jhollist") 7 | #' library('wesanderson') 8 | #' data(LakeTrophicModelling) 9 | #' mydf<-data.frame(chla=ltmData[["CHLA"]],biovp1=ltmData[["sumBioV"]]+1) 10 | #' zissou2<-wes.palette(5,"Zissou2") 11 | #' scatterPlot(mydf,xvar="chla",yvar="biovp1",zissou2[3],zissou2[2],zissou2[1], 12 | #' title="Chlorophyll and Cyanobacterai Relationship", 13 | #' x=expression(paste('Log10(Chl ', italic("a"),')')), 14 | #' y="Log10(Cyanobaterial Abundance + 1)") 15 | #' @export 16 | #' @import ggplot2 17 | 18 | scatterPlot<-function(df,xvar,yvar,pt_col,ln_col,cl_col,...){ 19 | options(scipen=5) 20 | xdf<-data.frame(xvar=df[[xvar]],yvar=df[[yvar]]) 21 | xdf<-xdf[complete.cases(xdf),] 22 | xlm<-summary(lm(log10(yvar+1)~log10(xvar+1),data=xdf)) 23 | xlm_r<-paste0("Adj. R-squared = ", round(xlm$adj.r.squared,2)) 24 | xlm_p<-paste0("p-value = ", format(pf(xlm$fstatistic[1], 25 | xlm$fstatistic[2], 26 | xlm$fstatistic[3],lower.tail=FALSE), 27 | scientific=TRUE)) 28 | 29 | 30 | x <- ggplot(xdf,aes(xvar,yvar))+ 31 | geom_point(size=3,colour=pt_col) + 32 | scale_x_log10() + 33 | scale_y_log10() + 34 | #stat_smooth(method="lm",fill=cl_col, 35 | # colour=ln_col,size=2) + 36 | #annotate("text", x = 0.25, y = 100000000, label = xlm_r) + 37 | #annotate("text", x = 0.285, y = 20000000, label = xlm_p) + 38 | theme(text = element_text(family="sans"), 39 | panel.background = element_blank(), panel.grid = element_blank(), 40 | panel.border = element_rect(fill = NA), 41 | plot.title = element_text(family="sans",size=12,face="bold",vjust=1.1), 42 | legend.position = "none", legend.key = element_rect(fill = 'white'), 43 | legend.text = element_text(family="sans",size=15), legend.title = element_text(size=11), 44 | axis.title.x = element_text(family="sans",vjust = -0.5, size = 12), 45 | axis.title.y = element_text(family="sans",vjust = 1.5, size = 12), 46 | axis.text.x = element_text(family="sans",size = 11), 47 | axis.text.y = element_text(family="sans",size = 11)) + 48 | labs(...) 49 | 50 | return(x) 51 | } -------------------------------------------------------------------------------- /R/pred_prob_map.R: -------------------------------------------------------------------------------- 1 | #' Create map of discrete predicted probabilities 2 | #' 3 | #' This function takes the predicted class probabilites and maps them for the 4 | #' predicted class 5 | #' 6 | #' @param states data for states, as data.frame 7 | #' @param lakes point locations for lake samples as data.frame with NLA ID 8 | #' @param probs class probabilites with NLA ID 9 | #' 10 | #' @examples 11 | #' state<-map_data('state') 12 | #' lakes_alb<-data.frame(ltmData[["AlbersX"]],ltmData[["AlbersY"]], 13 | #' ltmData[["NLA_ID"]]) 14 | #' p4s<-"+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=37.5 +lon_0=-96 +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs" 15 | #' ll<-"+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs" 16 | #' lakes_alb_sp<-SpatialPointsDataFrame(coordinates(lakes_alb[,1:2]),proj4string=CRS(p4s), 17 | #' data=data.frame(nla_id = as.character(lakes_alb[,3]))) 18 | #' lakes_dd<-spTransform(lakes_alb_sp,CRS=CRS(ll)) 19 | #' lakes_dd<-data.frame(coordinates(lakes_dd),lakes_dd$nla_id) 20 | #' names(lakes_dd)<-c("long","lat","nla_id") 21 | #' pred_prob_map(state,lakes_dd,gis_rf_ts_prob) 22 | #' @export 23 | #' @import ggplot2 24 | pred_prob_map<-function(states,lakes,probs,save_sep=FALSE){ 25 | lakes<-merge(lakes,probs,by="nla_id") 26 | value<-"max" 27 | title<-"" 28 | low<-viridis(3)[2] 29 | high<-viridis(3)[1] 30 | mid_pt<-mean(range(lakes$max)) 31 | gmap<-ggplot(states,aes(x=long,y=lat))+ 32 | geom_polygon(aes(group=group),fill="white",colour="grey")+ 33 | geom_point(data=lakes,aes_string(x="long",y="lat",colour=value),size=2.5)+ 34 | coord_map("albers", lat2 = 45.5, lat1 = 29.5)+ 35 | theme(text = element_text(family="sans"), 36 | panel.background = element_blank(), #panel.grid = element_blank(), 37 | panel.border = element_rect(fill = NA), 38 | plot.title = element_text(family="sans",size=15,face="bold",vjust=1.1), 39 | legend.key = element_rect(fill = 'white'), 40 | legend.text = element_text(family="sans",size=15), legend.title = element_text(size=15), 41 | axis.title.x = element_text(family="sans",vjust = -0.5, size = 12), 42 | axis.title.y = element_text(family="sans",vjust = 1.5, size = 12), 43 | axis.text.x = element_text(family="sans",size = 11), 44 | axis.text.y = element_text(family="sans",size = 11)) + 45 | ggtitle(title)+ 46 | ylab("") + 47 | xlab("") + 48 | scale_colour_gradient2("Probability",low=low,midpoint = mid_pt,high=high) 49 | return(gmap) 50 | } 51 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | LakeTrophicModelling 2 | ==================== 3 | 4 | 5 | [![DOI](https://zenodo.org/badge/doi/10.5281/zenodo.40271.svg)](https://doi.org/10.5281/zenodo.40271) 6 | 7 | Citation for published paper: 8 | 9 | Hollister, J. W., W. B . Milstead, B. J. Kreakie. (2016). Modeling Lake Trophic State: A Random Forest Approach. Ecosphere 7:3 [10.1002/ecs2.1321](https://doi.org/10.1002/ecs2.1321). 10 | 11 | 12 | This repository contains all the materials needed to reproduce Hollister *et al.* (2015) Modeling Lake Trophic State: A Random Forest Approach. These materials are presented as an R Package which contains code used for analyses, code used to develop figures, raw data used for all analysese, and a package vignette that contains the accepted, unformatted version of the manuscript. 13 | 14 | #Install the Package 15 | To install the package and gain access to the materials do the following: 16 | 17 | ``` 18 | install.packages("devtools") 19 | library("devtools") 20 | install_github("USEPA/LakeTrophicModelling") 21 | library("LakeTrophicModelling") 22 | ``` 23 | 24 | All the data used in this manuscript are available via: 25 | 26 | ``` 27 | data(LakeTrophicModelling) 28 | ``` 29 | 30 | And the manuscript vignette can be read via: 31 | NOTE:Not currently (3/30/15) available... 32 | ``` 33 | vignette("manuscript",package="LakeTrophicModelling") 34 | ``` 35 | 36 | #EPA Disclaimer 37 | The United States Environmental Protection Agency (EPA) GitHub project code is provided on an "as is" basis and the user assumes responsibility for its use. EPA has relinquished control of the information and no longer has responsibility to protect the integrity , confidentiality, or availability of the information. Any reference to specific commercial products, processes, or services by service mark, trademark, manufacturer, or otherwise, does not constitute or imply their endorsement, recommendation or favoring by EPA. The EPA seal and logo shall not be used in any manner to imply endorsement of any commercial product or activity by EPA or the United States Government. 38 | 39 | #Thanks 40 | The inspiration for housing this manuscript entierly within a package came from two sources. First, @rmflight has two blog posts about this concept. [First post](http://rmflight.github.io/posts/2014/07/analyses_as_packages.html) lays out the idea and the [second post](http://rmflight.github.io/posts/2014/07/vignetteAnalysis.html) details the steps to do it. Second is @cboettig's [template package](https://github.com/cboettig/template). 41 | 42 | For this I have decided to house the manuscript as a vignette, but build the vignette using the @cboettig's Rmd and latex templates. 43 | -------------------------------------------------------------------------------- /R/crossval_rf.R: -------------------------------------------------------------------------------- 1 | #' Cross Validate Random Forests to get Categorical Accuracy 2 | #' 3 | #' Funtion to cross-validate categorical prediction accuracy from 4 | #' resultant chl a. A Random forest of forests... Used to get categorical 5 | #' accuracy. Also returns a cross-validated accuracy of % var explained. 6 | #' 7 | #' @param y response a vector 8 | #' @param x predictors a data.frame 9 | #' @param breaks numeric vector of cut points 10 | #' @param cat categories of response 11 | #' @param split proportion to include in training datset. test set to inverse. 12 | #' @param n number of iterations 13 | #' @import broom party 14 | #' @export 15 | #' @examples 16 | #' data(LakeTrophicModelling) 17 | #' predictors_all <- predictors_all[predictors_all!="DATE_COL"] 18 | #' all_cf_dat <- data.frame(ltmData[predictors_all],LogCHLA=log10(ltmData$CHLA)) 19 | #' all_cf_dat <- all_cf_dat[complete.cases(all_cf_dat),] 20 | #' ts_brks <- c(min(all_cf_dat$LogCHLA),log10(2),log10(7),log10(30),max(all_cf_dat$LogCHLA)) 21 | #' ts_cats <- c("oligo","meso","eu","hyper") 22 | #' x<-crossval_rf(all_cf_dat$LogCHLA,all_cf_dat[,names(all_cf_dat)!="LogCHLA"], 23 | #' ts_brks,ts_cats,0.8,1000,1000) 24 | crossval_rf <- function(y,x, breaks, cat=NULL, split, n, ntree){ 25 | out <- list(summary=NULL,acc=NULL,all=list()) 26 | dat <- data.frame(y=y,x) 27 | for(i in 1:n){ 28 | train_idx <- sample(1:nrow(dat),split*nrow(dat)) 29 | test_idx <-!1:nrow(dat)%in%train_idx 30 | dat_train <-dat[train_idx,] 31 | dat_test <-dat[test_idx,] 32 | cf_train <- cforest(y~., dat=dat_train, 33 | control=cforest_unbiased(ntree=ntree, 34 | mtry=ncol(dat_train)/3)) 35 | cf_pred_test <- as.numeric(predict(cf_train,newdata=dat_test)) 36 | cf_orig_test <- dat_test$y 37 | cf_pred_test_cat <- cut(cf_pred_test,breaks,cat) 38 | cf_orig_test_cat <- cut(dat_test$y,breaks,cat) 39 | out$acc$rmse[[i]]<-glance(lm(cf_pred_test~cf_orig_test))$sigma 40 | out$acc$adjrsq[[i]]<-glance(lm(cf_pred_test~cf_orig_test))$adj.r.squared 41 | out$acc$tot_acc[[i]]<-classAgreement(table(cf_pred_test_cat,cf_orig_test_cat))$diag 42 | out$acc$kappa[[i]]<-classAgreement(table(cf_pred_test_cat,cf_orig_test_cat))$kappa 43 | out$all[[i]]<-list(cf_pred_test=cf_pred_test, 44 | cf_orig_test=cf_orig_test, 45 | cf_pred_test_cat=cf_pred_test_cat, 46 | cf_orig_test_cat=cf_orig_test_cat) 47 | } 48 | out$summary <- list(mean_rmse = mean(out$acc$rmse), 49 | mean_adjrs = mean(out$acc$adjrsq), 50 | mean_tot_acc = mean(out$acc$tot_acc), 51 | mean_kappa = mean(out$acc$kappa)) 52 | return(out) 53 | } -------------------------------------------------------------------------------- /R/partial_plot.R: -------------------------------------------------------------------------------- 1 | #' Create parital dependence plot 2 | #' 3 | #' This function takes the output of randomForest::paritalPlot() and 4 | #' generates a plot via ggplot. 5 | #' 6 | #' @param pd partial dependence from randomForest::partialPlot() 7 | #' @export 8 | partial_plot <- function(pd,xl,yl,...){ 9 | y_scale<-c(min(pd$y),min(pd$y)+diff(range(pd$y))/2,max(pd$y)) 10 | if(!is.factor(pd$x)){ 11 | ggp<-ggplot(data.frame(pd),aes(x=x,y=y))+ 12 | geom_line()+ 13 | theme(text = element_text(family="sans"), 14 | panel.background = element_blank(), panel.grid = element_blank(), 15 | panel.border = element_rect(fill = NA), 16 | plot.title = element_text(family="sans",size=12,face="bold", 17 | vjust=1.1), 18 | legend.position = "none", legend.key = element_rect(fill = 'white'), 19 | legend.text = element_text(family="sans",size=15), 20 | legend.title = element_text(size=11), 21 | axis.title.x = element_text(family="sans",vjust = -0.5, size = 12), 22 | axis.title.y = element_text(family="sans",vjust = 1.5, size = 12), 23 | axis.text.x = element_text(family="sans",size = 10), 24 | axis.text.y = element_text(family="sans",size = 10), 25 | plot.margin = unit(c(1,1,1,1), "lines"), 26 | ...) + 27 | labs(x=xl,y=yl)+ 28 | scale_y_continuous(breaks=y_scale, 29 | label=round(y_scale,2)) 30 | } else { 31 | ggp<-ggplot(data.frame(pd),aes(x=x,y=y))+ 32 | geom_bar(stat = "identity")+ 33 | theme(text = element_text(family="sans"), 34 | panel.background = element_blank(), panel.grid = element_blank(), 35 | panel.border = element_rect(fill = NA), 36 | plot.title = element_text(family="sans",size=12,face="bold", 37 | vjust=1.1), 38 | legend.position = "none", legend.key = element_rect(fill = 'white'), 39 | legend.text = element_text(family="sans",size=15), 40 | legend.title = element_text(size=11), 41 | axis.title.x = element_text(family="sans",vjust = -0.5, size = 12), 42 | axis.title.y = element_text(family="sans",vjust = 1.5, size = 12), 43 | axis.text.x = element_text(angle=50, vjust=0.5,family="sans",size = 11), 44 | axis.text.y = element_text(family="sans",size = 11), 45 | plot.margin = unit(c(1,1,1,1), "lines"), 46 | ...) + 47 | labs(x=xl,y=yl) 48 | 49 | } 50 | return(ggp) 51 | } 52 | 53 | -------------------------------------------------------------------------------- /R/nlaMap.R: -------------------------------------------------------------------------------- 1 | #' Create map of NLA samples 2 | #' 3 | #' Function to generate Map 1 in hkm2014ESA poster 4 | #' 5 | #' @param states data for states, as data.frame 6 | #' @param lakes point locations for lake samples as data.frame 7 | #' @param cats plot ts categories? 8 | #' @param myColor vector of length 3 with colors for fill, lines, and points in that order 9 | #' 10 | #' @examples 11 | #' state<-map_data('state') 12 | #' lakes_alb<-data.frame(nla_id = ltmData[["NLA_ID"]],ltmData[["AlbersX"]],ltmData[["AlbersY"]]) 13 | #' p4s<-"+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=37.5 +lon_0=-96 +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs" 14 | #' ll<-"+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs" 15 | #' lakes_alb_sp<-SpatialPointsDataFrame(coordinates(lakes_alb[,2:3]),proj4string=CRS(p4s),data = lakes_alb["nla_id"]) 16 | #' lakes_dd<-spTransform(lakes_alb_sp,CRS=CRS(ll)) 17 | #' lakes_dd<-data.frame(coordinates(lakes_dd)) 18 | #' names(lakes_dd)<-c("long","lat") 19 | #' nlaMap(state,lakes_dd) 20 | #' @export 21 | #' @import ggplot2 22 | nlaMap<-function(states,lakes,cats=F,myColor=1:3,catColor=NULL){ 23 | #Color Blind Friendly Palette 24 | if(cats){ 25 | gmap<-ggplot(states,aes(x=long,y=lat))+ 26 | geom_polygon(aes(group=group),fill=myColor[2],colour=myColor[1])+ 27 | geom_point(data=lakes,aes(x=long,y=lat,color=factor(data)),size=2.5)+ 28 | scale_color_manual(values=catColor, 29 | name="Trophic\nState", 30 | breaks=c("Oligo", "Meso", "Eu","Hyper"), 31 | labels=c("Oligotrophc", "Mesotrophic", "Eutrophic","Hypereutrophic"))+ 32 | coord_map("albers", lat2 = 45.5, lat1 = 29.5) + 33 | theme(panel.background = element_blank(), 34 | panel.grid = element_blank(), 35 | panel.margin=unit(c(0,0,0,0),"in"), 36 | plot.margin=unit(c(0,0,0,0),"in"), 37 | plot.background = element_blank(), 38 | legend.position = c(0.5,0), 39 | legend.direction="horizontal", 40 | axis.text=element_blank(), 41 | axis.ticks = element_blank(), 42 | axis.title=element_blank()) 43 | } else { 44 | gmap<-ggplot(states,aes(x=long,y=lat))+ 45 | geom_polygon(aes(group=group),fill=myColor[2],colour=myColor[1])+ 46 | geom_point(data=lakes,aes(x=long,y=lat),size=2.5,colour=myColor[3])+ 47 | coord_map("albers", lat2 = 45.5, lat1 = 29.5)+ 48 | theme(panel.background = element_rect(fill="white"), panel.grid = element_blank(), 49 | panel.border = element_blank(), legend.position = "none", 50 | axis.text = element_blank(),axis.ticks = element_blank()) + 51 | ylab("") + 52 | xlab("") 53 | } 54 | return(gmap) 55 | } -------------------------------------------------------------------------------- /inst/extdata/data_def.csv: -------------------------------------------------------------------------------- 1 | variable_names,description,type 2 | PercentImperv_3000m,% Impervious,GIS 3 | WaterPer_3000m,% Water,GIS 4 | IceSnowPer_3000m,% Ice/Snow,GIS 5 | DevOpenPer_3000m,% Developed Open Space,GIS 6 | DevLowPer_3000m,% Low Intensity Development,GIS 7 | DevMedPer_3000m,% Medium Intensity Development,GIS 8 | DevHighPer_3000m,% High Intensity Development,GIS 9 | BarrenPer_3000m,% Barren,GIS 10 | DeciduousPer_3000m,% Decidous Forest,GIS 11 | EvergreenPer_3000m,% Evergreen Forest,GIS 12 | MixedForPer_3000m,% Mixed Forest,GIS 13 | ShrubPer_3000m,% Shrub/Scrub,GIS 14 | GrassPer_3000m,% Grassland,GIS 15 | PasturePer_3000m,% Pasture,GIS 16 | CropsPer_3000m,% Cropland,GIS 17 | WoodyWetPer_3000m,% Woody Wetland,GIS 18 | HerbWetPer_3000m,% Herbaceuos Wetland,GIS 19 | AlbersX,Longitude (Albers meters),GIS 20 | AlbersY,Latitude (Albers meters),GIS 21 | LakeArea,Lake Surface Area (sq. meters),GIS 22 | LakePerim,Lake Perimeter (meters),GIS 23 | ShoreDevel,Shoreline Development Index,GIS 24 | DATE_COL,Date Samples Collected,NLA 25 | WSA_ECO9,Ecoregion,GIS 26 | BASINAREA,Watershed Area (sq. meters),GIS 27 | DEPTHMAX,Maximum Depth (meters),NLA 28 | ELEV_PT,Elevation (meters),GIS 29 | DO2_2M,Dissolved Oxygen (mg/L),NLA 30 | PH_FIELD,pH,NLA 31 | COND,Conductivity (uS/cm),NLA 32 | ANC,Acid Neutralizing Capacity (ueq/L),NLA 33 | TURB,Turbidity (NTU),NLA 34 | TOC,Total Organic Carbon (mg/L),NLA 35 | DOC,Dissolved Organic Carbon (mg/L),NLA 36 | NH4,Ammonium (mg/L),NLA 37 | NO3_NO2,Nitrate/Nitrite (mg N/L),NLA 38 | NTL,Total Nitrogen ($\mu$g/L),NLA 39 | PTL,Total Phosphorus ($\mu$g/L),NLA 40 | CL,Chloride (ueq/L),NLA 41 | NO3,Nitrate (ueq/L),NLA 42 | SO4,Sulfate (ueq/L),NLA 43 | CA,Calcium (ueq/L),NLA 44 | MG,Magnesium (ueq/L),NLA 45 | Na,Sodium (ueq/L),NLA 46 | K,Potassium (ueq/L),NLA 47 | COLOR,Color (PCU),NLA 48 | SIO2,Silica (mg/L),NLA 49 | H,Hydrogen Ions (ueq/L),NLA 50 | OH,Hydroxide (ueq/L),NLA 51 | NH4ION,Calculated Ammonium (ueq/L),NLA 52 | CATSUM,Sum of Cations (ueq/L),NLA 53 | ANSUM2,Sum of Anions using ANC (ueq/L),NLA 54 | ANDEF2,Anion Deficit (ueq/L),NLA 55 | SOBC,Sum of Base Cation (ueq/L),NLA 56 | BALANCE2,Ion Balance (%),NLA 57 | ORGION,Est. Organic Anions (ueq/L),NLA 58 | CONCAL2,Calculated Conductivity (uS/cm),NLA 59 | CONDHO2,D-H-O Calculated Conductivity (uS/cm),NLA 60 | TmeanW,Mean Profile Water Temp. (C),NLA 61 | DDs45,Growing Degree Days (Days),GIS 62 | MaxLength,Maximum Lake Length (m),GIS 63 | MaxWidth,Maximum Lake Width (m),GIS 64 | MeanWidth,Mean Lake Width (m),GIS 65 | FetchN,Fetch from North (m),GIS 66 | FetchNE,Fetch form Northeast (m),GIS 67 | FetchE,Fetch from East (m),GIS 68 | FetchSE,Fetch from Southeast (m),GIS 69 | MaxDepthCorrect,Est. Maximum Lake Depth (m),GIS 70 | VolumeCorrect,Est. Lake Volume (cubic meters),GIS 71 | MeanDepthCorrect,Est. Mean Lake Depth (m),GIS 72 | NPratio,Nitrogen:Phophorus Ratio,NLA 73 | -------------------------------------------------------------------------------- /R/multiplot.R: -------------------------------------------------------------------------------- 1 | #' Create Mulitple Plots with ggplots (from Winston Chang) 2 | #' 3 | #' This is the Multiple plot function from 4 | #' \href{http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_(ggplot2)}{R-Cookbook}. 5 | #' I have merely cleaned up some of the params for my use, added some documentation and examples. 6 | #' 7 | #' @param ... can pass ggplot objects 8 | #' @param plotlist alternative to ..., list of ggplot objects 9 | #' @param cols Number of columns in layout 10 | #' @param layout A matrix specifying the layout. If present, 'cols' is ignored. 11 | #' If the layout is something like matrix(c(1,2,3,3), nrow=2, byrow=TRUE), 12 | #' then plot 1 will go in the upper left, 2 will go in the upper right, and 13 | #' 3 will go all the way across the bottom. 14 | #' 15 | #' @examples 16 | #' x<-rnorm(100) 17 | #' y<-jitter(x,10000) 18 | #' img <- readJPEG(system.file('img', 'Rlogo.jpg', package='jpeg')) 19 | #' xdf<-data.frame(x=x,y=y) 20 | #' firstplot<-ggplot(xdf,aes(x=x,y=y))+ geom_point() 21 | #' secondplot<-ggplot(xdf,aes(x=x))+ geom_bar() 22 | #' thirdplot<-ggplot(xdf, aes(x,y)) + 23 | #' annotation_custom(rasterGrob(img, width=unit(1,'npc'), height=unit(1,'npc')), 24 | #' -Inf, Inf, -Inf, Inf) 25 | #' thirdplot 26 | #' svg("test.svg",width=8) 27 | #' multiplot(thirdplot,secondplot,firstplot,firstplot,layout=matrix(c(1,2,3,4),ncol=4,byrow=F)) 28 | #' dev.off() 29 | #' 30 | #' @export 31 | #' @import ggplot2 32 | 33 | multiplot <- function(..., plotlist = NULL, cols = 1, 34 | layout = NULL) { 35 | require(grid) 36 | 37 | # Make a list from the ... arguments and plotlist 38 | plots <- c(list(...), plotlist) 39 | 40 | numPlots = length(plots) 41 | 42 | # If layout is NULL, then use 'cols' to determine 43 | # layout 44 | if (is.null(layout)) { 45 | # Make the panel ncol: Number of columns of plots 46 | # nrow: Number of rows needed, calculated from # of 47 | # cols 48 | layout <- matrix(seq(1, cols * ceiling(numPlots/cols)), 49 | ncol = cols, nrow = ceiling(numPlots/cols)) 50 | } 51 | 52 | if (numPlots == 1) { 53 | print(plots[[1]]) 54 | 55 | } else { 56 | # Set up the page 57 | grid.newpage() 58 | pushViewport(viewport(layout = grid.layout(nrow(layout), 59 | ncol(layout)))) 60 | 61 | # Make each plot, in the correct location 62 | for (i in 1:numPlots) { 63 | # Get the i,j matrix positions of the regions that 64 | # contain this subplot 65 | matchidx <- as.data.frame(which(layout == 66 | i, arr.ind = TRUE)) 67 | 68 | print(plots[[i]], vp = viewport(layout.pos.row = matchidx$row, 69 | layout.pos.col = matchidx$col)) 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /vignettes/sessioninfo.txt: -------------------------------------------------------------------------------- 1 | R version 3.2.3 (2015-12-10) 2 | Platform: i686-pc-linux-gnu (32-bit) 3 | Running under: Ubuntu 14.04.3 LTS 4 | 5 | locale: 6 | [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C 7 | [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 8 | [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 9 | [7] LC_PAPER=en_US.UTF-8 LC_NAME=C 10 | [9] LC_ADDRESS=C LC_TELEPHONE=C 11 | [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C 12 | 13 | attached base packages: 14 | [1] parallel stats4 grid stats graphics grDevices utils 15 | [8] datasets methods base 16 | 17 | other attached packages: 18 | [1] maptools_0.8-36 sfsmisc_1.0-27 19 | [3] mapproj_1.2-3 maps_2.3-10 20 | [5] rmarkdown_0.8 caret_6.0-47 21 | [7] lattice_0.20-33 dplyr_0.4.2 22 | [9] e1071_1.6-4 rgdal_1.0-4 23 | [11] sp_1.2-0 ggplot2_2.0.0 24 | [13] knitr_1.11 LakeTrophicModelling_0.1 25 | [15] viridis_0.3.1 doParallel_1.0.10 26 | [17] iterators_1.0.7 foreach_1.4.2 27 | [19] interpretR_0.2.3 randomForest_4.6-10 28 | [21] broom_0.3.7 party_1.0-21 29 | [23] strucchange_1.5-1 sandwich_2.3-3 30 | [25] zoo_1.7-12 modeltools_0.2-21 31 | [27] mvtnorm_1.0-2 tidyr_0.2.0 32 | [29] pander_0.5.2 condprob2_2.0 33 | [31] edarf_0.1 wesanderson_0.3.2 34 | [33] autocrop_0.0.1.9000 gridExtra_2.0.0 35 | 36 | loaded via a namespace (and not attached): 37 | [1] Rcpp_0.12.2 raster_2.3-40 magrittr_1.5 38 | [4] MASS_7.3-44 splines_3.2.3 mnormt_1.5-3 39 | [7] colorspace_1.2-6 R6_2.1.1 snowfall_1.84-6 40 | [10] rgeos_0.3-11 gtools_3.5.0 htmltools_0.2.6 41 | [13] class_7.3-14 lme4_1.1-7 assertthat_0.1 42 | [16] digest_0.6.8 Matrix_1.2-3 coin_1.0-24 43 | [19] BradleyTerry2_1.0-6 scales_0.3.0 varSelRF_0.7-5 44 | [22] munsell_0.4.2 minqa_1.2.4 highr_0.5.1 45 | [25] car_2.0-25 plyr_1.8.3 stringr_1.0.0 46 | [28] tools_3.2.3 pbkrtest_0.4-2 nnet_7.3-11 47 | [31] nlme_3.1-122 gtable_0.1.2 mgcv_1.8-7 48 | [34] quantreg_5.11 psych_1.5.4 DBI_0.3.1 49 | [37] lazyeval_0.1.10 yaml_2.1.13 survival_2.38-3 50 | [40] formatR_1.2.1 nloptr_1.0.4 reshape2_1.4.1 51 | [43] AUC_0.3.0 codetools_0.2-14 evaluate_0.8 52 | [46] labeling_0.3 stringi_1.0-1 SparseM_1.6 53 | [49] brglm_0.5-9 foreign_0.8-66 54 | -------------------------------------------------------------------------------- /vignettes/sessionInfo.txt: -------------------------------------------------------------------------------- 1 | R version 3.2.0 (2015-04-16) 2 | Platform: x86_64-w64-mingw32/x64 (64-bit) 3 | Running under: Windows 7 x64 (build 7601) Service Pack 1 4 | 5 | locale: 6 | [1] LC_COLLATE=English_United States.1252 7 | [2] LC_CTYPE=English_United States.1252 8 | [3] LC_MONETARY=English_United States.1252 9 | [4] LC_NUMERIC=C 10 | [5] LC_TIME=English_United States.1252 11 | 12 | attached base packages: 13 | [1] parallel stats4 grid stats graphics grDevices utils 14 | [8] datasets methods base 15 | 16 | other attached packages: 17 | [1] maptools_0.8-36 sfsmisc_1.0-28 18 | [3] mapproj_1.2-4 maps_3.0.0-2 19 | [5] rmarkdown_0.8.1 caret_6.0-58 20 | [7] lattice_0.20-31 interpretR_0.2.3 21 | [9] doParallel_1.0.10 iterators_1.0.8 22 | [11] foreach_1.4.3 randomForest_4.6-12 23 | [13] edarf_0.1 broom_0.3.7 24 | [15] party_1.0-25 strucchange_1.5-1 25 | [17] sandwich_2.3-4 zoo_1.7-12 26 | [19] modeltools_0.2-21 mvtnorm_1.0-3 27 | [21] condprob2_2.0 dplyr_0.4.1 28 | [23] e1071_1.6-7 rgdal_1.1-1 29 | [25] sp_1.2-1 ggplot2_1.0.1 30 | [27] knitr_1.11 LakeTrophicModelling_0.1 31 | [29] viridis_0.3.1 tidyr_0.3.1 32 | [31] pander_0.5.2 wesanderson_0.3.2 33 | 34 | loaded via a namespace (and not attached): 35 | [1] httr_0.6.1 splines_3.2.0 AUC_0.3.0 36 | [4] assertthat_0.1 highr_0.5.1 coin_1.1-1 37 | [7] yaml_2.1.13 quantreg_5.19 digest_0.6.8 38 | [10] minqa_1.2.4 colorspace_1.2-6 htmltools_0.2.6 39 | [13] Matrix_1.2-0 plyr_1.8.3 psych_1.5.8 40 | [16] XML_3.98-1.1 varSelRF_0.7-5 devtools_1.8.0 41 | [19] SparseM_1.7 scales_0.3.0 MatrixModels_0.4-1 42 | [22] lme4_1.1-10 git2r_0.10.1 mgcv_1.8-6 43 | [25] car_2.1-0 TH.data_1.0-6 lazyeval_0.1.10 44 | [28] nnet_7.3-9 pbkrtest_0.4-2 mnormt_1.5-3 45 | [31] proto_0.3-10 survival_2.38-1 magrittr_1.5 46 | [34] memoise_0.2.1 evaluate_0.8 nlme_3.1-120 47 | [37] MASS_7.3-40 foreign_0.8-63 class_7.3-12 48 | [40] tools_3.2.0 formatR_1.2.1 multcomp_1.4-1 49 | [43] stringr_1.0.0 munsell_0.4.2 rversions_1.0.0 50 | [46] snowfall_1.84-6.1 RCurl_1.95-4.6 nloptr_1.0.4 51 | [49] labeling_0.3 bitops_1.0-6 gtable_0.1.2 52 | [52] codetools_0.2-11 DBI_0.3.1 reshape2_1.4.1 53 | [55] gridExtra_2.0.0 rgeos_0.3-15 stringi_1.0-1 54 | [58] Rcpp_0.12.1 55 | -------------------------------------------------------------------------------- /R/plotCdf.R: -------------------------------------------------------------------------------- 1 | #' plotCDF Function to create CDFs of chla, ts, and cyano 2 | #' 3 | #' 4 | #' This functions produces CDF plots from the hkm2014Data. The implementation may be used more 5 | #' widely though to create cumulative distribution functions for multiple categories 6 | #' 7 | #' @param catVar the categorical Variable such as-'bvCat', 'TS_CHLA_2', 'TS_CHLA_3', 'TS_CHLA_4'. 8 | #' Of same length as contVar 9 | #' @param contVar the continuous Variable such as-'sumBioV','CHLA', 'NTL', 'PTL', etc. Of same 10 | #' length as contVar 11 | #' @param cdf_colors colors for CDF plots and median line -should equal # of categories in catVar + 1 12 | #' @param ... pass additional parameters to labs (e.g. set titles, axis labels, etc.) 13 | #' 14 | #' @examples 15 | #' devtools::install_github('wesanderson','karthik') 16 | #' library(wesanderson) 17 | #' data(LakeTrophicModelling) 18 | #' plotCdf(ltmData$bvCat,ltmData$CHLA,cdf_colors=wes.palette(3,'Royal1'),y='Percent', 19 | #' x=expression(paste('Log10(Chl ', italic("a"),')')),title='CDF for category bvCat', 20 | #' color="Biovolume\nCategories") 21 | #' plotCdf(ltmData$TS_CHLA_3,ltmData$sumBioV+1,cdf_colors=wes.palette(3,'FantasticFox'), 22 | #' y='Percent',x='Log10(Cyanobacterial Biovolume)', 23 | #' title=expression(paste('CDF for Chlorophyll ', italic("a"),' Trophic States (3 Categories)')), 24 | #' color="Trophic State\nCategories") 25 | #' 26 | #' @export 27 | #' @import ggplot2 28 | 29 | plotCdf <- function(catVar, contVar, cdf_colors = 1:length(catVar), ...) { 30 | 31 | options(scipen = 5) #tell r not to use scientific notation on axis labels 32 | 33 | keep<-complete.cases(catVar,contVar) 34 | cdf_df<-data.frame(catVar,contVar)[keep,] 35 | x <- ggplot(cdf_df,aes(contVar,colour=catVar)) + 36 | stat_ecdf(size=2)+scale_color_manual(values=cdf_colors)+ 37 | scale_x_log10()+ 38 | theme(text = element_text(family="Times"), 39 | panel.background = element_blank(), panel.grid = element_blank(), 40 | panel.border = element_rect(fill = NA), 41 | plot.title = element_text(family="sans",size=12,face="bold",vjust=1.1), 42 | legend.position = c(0.15,0.75), legend.key = element_rect(fill = 'white'), 43 | legend.text = element_text(family="sans",size=15), legend.title = element_text(family="sans",size=11), 44 | axis.title.x = element_text(family="sans",vjust = -0.5, size = 12), 45 | axis.title.y = element_text(family="sans",vjust = 1.5, size = 12), 46 | axis.text.x = element_text(family="sans",size = 11), 47 | axis.text.y = element_text(family="sans",size = 11)) + 48 | geom_hline(linetype = 3, size = 1, colour = "gray", 49 | yintercept = c(0,0.5,1)) + 50 | labs(...) 51 | return(x) 52 | } 53 | -------------------------------------------------------------------------------- /R/condAccuracy.R: -------------------------------------------------------------------------------- 1 | #' Plot conditional accuracy 2 | #' 3 | #' This function plots the total accuracy as a function of maximum probability. 4 | #' We determine the maximum probability for each lake for a given random forest 5 | #' object and then plot the total accuracy for lakes at each value of x or greater 6 | #' 7 | #' @param rf A random forest object 8 | #' @param ... parameters to be passed to condprob 9 | #' @export 10 | #' @import ggplot2 11 | #' @examples 12 | #' condAccuracy(all_rf_ts_prob,gis_rf_ts_prob,xImpair=0,R=1,xlab="Xc >= Prediction Probability") 13 | condAccuracy<-function(pred_prob1,pred_prob2,xlab="x",...){ 14 | #devtools::install_github("jhollist/condprob2") 15 | max_vote<-pred_prob1$max 16 | obs<-pred_prob1$obs_class 17 | pred<-pred_prob1$pred_class 18 | correct<-pred==obs 19 | cp1<-condprob2::condprob(max_vote,correct,ProbComp="gt",Exceed="gte",...) 20 | max_vote<-pred_prob2$max 21 | obs<-pred_prob2$obs_class 22 | pred<-pred_prob2$pred_class 23 | correct<-pred==obs 24 | cp2<-condprob2::condprob(max_vote,correct,ProbComp="gt",Exceed="gte",...) 25 | #plot(cp$max_vote,cp$Raw.Data.Probability) 26 | cp1<-data.frame(max_vote=cp1$max_vote,Raw.Data.Probability=cp1$Raw.Data.Probability, 27 | model=rep(pred_prob1$model[1],length(cp1[[1]]))) 28 | cp2<-data.frame(max_vote=cp2$max_vote,Raw.Data.Probability=cp2$Raw.Data.Probability, 29 | model=rep(pred_prob2$model[1],length(cp2[[1]]))) 30 | 31 | cp1_k <- vector("numeric",nrow(cp1)) 32 | for(i in 1:nrow(cp1)){ 33 | x<-dplyr::filter(pred_prob1,max>=cp1$max_vote[i]) 34 | cp1_k[i] <- classAgreement(table(x$pred_class,x$obs_class))$kappa 35 | 36 | } 37 | cp2_k <- vector("numeric",nrow(cp2)) 38 | for(i in 1:nrow(cp2)){ 39 | x<-dplyr::filter(pred_prob2,max>=cp2$max_vote[i]) 40 | cp2_k[i] <- classAgreement(table(x$pred_class,x$obs_class))$kappa 41 | } 42 | cp1<<-data.frame(cp1,kappa=cp1_k) 43 | cp2<<-data.frame(cp2,kappa=cp2_k) 44 | df<-rbind(data.frame(cp1,kappa=cp1_k),data.frame(cp2,kappa=cp2_k)) 45 | ggp<-ggplot(df,aes(x=max_vote,y=kappa,colour=model))+ 46 | geom_point(size=2)+ 47 | theme(text = element_text(family="sans"), 48 | panel.background = element_blank(), #panel.grid = element_blank(), 49 | panel.border = element_rect(fill = NA), 50 | plot.title = element_text(family="sans",size=15,face="bold",vjust=1.1), 51 | legend.key = element_rect(fill = 'white'), 52 | legend.text = element_text(family="sans",size=15), legend.title = element_text(size=15), 53 | axis.title.x = element_text(family="sans",vjust = -0.5, size = 12), 54 | axis.title.y = element_text(family="sans",vjust = 1.5, size = 12), 55 | axis.text.x = element_text(family="sans",size = 11), 56 | axis.text.y = element_text(family="sans",size = 11), 57 | legend.position = c(0, 0.975), 58 | legend.justification = c(0, 1)) + 59 | labs(y="Kappa Coefficient",x=xlab) + 60 | scale_colour_manual(name='',values = viridis(2)) 61 | return(ggp) 62 | } -------------------------------------------------------------------------------- /vignettes/fws_submission/cover_letter.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: pdf_document 3 | fontsize: 12pt 4 | geometry: 5 | - top=0.05in 6 | - right=0.5in 7 | - left=0.5in 8 | - bottom=0.1in 9 | --- 10 | 11 | ![letterhead](epa_letterhead.jpg) 12 | 13 | April 07, 2015 \newline 14 | 15 | Pamela Silver, Ph.D.\newline 16 | Editor, *Freshwater Science*\newline 17 | School of Science\newline 18 | Penn State Erie\newline 19 | Erie, PA 16563\newline 20 | 21 | Dear Dr. Silver, 22 | 23 | Please accept for your review the submission, "Modelling Lake Trophic State: A Random Forest Approach" to be published in *Freshwater Science*. In this article we detail our use of Random Forests to model trophic state in lakes across the United States. This research makes three important contributions. First, most prior studies of lake trophic state focus on a limited number of lakes that span local or regional extents. Our models are built for lakes that span the conterminous United States. Second, we compare models with and without *in situ* water quality data and find that models with only broadly available data still provide reliable predictions. This allows for predictions to be made in nearly every lakes in the U.S. Third, we utilize a data mining algorithm, Random Forests, to build our model. This approach provides accurate and unbiased predictions. 24 | 25 | Our primary data sources are the US EPA's National Lakes Assessment from 2007, the National Land Cover Dataset from 2006, and predicted lake morphometry, which relies on the National Elevation Dataste and the National Hydrography Dataset Plus. These datasets are provided by the US Government, have all undergone strict and extensive quality assurance and are freely available. There are numerous publications based on these data, including some of our own prior work, most notably Hollister and Milstead (2010), Using GIS to Estimate Lake Volume from Limited Data, Lake and Reservoir Management 26(3), Hollister et al. (2011) Predicting Maximum Lake Depth from Surrounding Topography, PLoS ONE 6(9), and Milstead et al. (2013) Estimating Summer Nutrient Concentrations in Northeastern Lakes from SPARROW Load Predictions and Modeled Hydraulic Residence Time, PLoS ONE 8(11). 26 | 27 | Lastly, we use open source tools, open data, and open access publishing whenever possible. Towards that end all of the data and source code for this manuscript are availble as an R package via GitHub (https://github.com/USEPA/LakeTrophicModelling). We also plan to take advantage of the Open Access publishing options provided by *Freshwater Science* and, if accepted, publish this manuscript as Gold Open Access. We are aware of both the additional cost for this and the page charges required by *Freshwater Science* and are able to cover these costs. We look forward to the review process and are hopeful that our manuscript can find a home in *Freshwater Science*. 28 | 29 | 30 | Sincerely, 31 | 32 | Jeffrey W. Hollister 33 | 401 782 9655 34 | hollister.jeff@epa.gov 35 | 36 | W. Bryan Milstead 37 | milstead.bryan@epa.gov 38 | 39 | Betty J. Kreakie 40 | kreakie.betty@epa.gov 41 | -------------------------------------------------------------------------------- /R/importancePlot.R: -------------------------------------------------------------------------------- 1 | #' Random Forest Variable Importance Plotting 2 | #' 3 | #' @param rf a randomForest object 4 | #' @param type the type of importance to plot "acc" for Mean Decrease Accuracy, and 5 | #' "gini for Mean Decrease Gini. 6 | #' @param ... any items that can be passed to geom_point. Mostly used to control size 7 | #' and color of points. 8 | #' 9 | #' @export 10 | #' @import ggplot2 11 | #' @examples 12 | #' require(wesanderson) 13 | #' data(iris) 14 | #' iris_rf<-randomForest(iris[,1:4],iris[,5],importance=T,proximity=T) 15 | #' importancePlot(iris_rf,'acc',size=10,aes(colour=wes.palette(4, 'GrandBudapest'))) 16 | #' importancePlot(iris_rf,'gini',size=10,aes(colour=wes.palette(4, 'GrandBudapest'))) 17 | 18 | importancePlot <- function(rf, sumtbl=NULL, data_def = NULL, type = c("acc", "gini"), ...) { 19 | 20 | idf<-importance(rf) 21 | browser() 22 | # set up data.frame for ggplot 23 | if (type == "gini") { 24 | imp_df <- data.frame(variables = names(idf[,dim(idf)[2]]), 25 | Mean_Decrease = idf[,dim(idf)[2]]) 26 | o <- order(imp_df$Mean_Decrease, decreasing = FALSE) 27 | imp_df$variables <- factor(imp_df$variables, 28 | levels = imp_df$variables[o], ordered = T) 29 | label <- "Mean Decrease Gini" 30 | } else if (type == "acc") { 31 | imp_df <- data.frame(variables = names(idf[,dim(idf)[2]-1]), 32 | Mean_Decrease = idf[,dim(idf)[2]-1]) 33 | o <- order(imp_df$Mean_Decrease, decreasing = FALSE) 34 | imp_df$variables <- factor(imp_df$variables, 35 | levels = imp_df$variables[o], ordered = T) 36 | label <- "Percent Increase in Mean Square Error" 37 | } else { 38 | stop("Type not specificed correctly") 39 | } 40 | if(!is.null(sumtbl)){ 41 | imp_df<-merge(imp_df,sumtbl,by.x="variables",by.y="Variable") 42 | } 43 | if (!is.null(data_def)){ 44 | imp_df$variables<-data_def$description[match(imp_df$variables,data_def$variable_names)] 45 | o <- order(imp_df$Mean_Decrease, decreasing = FALSE) 46 | imp_df$variables <- factor(imp_df$variables, 47 | levels = imp_df$variables[o], ordered = T) 48 | ylabels <- as.character(imp_df$variables[o]) 49 | ylabels[19] <- expression(paste("Total Phosphorus (", mu, "g/L)",sep="")) 50 | ylabels[18] <- expression(paste("Total Nitrogen (", mu, "g/L)",sep="")) 51 | } 52 | 53 | x <- ggplot(imp_df, aes(Mean_Decrease, variables)) + 54 | geom_point(...) + 55 | geom_hline(linetype = 3, size = 1, colour = "gray", 56 | yintercept = 1:nlevels(imp_df$variables)) + 57 | geom_point(...) + 58 | theme(text = element_text(family="Times"), 59 | panel.background = element_blank(), panel.grid = element_blank(), 60 | panel.border = element_rect(fill = NA), legend.position = "none", 61 | axis.title.x = element_text(family="sans",face = "bold", vjust = -0.5, size = 12), 62 | axis.text = element_text(family="sans",size = 11,color = "black")) + 63 | ylab("") + 64 | xlab(label) + 65 | scale_y_discrete(labels=ylabels) 66 | 67 | return(x) 68 | } 69 | -------------------------------------------------------------------------------- /R/class_prob_rf.R: -------------------------------------------------------------------------------- 1 | #' Get Class Prediction Probabilities 2 | #' 3 | #' This function takes a regression randomForest and returns class probabilities 4 | #' for a provided classifcation. These probabilities are based on a full, new dataset. 5 | #' If using the dataset used to build the random forest these are not out of 6 | #' bag estimates. The predicted classes that are output are directly from the random forest object, 7 | #' thus they are predictions resulting from the out of bag esimates. 8 | #' 9 | #' @param rf_obj a randomForest object of type regression 10 | #' @param newdata data frame used to make predictions. Can be same as original 11 | #' data. 12 | #' @param breaks a numeric vector of values used to turn predictions into classes 13 | #' @param labels a character vector of labels for the classes 14 | #' @param ordered logical indicating if categories are ordered (in order specified 15 | #' in labels) 16 | #' @param type a character vector indicating whether total votes or probabilites 17 | #' should be returned 18 | #' @return returns a dataframe of probabilites or number of votes for each class 19 | #' @export 20 | class_prob_rf <- function(rf_obj,newdata,breaks,labels,ordered=FALSE, 21 | type=c("probs","votes")){ 22 | if(rf_obj$type!="regression"){ 23 | stop("rf_obj is not a regression randomForest object.") 24 | } 25 | 26 | get_oob_predictions <- function(rf_obj, newdata){ 27 | if(!"inbag" %in% names(rf_obj)){stop("The in bag matrix is not present. Try re-running random forest with keep.inbag = T.")} 28 | rf_pred <- predict(rf_obj, newdata = newdata, predict.all = TRUE) 29 | rf_inbag <- rf_obj$inbag 30 | rf_inbag[rf_inbag != 0] <- NA 31 | rf_pred$individual + rf_inbag 32 | } 33 | type <- match.arg(type) 34 | preds <- predict(rf_obj,newdata=newdata,predict.all=TRUE) 35 | preds_df <- data.frame(preds$individual) 36 | class_prob <- apply(preds_df,2, function(x) cut(x,breaks,labels)) 37 | row.names(class_prob)<-row.names(preds_df) 38 | if(type=="probs"){ 39 | class_prob <- apply(class_prob,1, function(x) 40 | table(factor(x,levels=labels, ordered=ordered))/rf_obj$ntree) 41 | } else { 42 | class_prob <- apply(class_prob,1, function(x) 43 | table(factor(x,levels=labels, ordered=ordered))) 44 | } 45 | class_prob<-data.frame(t(class_prob)) 46 | class_prob$nla_id<-row.names(class_prob) 47 | class_prob$max <- apply(class_prob[,1:4],1,max) 48 | class_prob$pred_class_oob <- cut(rf_obj$predicted,breaks,labels) 49 | class_prob$pred_class <- cut(predict(rf_obj,newdata=newdata), breaks, labels) 50 | class_prob$obs_class <- cut(rf_obj$y,breaks,labels) 51 | row.names(class_prob)<-as.character(1:nrow(class_prob)) 52 | oob_pred <- data.frame(get_oob_predictions(rf_obj,newdata)) 53 | oob_class_prob <- apply(oob_pred,2, function(x) cut(x,breaks,labels)) 54 | row.names(oob_class_prob)<-row.names(oob_pred) 55 | if(type=="probs"){ 56 | oob_class_prob <- apply(oob_class_prob,1, function(x) 57 | table(factor(x,levels=labels, ordered=ordered))/length(na.omit(oob_class_prob[1,]))) 58 | } else { 59 | oob_class_prob <- apply(oob_class_prob,1, function(x) 60 | table(factor(x,levels=labels, ordered=ordered))) 61 | } 62 | oob_class_prob<-data.frame(t(oob_class_prob)) 63 | oob_class_prob$nla_id<-row.names(oob_class_prob) 64 | names(oob_class_prob)[1:4] <- c("oligo_oob", "meso_oob", "eu_oob", 65 | "hyper_oob") 66 | class_prob <- left_join(class_prob, oob_class_prob) 67 | return(class_prob) 68 | } -------------------------------------------------------------------------------- /R/ts_prob_map.R: -------------------------------------------------------------------------------- 1 | #' Create map of trophic state probabilities 2 | #' 3 | #' This function takes the predicted class probabilites and maps them for each trophic 4 | #' state. 5 | #' 6 | #' @param states data for states, as data.frame 7 | #' @param lakes point locations for lake samples as data.frame with NLA ID 8 | #' @param probs class probabilites with NLA ID 9 | #' 10 | #' @examples 11 | #' state<-map_data('state') 12 | #' lakes_alb<-data.frame(ltmData[["AlbersX"]],ltmData[["AlbersY"]], 13 | #' ltmData[["NLA_ID"]]) 14 | #' p4s<-"+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=37.5 +lon_0=-96 +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs" 15 | #' ll<-"+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs" 16 | #' lakes_alb_sp<-SpatialPointsDataFrame(coordinates(lakes_alb[,1:2]),proj4string=CRS(p4s), 17 | #' data=data.frame(nla_id = as.character(lakes_alb[,3]))) 18 | #' lakes_dd<-spTransform(lakes_alb_sp,CRS=CRS(ll)) 19 | #' lakes_dd<-data.frame(coordinates(lakes_dd),lakes_dd$nla_id) 20 | #' names(lakes_dd)<-c("long","lat","nla_id") 21 | #' ts_prob_map(state,lakes_dd,gis_rf_ts_prob) 22 | #' @export 23 | #' @import ggplot2 24 | ts_prob_map<-function(states,lakes,probs,save_sep=FALSE, original = TRUE){ 25 | lakes<-merge(lakes,probs,by="nla_id") 26 | gmap_o<-make_ts_map(states,lakes,"Oligotrophic",high=viridis(4)[1], original)#"#08519c") 27 | gmap_m<-make_ts_map(states,lakes,"Mesotrophic",high=viridis(4)[2], original)#"#756bb1") 28 | gmap_e<-make_ts_map(states,lakes,"Eutrophic", high=viridis(4)[3], original)#"#e6550d") 29 | gmap_h<-make_ts_map(states,lakes,"Hypereutrophic", high=viridis(4)[4], original)#"#de2d26") 30 | gmap_m$theme$plot.margin <- grid::unit(c(0,0,0,-2),"line") 31 | gmap_h$theme$plot.margin <- grid::unit(c(0,0,0,-2),"line") 32 | gmap_o$theme$plot.margin <- grid::unit(c(0,-2,0,0),"line") 33 | gmap_e$theme$plot.margin <- grid::unit(c(0,-2,0,0),"line") 34 | if(save_sep){ 35 | ggsave("oligo_prob.jpg",gmap_o,width=8.5) 36 | ggsave("meso_prob.jpg",gmap_m,width=8.5) 37 | ggsave("eu_prob.jpg",gmap_e,width=8.5) 38 | ggsave("hyper_prob.jpg",gmap_h,width=8.5) 39 | } 40 | 41 | return(multiplot(gmap_o,gmap_e,gmap_m,gmap_h,cols=2)) 42 | } 43 | 44 | #' helper function to generate each map 45 | #' 46 | #' @param states the states 47 | #' @param lake_prob merged lake and prob data 48 | #' @param title title of map 49 | #' @param low lower color 50 | #' @param high higher color 51 | #' @export 52 | make_ts_map <- function(states,lake_prob,title,low,high, original = TRUE){ 53 | browser() 54 | if(original){ 55 | if(title=="Oligotrophic"){value<<-"oligo"} 56 | if(title=="Mesotrophic"){value<<-"meso"} 57 | if(title=="Eutrophic"){value<<-"eu"} 58 | if(title=="Hypereutrophic"){value<<-"hyper"} 59 | } else{ 60 | if(title=="Oligotrophic"){value<<-"oligo_oob"} 61 | if(title=="Mesotrophic"){value<<-"meso_oob"} 62 | if(title=="Eutrophic"){value<<-"eu_oob"} 63 | if(title=="Hypereutrophic"){value<<-"hyper_oob"} 64 | } 65 | 66 | gmap<-ggplot(states,aes(x=long,y=lat))+ 67 | geom_point(data=lake_prob,aes_string(x="long",y="lat",colour=value),size=2.5)+ 68 | geom_polygon(aes(group=group),alpha=0,colour="grey")+ 69 | coord_map("albers", lat2 = 45.5, lat1 = 29.5)+ 70 | theme(panel.background = element_rect(fill="white"), panel.grid = element_blank(), 71 | panel.border = element_blank(), 72 | axis.text = element_blank(),axis.ticks = element_blank(), 73 | plot.margin = grid::unit(c(0,0,0,0),"line"), 74 | legend.key.width=unit(2, "line"), 75 | legend.key.height=unit(0.5, "line"), 76 | legend.position = c(0.5,-0.1), legend.direction="horizontal") + 77 | ggtitle(title)+ 78 | ylab("") + 79 | xlab("") + 80 | scale_colour_gradient("Probability",low="white",high=high, 81 | breaks=c(0.2,0.4,0.6,0.8)) 82 | return(gmap) 83 | } 84 | -------------------------------------------------------------------------------- /R/iterVarSelRF.R: -------------------------------------------------------------------------------- 1 | #' iterVarSelRF 2 | #' 3 | #' This function iterates the `varselRF` function to capture variability in the 4 | #' possibly selected variables. This process forms the basis of the analysis 5 | #' conducted in Hollister, Kreakie, and Milsted (2014). We us the proportion 6 | #' of iterations that a given variable is selected as a variable selection 7 | #' metric. A parallel implementation is possible using `snowfall`. User only need 8 | #' specify the number of cores to use. Function relies on knitr,snowfall,parallel, 9 | #' and varSelRF 10 | #' 11 | #' @param indVar independent variables 12 | #' @param depVar dependent variable 13 | #' @param numRun number of iterations. default is 10 14 | #' @param numCore number of cores to split runs across. defualt is 1 15 | #' @param outStr string to append to output files. Defaults to a tmp file 16 | #' @param time logical true will output overall time for the run. 17 | #' 18 | #' @examples 19 | #' data(LakeTrophicModelling) 20 | #' x1<-iterVarSelRF(ltmData[predictors_gis],ltmData$TS_CHLA_4,10,ntree=10,ntreeIterat=5, 21 | #' vars.drop.frac=NULL,vars.drop.num=1,time=TRUE) 22 | #' x2<-iterVarSelRF(ltmData[predictors_gis],ltmData$TS_CHLA_4,10,4,ntree=10,ntreeIterat=5, 23 | #' vars.drop.frac=NULL,vars.drop.num=1,time=TRUE) 24 | #' @export 25 | #' @import varSelRF snowfall 26 | 27 | iterVarSelRF <- function(indVar, depVar, numRun = 10, 28 | numCore = 1, outStr = tempfile(tmpdir = getwd()), 29 | ntree = 10, ntreeIterat = 5, vars.drop.frac = NULL, 30 | vars.drop.num = 1, time = FALSE) { 31 | 32 | if (time) { 33 | x1 <- proc.time() 34 | } 35 | 36 | # Only Pass Complete Cases 37 | comp_case <- complete.cases(indVar, depVar) 38 | if (length(indVar) > 1) { 39 | indVar <- indVar[comp_case, ] 40 | } else { 41 | indVar <- indVar[comp_case] 42 | } 43 | depVar <- depVar[comp_case] 44 | 45 | # validate number of cores 46 | if (numCore > parallel::detectCores()) { 47 | return(stop(paste("Your system only has", parallel::detectCores(), 48 | "cores available"))) 49 | } 50 | 51 | # Set up single core/sequential 52 | if (numCore == 1) { 53 | sfInit(parallel = FALSE) 54 | } 55 | 56 | # Set up multiple cores/parallel 57 | if (numCore > 1) { 58 | sfInit(parallel = TRUE, cpus = numCore) 59 | sfExport(list = c("indVar", "depVar", "ntree", 60 | "ntreeIterat", "vars.drop.frac", "vars.drop.num"), 61 | local = TRUE) 62 | sfLibrary(varSelRF) 63 | } 64 | 65 | # varSelRF Function to pass to sfLapply 66 | sfVarSelRF <- function(x) { 67 | outVarSel <- varSelRF(indVar, depVar, ntree = ntree, 68 | ntreeIterat = ntreeIterat, vars.drop.frac = vars.drop.frac, 69 | vars.drop.num = vars.drop.num) 70 | return(outVarSel$selected.vars) 71 | } 72 | 73 | # Run it 74 | result <- sfLapply(1:numRun, sfVarSelRF) 75 | 76 | # summarize variables 77 | summDF <- data.frame() 78 | uniqueVar <- unique(unlist(result)) 79 | for (i in uniqueVar) { 80 | summDF <- rbind(summDF, data.frame(Variable = i, 81 | Percent = sum(unlist(result) %in% i)/numRun)) 82 | } 83 | summDF <- summDF[order(summDF$Percent, decreasing = T), 84 | ] 85 | 86 | # write results to file 87 | write(kable(summDF), paste(outStr, "_variable_summary.md", 88 | sep = "")) 89 | lapply(result, write, paste(outStr, "_selected_variables_ts.csv", 90 | sep = ""), append = T, ncolumns = 1000) 91 | 92 | # stop cluster 93 | sfStop() 94 | 95 | # finish timing 96 | if (time) { 97 | x1 <- proc.time() - x1 98 | result <- c(result, time = x1) 99 | } 100 | 101 | return(result) 102 | } 103 | -------------------------------------------------------------------------------- /vignettes/manuscript_peerj.R: -------------------------------------------------------------------------------- 1 | ## ----setup, include=FALSE, echo=FALSE----------------------------------------- 2 | options(repos="https://cran.rstudio.com") 3 | if(!require(wesanderson)){ 4 | devtools::install_github("jhollist/wesanderson") 5 | } 6 | if(!require(edarf)){ 7 | devtools::install_github("zmjones/edarf/pkg") 8 | } 9 | if(!require(condprob2)){ 10 | devtools::install_github("jhollist/condprob2") 11 | } 12 | if(!require(pander)){ 13 | install.packages("pander") 14 | } 15 | if(!require(tidyr)){ 16 | install.packages("tidyr") 17 | } 18 | if(!require(party)){ 19 | install.packages("party") 20 | } 21 | 22 | if(!require(broom)){ 23 | install.packages("broom") 24 | } 25 | 26 | if(!require(interpretR)){ 27 | install.packages("interpretR") 28 | } 29 | 30 | if(!require(doParallel)){ 31 | install.packages("doParallel") 32 | } 33 | if(!require(viridis)){ 34 | devtools::install_github("CRAN/viridis") 35 | } 36 | 37 | if(!require(LakeTrophicModelling)){ 38 | devtools::install_github("USEPA/LakeTrophicModelling",quick=TRUE) 39 | } 40 | 41 | library("viridis") 42 | library("wesanderson") 43 | library("LakeTrophicModelling") 44 | library("knitr") 45 | library("ggplot2") 46 | library("sp") 47 | library("rgdal") 48 | library("e1071") 49 | library("dplyr") 50 | library("tidyr") 51 | library("condprob2") 52 | library("party") 53 | library("broom") 54 | library("edarf") 55 | #library("caret") 56 | library("randomForest") 57 | library("doParallel") 58 | opts_chunk$set(dev = 'jpeg', dpi=300, fig.width=7.5, knitr.table.format="html") 59 | data(LakeTrophicModelling) 60 | 61 | # 62 | #Checks for existing cache (from another project) 63 | #Else if Repeats running chunk outside of knitr 64 | if(file.exists("prior_cache")){ 65 | for(i in gsub(".rdb","",list.files("prior_cache",".rdb",full.names=T))){ 66 | lazyLoad(i) 67 | } 68 | } else if(file.exists("vignettes/prior_cache")){ 69 | for(i in gsub(".rdb","",list.files("vignettes/prior_cache",".rdb",full.names=T))){ 70 | lazyLoad(i) 71 | } 72 | } else if(file.exists("../prior_cache")){ 73 | for(i in gsub(".rdb","",list.files("../prior_cache",".rdb",full.names=T))){ 74 | lazyLoad(i) 75 | } 76 | } 77 | #multiple caches... silly Jeff 78 | # 79 | if(file.exists("manuscript_cache/latex")){ 80 | for(i in gsub(".rdb","",list.files("manuscript_cache/latex",".rdb",full.names=T))){ 81 | lazyLoad(i) 82 | } 83 | } else if(file.exists("vignettes/manuscript_cache/latex")){ 84 | for(i in gsub(".rdb","",list.files("vignettes/manuscript_cache/latex",".rdb",full.names=T))){ 85 | lazyLoad(i) 86 | } 87 | } else if(file.exists("../manuscript_cache/latex")){ 88 | for(i in gsub(".rdb","",list.files("../manuscript_cache/latex",".rdb",full.names=T))){ 89 | lazyLoad(i) 90 | } 91 | } 92 | 93 | # Table Captions from @DeanK on 94 | #http://stackoverflow.com/questions/15258233/using-table-caption-on-r-markdown-file-using-knitr-to-use-in-pandoc-to-convert-t 95 | 96 | knit_hooks$set(tab.cap = function(before, options, envir) { 97 | if(!before) { 98 | paste('\n\n:', options$tab.cap, sep='') 99 | } 100 | }) 101 | default_output_hook = knit_hooks$get("output") 102 | knit_hooks$set(output = function(x, options) { 103 | if (is.null(options$tab.cap) == FALSE) { 104 | x 105 | } else 106 | default_output_hook(x,options) 107 | }) 108 | 109 | 110 | 111 | ## ----data_setup ,echo=FALSE, message=FALSE------------------------------------ 112 | #All Variables 113 | #Clean Up Data - Complete Cases 114 | predictors_all <- predictors_all[predictors_all!="DATE_COL"] 115 | all_dat <- data.frame(ltmData[predictors_all],LogCHLA=log10(ltmData$CHLA)) 116 | row.names(all_dat)<-ltmData$NLA_ID 117 | all_dat <- all_dat[complete.cases(all_dat),] 118 | 119 | #GIS Variables 120 | #Clean Up Data - Complete Cases 121 | gis_dat <- data.frame(ltmData[predictors_gis],LogCHLA=log10(ltmData$CHLA)) 122 | row.names(gis_dat)<-ltmData$NLA_ID 123 | gis_dat <- gis_dat[complete.cases(gis_dat),] 124 | #ecoregion shape 125 | ecor_path <- system.file("extdata/", package = "LakeTrophicModelling") 126 | wsa9<-readOGR(ecor_path,"wsa9_low48",verbose=FALSE) 127 | 128 | -------------------------------------------------------------------------------- /vignettes/ecosphere_submission/review_first_submission.txt: -------------------------------------------------------------------------------- 1 | Dear Dr. Hollister: 2 | 3 | Thank you very much for submitting your manuscript "Modelling lake trophic state: A random forest approach" to Ecosphere for review. The reviewers and I appreciate the work you have accomplished. Based on the reviews, a major revision would be required before publication. Because this revision will likely take significant time to complete and Ecosphere is a rapid-publication journal, we will not be able to accept this manuscript for publication. However, we encourage you to revise the manuscript according to the review comments and then submit the new manuscript to Ecosphere. 4 | 5 | Should you decide to revise the manuscript for further consideration in Ecosphere, your revisions should address the specific points made by each reviewer. Please include a cover letter, indicating your responses to the review comments and the changes you have made in the manuscript. If you disagree with a reviewer's point, explain why. You would need to submit the new manuscript at http://ecosphere.esapubs.org. Please indicate in the Comment field the manuscript number of the previous submission. The resubmission would be assigned a new manuscript number and may be sent out for additional review. 6 | 7 | Sincerely, 8 | 9 | Debra P. C. Peters 10 | Editor-in-Chief, Ecosphere 11 | 12 | __________________________________________ 13 | 14 | 15 | Reviewer #1 (Comments to Author): 16 | 17 | This manuscript describes the predictive accuracy for lake chlorophyll-a concentration and trophic status by two different random forest models: one which includes all variables available from the EPA National Lakes Assessment and the National Land Cover Dataset; and another which included 'GIS only' NLCD data. The authors showed that the predictive ability of the 'all data' model was higher than the GIS only model; and draw conclusions about the ability of the models to predict risk of cyanobacteria in lakes. One of the main recommendations of the paper is to use this approach in targeting limited management resources to improving water quality. 18 | 19 | The paper is clear, well written, and the methods are extensively documented in publicly available code on Github. I commend the authors on this transparent approach to the scientific process. 20 | 21 | Two general comments on the manuscript: 1) Why didn't the authors spin up a 2nd set of random forest models for cyanobacterial density, given that those data were available? It is not clear why they authors just point to the general relationship between chl-a and cyano density, rather than actually modeling it. 2) The authors rightly acknowledge that the GIS only models do not have great predictive accuracy for any one lake, however the discussion does point to the relevance of this work for making lake-specific management decision. I think it would be very interesting if, in the discussion, the authors focussed on how this method could be applied to questions related to scaling-up process estimates (e.g., GPP contribution from lakes across the nation). Issues related to uncertainty with the in situ and GIS only models might also be informative to such future research efforts. 22 | 23 | ___________________________________ 24 | 25 | Reviewer #2 (Comments to Author): 26 | 27 | The authors present a contrasting set of regression tree models (random forest approach) to model lake trophic state based on the National Lakes Assessment data set. The analysis demonstrates the potential to use landscape analyses to generate probabilistic estimates of lake trophic state, and thus serve as a screening tool for lake classification. As such, it has the potential to make a substantial contribution to the landscape limnology literature. In particular, developing the probabilistic approach ("prediction probability") is a compelling strength of this study, as is the nationally-extensive scope of the data. The paper is well-organized, and well-written, though there are many figures. To broaden the interest of the paper to readers of ESA journals, the introduction could speak more broadly to the problem of ecological classification and its implication for resource management. I do have some specific concerns, however, with the submitted manuscript. 28 | 29 | Foremost, the approach of modeling trophic state as indicated by chlorophyll concentration in the all variables model strikes me as somewhat circular - essentially modeling one well known indicator of trophic state (chlorophyll) using other well-known indicators of trophic state (TP concentration, turbidity). To the point, Carlson's (1996) trophic state index incorporated both TP and chlorophyll concentration. A further concern with the random forest model is that a common and important watershed-derived factor - color - was not included (Soranno et al. 2008). DOC might serve as a proxy, but only roughly so (Pace and Cole 2002). Another concern with the model is the presentation of its utility in application. The authors present a kappa coefficient of 0.6 as a benchmark for model quality, yet both models fell below that threshold (the GIS only model substantially so) - what is the implication? Even if the GIS only model is successful in specific instances (L322), the boundary 30 | conditions for those instances remain uncharacterized. A final concern is the choice of the 3 km buffer for the GIS analysis. Others have explored the scaling problem associated with landscape predictors of lake water quality in much greater detail (Cheruvelil et al. 2013 comes to mind, in particular), and the choice is not well-justified in the methods. 31 | 32 | Beyond the modeling, I had a few other concerns. First, the cyanobacteria analysis is presented only in the discussion, allowing limited scrutiny. If the analysis is of merit, it should be described in the methods and presented in the results. Also, regarding the partial dependence plots, how is TN concentration saturating with respect to chlorophyll concentration given the N:P - chlorophyll concentration relationship shown? 33 | 34 | 35 | ___________________________________ -------------------------------------------------------------------------------- /vignettes/components/elsarticle.latex: -------------------------------------------------------------------------------- 1 | \documentclass[author-year, $layout$, $fontsize$]{$documentclass$} %review=doublespace preprint=single 5p=2 column 2 | %%% Begin My (@cboettig) package additions %%%%%%%%%%%%%%%%%%% 3 | \usepackage[hyphens]{url} 4 | \usepackage{lineno} % add 5 | $if(linenumbers)$ 6 | \linenumbers % turns line numbering on 7 | $endif$ 8 | \bibliographystyle{elsarticle-harv} 9 | \biboptions{sort&compress} % For natbib 10 | \usepackage{graphicx} 11 | \usepackage{booktabs} % book-quality tables 12 | %% Redefines the elsarticle footer 13 | \makeatletter 14 | \def\ps@pprintTitle{% 15 | \let\@oddhead\@empty 16 | \let\@evenhead\@empty 17 | \def\@oddfoot{\it \hfill\today}% 18 | \let\@evenfoot\@oddfoot} 19 | \makeatother 20 | 21 | % A modified page layout 22 | \textwidth 6.75in 23 | \oddsidemargin -0.15in 24 | \evensidemargin -0.15in 25 | \textheight 9in 26 | \topmargin -0.5in 27 | %%%%%%%%%%%%%%%% end my additions to header 28 | 29 | %%% @jhollist Additions%%% 30 | \usepackage[font=$capsize$]{caption} 31 | $if(spacing)$ 32 | \usepackage[$spacing$]{setspace} 33 | $endif$ 34 | \usepackage{parskip} 35 | %%%%%%%%%%%%%%%%%%%%%%%%%%% 36 | 37 | \usepackage[T1]{fontenc} 38 | \usepackage{lmodern} 39 | \usepackage{amssymb,amsmath} 40 | \usepackage{ifxetex,ifluatex} 41 | \usepackage{fixltx2e} % provides \textsubscript 42 | % use upquote if available, for straight quotes in verbatim environments 43 | \IfFileExists{upquote.sty}{\usepackage{upquote}}{} 44 | \ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex 45 | \usepackage[utf8]{inputenc} 46 | $if(euro)$ 47 | \usepackage{eurosym} 48 | $endif$ 49 | \else % if luatex or xelatex 50 | \usepackage{fontspec} 51 | \ifxetex 52 | \usepackage{xltxtra,xunicode} 53 | \fi 54 | \defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase} 55 | \newcommand{\euro}{€} 56 | $if(mainfont)$ 57 | \setmainfont{$mainfont$} 58 | $endif$ 59 | $if(sansfont)$ 60 | \setsansfont{$sansfont$} 61 | $endif$ 62 | $if(monofont)$ 63 | \setmonofont{$monofont$} 64 | $endif$ 65 | $if(mathfont)$ 66 | \setmathfont{$mathfont$} 67 | $endif$ 68 | \fi 69 | % use microtype if available 70 | \IfFileExists{microtype.sty}{\usepackage{microtype}}{} 71 | $if(geometry)$ 72 | \usepackage[$for(geometry)$$geometry$$sep$,$endfor$]{geometry} 73 | $endif$ 74 | $if(natbib)$ 75 | \usepackage{natbib} 76 | \bibliographystyle{plainnat} 77 | $endif$ 78 | $if(biblatex)$ 79 | \usepackage{biblatex} 80 | $if(biblio-files)$ 81 | \bibliography{$biblio-files$} 82 | $endif$ 83 | $endif$ 84 | $if(listings)$ 85 | \usepackage{listings} 86 | $endif$ 87 | $if(lhs)$ 88 | \lstnewenvironment{code}{\lstset{language=Haskell,basicstyle=\small\ttfamily}}{} 89 | $endif$ 90 | $if(highlighting-macros)$ 91 | $highlighting-macros$ 92 | $endif$ 93 | $if(verbatim-in-note)$ 94 | \usepackage{fancyvrb} 95 | $endif$ 96 | $if(tables)$ 97 | \usepackage{longtable} 98 | $endif$ 99 | $if(graphics)$ 100 | \usepackage{graphicx} 101 | % We will generate all images so they have a width \maxwidth. This means 102 | % that they will get their normal width if they fit onto the page, but 103 | % are scaled down if they would overflow the margins. 104 | \makeatletter 105 | \def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth 106 | \else\Gin@nat@width\fi} 107 | \makeatother 108 | \let\Oldincludegraphics\includegraphics 109 | \renewcommand{\includegraphics}[1]{\Oldincludegraphics[width=\maxwidth]{#1}} 110 | $endif$ 111 | \ifxetex 112 | \usepackage[setpagesize=false, % page size defined by xetex 113 | unicode=false, % unicode breaks when used with xetex 114 | xetex]{hyperref} 115 | \else 116 | \usepackage[unicode=true]{hyperref} 117 | \fi 118 | \hypersetup{breaklinks=true, 119 | bookmarks=true, 120 | pdfauthor={$author-meta$}, 121 | pdftitle={$title-meta$}, 122 | colorlinks=true, 123 | urlcolor=$if(urlcolor)$$urlcolor$$else$blue$endif$, 124 | linkcolor=$if(linkcolor)$$linkcolor$$else$magenta$endif$, 125 | pdfborder={0 0 0}} 126 | \urlstyle{same} % don't use monospace font for urls 127 | $if(links-as-notes)$ 128 | % Make links footnotes instead of hotlinks: 129 | \renewcommand{\href}[2]{#2\footnote{\url{#1}}} 130 | $endif$ 131 | $if(strikeout)$ 132 | \usepackage[normalem]{ulem} 133 | % avoid problems with \sout in headers with hyperref: 134 | \pdfstringdefDisableCommands{\renewcommand{\sout}{}} 135 | $endif$ 136 | % @jhollist removed parskip and parindent infavor of parskip package 137 | \setlength{\emergencystretch}{3em} % prevent overfull lines 138 | $if(numbersections)$ 139 | \setcounter{secnumdepth}{5} 140 | $else$ 141 | \setcounter{secnumdepth}{0} 142 | $endif$ 143 | $if(verbatim-in-note)$ 144 | \VerbatimFootnotes % allows verbatim text in footnotes 145 | $endif$ 146 | $if(lang)$ 147 | \ifxetex 148 | \usepackage{polyglossia} 149 | \setmainlanguage{$mainlang$} 150 | \else 151 | \usepackage[$lang$]{babel} 152 | \fi 153 | $endif$ 154 | $for(header-includes)$ 155 | $header-includes$ 156 | $endfor$ 157 | % Pandoc toggle for numbering sections (defaults to be off) 158 | $if(numbersections)$ 159 | $else$ 160 | \setcounter{secnumdepth}{0} 161 | $endif$ 162 | % Pandoc header 163 | $for(header-includes)$ 164 | $header-includes$ 165 | $endfor$ 166 | 167 | \begin{document} 168 | \begin{frontmatter} 169 | \title{$title$} 170 | $for(author)$ 171 | \author[$author.affiliation$]{$author.name$$if(author.footnote)$\corref{c1}$endif$} 172 | $if(author.email)$ \ead{$author.email$} $endif$ 173 | $if(author.footnote)$ \cortext[c1]{$author.footnote$}$endif$ 174 | $endfor$ 175 | $for(address)$ 176 | \address[$address.code$]{$address.address$} 177 | $endfor$ 178 | $if(abstract)$ 179 | \begin{singlespace} 180 | \begin{abstract} 181 | $abstract$ 182 | \end{abstract} 183 | \end{singlespace} 184 | $endif$ 185 | $if(keywords)$ \begin{keyword} $for(keywords)$$keywords$ \sep $endfor$\end{keyword}$endif$ 186 | \end{frontmatter} 187 | 188 | %%@jhollist added singlespace and pulled from frontmatter 189 | 190 | $body$ 191 | 192 | $if(natbib)$ 193 | $if(biblio-files)$ 194 | $if(biblio-title)$ 195 | $if(book-class)$ 196 | \renewcommand\bibname{$biblio-title$} 197 | $else$ 198 | \renewcommand\refname{$biblio-title$} 199 | $endif$ 200 | $endif$ 201 | \bibliography{$biblio-files$} 202 | 203 | $endif$ 204 | $endif$ 205 | $if(biblatex)$ 206 | \printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$ 207 | 208 | $endif$ 209 | $for(include-after)$ 210 | $include-after$ 211 | 212 | $endfor$ 213 | \end{document} 214 | 215 | 216 | -------------------------------------------------------------------------------- /vignettes/fws_submission/components/elsarticle.latex: -------------------------------------------------------------------------------- 1 | \documentclass[author-year, $layout$, $fontsize$]{$documentclass$} %review=doublespace preprint=single 5p=2 column 2 | %%% Begin My (@cboettig) package additions %%%%%%%%%%%%%%%%%%% 3 | \usepackage[hyphens]{url} 4 | \usepackage{lineno} % add 5 | $if(linenumbers)$ 6 | \linenumbers % turns line numbering on 7 | $endif$ 8 | \bibliographystyle{elsarticle-harv} 9 | \biboptions{sort&compress} % For natbib 10 | \usepackage{graphicx} 11 | \usepackage{booktabs} % book-quality tables 12 | %% Redefines the elsarticle footer 13 | \makeatletter 14 | \def\ps@pprintTitle{% 15 | \let\@oddhead\@empty 16 | \let\@evenhead\@empty 17 | \def\@oddfoot{\it \hfill\today}% 18 | \let\@evenfoot\@oddfoot} 19 | \makeatother 20 | 21 | % A modified page layout 22 | \textwidth 6.75in 23 | \oddsidemargin -0.15in 24 | \evensidemargin -0.15in 25 | \textheight 9in 26 | \topmargin -0.5in 27 | %%%%%%%%%%%%%%%% end my additions to header 28 | 29 | %%% @jhollist Additions%%% 30 | \usepackage[font=$capsize$]{caption} 31 | $if(spacing)$ 32 | \usepackage[$spacing$]{setspace} 33 | $endif$ 34 | \usepackage{parskip} 35 | %%%%%%%%%%%%%%%%%%%%%%%%%%% 36 | 37 | \usepackage[T1]{fontenc} 38 | \usepackage{lmodern} 39 | \usepackage{amssymb,amsmath} 40 | \usepackage{ifxetex,ifluatex} 41 | \usepackage{fixltx2e} % provides \textsubscript 42 | % use upquote if available, for straight quotes in verbatim environments 43 | \IfFileExists{upquote.sty}{\usepackage{upquote}}{} 44 | \ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex 45 | \usepackage[utf8]{inputenc} 46 | $if(euro)$ 47 | \usepackage{eurosym} 48 | $endif$ 49 | \else % if luatex or xelatex 50 | \usepackage{fontspec} 51 | \ifxetex 52 | \usepackage{xltxtra,xunicode} 53 | \fi 54 | \defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase} 55 | \newcommand{\euro}{€} 56 | $if(mainfont)$ 57 | \setmainfont{$mainfont$} 58 | $endif$ 59 | $if(sansfont)$ 60 | \setsansfont{$sansfont$} 61 | $endif$ 62 | $if(monofont)$ 63 | \setmonofont{$monofont$} 64 | $endif$ 65 | $if(mathfont)$ 66 | \setmathfont{$mathfont$} 67 | $endif$ 68 | \fi 69 | % use microtype if available 70 | \IfFileExists{microtype.sty}{\usepackage{microtype}}{} 71 | $if(geometry)$ 72 | \usepackage[$for(geometry)$$geometry$$sep$,$endfor$]{geometry} 73 | $endif$ 74 | $if(natbib)$ 75 | \usepackage{natbib} 76 | \bibliographystyle{plainnat} 77 | $endif$ 78 | $if(biblatex)$ 79 | \usepackage{biblatex} 80 | $if(biblio-files)$ 81 | \bibliography{$biblio-files$} 82 | $endif$ 83 | $endif$ 84 | $if(listings)$ 85 | \usepackage{listings} 86 | $endif$ 87 | $if(lhs)$ 88 | \lstnewenvironment{code}{\lstset{language=Haskell,basicstyle=\small\ttfamily}}{} 89 | $endif$ 90 | $if(highlighting-macros)$ 91 | $highlighting-macros$ 92 | $endif$ 93 | $if(verbatim-in-note)$ 94 | \usepackage{fancyvrb} 95 | $endif$ 96 | $if(tables)$ 97 | \usepackage{longtable} 98 | $endif$ 99 | $if(graphics)$ 100 | \usepackage{graphicx} 101 | % We will generate all images so they have a width \maxwidth. This means 102 | % that they will get their normal width if they fit onto the page, but 103 | % are scaled down if they would overflow the margins. 104 | \makeatletter 105 | \def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth 106 | \else\Gin@nat@width\fi} 107 | \makeatother 108 | \let\Oldincludegraphics\includegraphics 109 | \renewcommand{\includegraphics}[1]{\Oldincludegraphics[width=\maxwidth]{#1}} 110 | $endif$ 111 | \ifxetex 112 | \usepackage[setpagesize=false, % page size defined by xetex 113 | unicode=false, % unicode breaks when used with xetex 114 | xetex]{hyperref} 115 | \else 116 | \usepackage[unicode=true]{hyperref} 117 | \fi 118 | \hypersetup{breaklinks=true, 119 | bookmarks=true, 120 | pdfauthor={$author-meta$}, 121 | pdftitle={$title-meta$}, 122 | colorlinks=true, 123 | urlcolor=$if(urlcolor)$$urlcolor$$else$blue$endif$, 124 | linkcolor=$if(linkcolor)$$linkcolor$$else$magenta$endif$, 125 | pdfborder={0 0 0}} 126 | \urlstyle{same} % don't use monospace font for urls 127 | $if(links-as-notes)$ 128 | % Make links footnotes instead of hotlinks: 129 | \renewcommand{\href}[2]{#2\footnote{\url{#1}}} 130 | $endif$ 131 | $if(strikeout)$ 132 | \usepackage[normalem]{ulem} 133 | % avoid problems with \sout in headers with hyperref: 134 | \pdfstringdefDisableCommands{\renewcommand{\sout}{}} 135 | $endif$ 136 | % @jhollist removed parskip and parindent infavor of parskip package 137 | \setlength{\emergencystretch}{3em} % prevent overfull lines 138 | $if(numbersections)$ 139 | \setcounter{secnumdepth}{5} 140 | $else$ 141 | \setcounter{secnumdepth}{0} 142 | $endif$ 143 | $if(verbatim-in-note)$ 144 | \VerbatimFootnotes % allows verbatim text in footnotes 145 | $endif$ 146 | $if(lang)$ 147 | \ifxetex 148 | \usepackage{polyglossia} 149 | \setmainlanguage{$mainlang$} 150 | \else 151 | \usepackage[$lang$]{babel} 152 | \fi 153 | $endif$ 154 | $for(header-includes)$ 155 | $header-includes$ 156 | $endfor$ 157 | % Pandoc toggle for numbering sections (defaults to be off) 158 | $if(numbersections)$ 159 | $else$ 160 | \setcounter{secnumdepth}{0} 161 | $endif$ 162 | % Pandoc header 163 | $for(header-includes)$ 164 | $header-includes$ 165 | $endfor$ 166 | 167 | \begin{document} 168 | \begin{frontmatter} 169 | \title{$title$} 170 | $for(author)$ 171 | \author[$author.affiliation$]{$author.name$$if(author.footnote)$\corref{c1}$endif$} 172 | $if(author.email)$ \ead{$author.email$} $endif$ 173 | $if(author.footnote)$ \cortext[c1]{$author.footnote$}$endif$ 174 | $endfor$ 175 | $for(address)$ 176 | \address[$address.code$]{$address.address$} 177 | $endfor$ 178 | $if(abstract)$ 179 | \begin{singlespace} 180 | \begin{abstract} 181 | $abstract$ 182 | \end{abstract} 183 | \end{singlespace} 184 | $endif$ 185 | $if(keywords)$ \begin{keyword} $for(keywords)$$keywords$ \sep $endfor$\end{keyword}$endif$ 186 | \end{frontmatter} 187 | 188 | %%@jhollist added singlespace and pulled from frontmatter 189 | 190 | $body$ 191 | 192 | $if(natbib)$ 193 | $if(biblio-files)$ 194 | $if(biblio-title)$ 195 | $if(book-class)$ 196 | \renewcommand\bibname{$biblio-title$} 197 | $else$ 198 | \renewcommand\refname{$biblio-title$} 199 | $endif$ 200 | $endif$ 201 | \bibliography{$biblio-files$} 202 | 203 | $endif$ 204 | $endif$ 205 | $if(biblatex)$ 206 | \printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$ 207 | 208 | $endif$ 209 | $for(include-after)$ 210 | $include-after$ 211 | 212 | $endfor$ 213 | \end{document} 214 | 215 | 216 | -------------------------------------------------------------------------------- /vignettes/components/plos.csl: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /vignettes/fws_submission/components/plos.csl: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /vignettes/components/ecology.csl: -------------------------------------------------------------------------------- 1 | 2 | 193 | -------------------------------------------------------------------------------- /vignettes/fws_submission/components/ecology.csl: -------------------------------------------------------------------------------- 1 | 2 | 193 | -------------------------------------------------------------------------------- /vignettes/components/freshwater-science.csl: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /vignettes/fws_submission/components/freshwater-science.csl: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /vignettes/components/default_jwh.latex: -------------------------------------------------------------------------------- 1 | \documentclass[$if(fontsize)$$fontsize$,$endif$$if(lang)$$lang$,$endif$$if(papersize)$$papersize$,$endif$$for(classoption)$$classoption$$sep$,$endfor$]{$documentclass$} 2 | \usepackage[T1]{fontenc} 3 | \usepackage{lmodern} 4 | \usepackage{amssymb,amsmath} 5 | \usepackage{ifxetex,ifluatex} 6 | \usepackage{fixltx2e} % provides \textsubscript 7 | % use upquote if available, for straight quotes in verbatim environments 8 | \IfFileExists{upquote.sty}{\usepackage{upquote}}{} 9 | \ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex 10 | \usepackage[utf8]{inputenc} 11 | $if(euro)$ 12 | \usepackage{eurosym} 13 | $endif$ 14 | \else % if luatex or xelatex 15 | \ifxetex 16 | \usepackage{mathspec} 17 | \usepackage{xltxtra,xunicode} 18 | \else 19 | \usepackage{fontspec} 20 | \fi 21 | \defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase} 22 | \newcommand{\euro}{€} 23 | $if(mainfont)$ 24 | \setmainfont{$mainfont$} 25 | $endif$ 26 | $if(sansfont)$ 27 | \setsansfont{$sansfont$} 28 | $endif$ 29 | $if(monofont)$ 30 | \setmonofont[Mapping=tex-ansi]{$monofont$} 31 | $endif$ 32 | $if(mathfont)$ 33 | \setmathfont(Digits,Latin,Greek){$mathfont$} 34 | $endif$ 35 | \fi 36 | % use microtype if available 37 | \IfFileExists{microtype.sty}{\usepackage{microtype}}{} 38 | $if(geometry)$ 39 | \usepackage[$for(geometry)$$geometry$$sep$,$endfor$]{geometry} 40 | $endif$ 41 | $if(natbib)$ 42 | \usepackage{natbib} 43 | \bibliographystyle{$if(biblio-style)$$biblio-style$$else$plainnat$endif$} 44 | $endif$ 45 | $if(biblatex)$ 46 | \usepackage{biblatex} 47 | $if(biblio-files)$ 48 | \bibliography{$biblio-files$} 49 | $endif$ 50 | $endif$ 51 | $if(listings)$ 52 | \usepackage{listings} 53 | $endif$ 54 | $if(lhs)$ 55 | \lstnewenvironment{code}{\lstset{language=Haskell,basicstyle=\small\ttfamily}}{} 56 | $endif$ 57 | $if(highlighting-macros)$ 58 | $highlighting-macros$ 59 | $endif$ 60 | $if(verbatim-in-note)$ 61 | \usepackage{fancyvrb} 62 | $endif$ 63 | $if(tables)$ 64 | \usepackage{longtable,booktabs} 65 | $endif$ 66 | $if(graphics)$ 67 | \usepackage{graphicx} 68 | % Redefine \includegraphics so that, unless explicit options are 69 | % given, the image width will not exceed the width of the page. 70 | % Images get their normal width if they fit onto the page, but 71 | % are scaled down if they would overflow the margins. 72 | \makeatletter 73 | \def\ScaleIfNeeded{% 74 | \ifdim\Gin@nat@width>\linewidth 75 | \linewidth 76 | \else 77 | \Gin@nat@width 78 | \fi 79 | } 80 | \makeatother 81 | \let\Oldincludegraphics\includegraphics 82 | {% 83 | \catcode`\@=11\relax% 84 | \gdef\includegraphics{\@ifnextchar[{\Oldincludegraphics}{\Oldincludegraphics[width=\ScaleIfNeeded]}}% 85 | }% 86 | $endif$ 87 | \ifxetex 88 | \usepackage[setpagesize=false, % page size defined by xetex 89 | unicode=false, % unicode breaks when used with xetex 90 | xetex]{hyperref} 91 | \else 92 | \usepackage[unicode=true]{hyperref} 93 | \fi 94 | \hypersetup{breaklinks=true, 95 | bookmarks=true, 96 | pdfauthor={$author-meta$}, 97 | pdftitle={$title-meta$}, 98 | colorlinks=true, 99 | citecolor=$if(citecolor)$$citecolor$$else$blue$endif$, 100 | urlcolor=$if(urlcolor)$$urlcolor$$else$blue$endif$, 101 | linkcolor=$if(linkcolor)$$linkcolor$$else$magenta$endif$, 102 | pdfborder={0 0 0}} 103 | \urlstyle{same} % don't use monospace font for urls 104 | $if(links-as-notes)$ 105 | % Make links footnotes instead of hotlinks: 106 | \renewcommand{\href}[2]{#2\footnote{\url{#1}}} 107 | $endif$ 108 | $if(strikeout)$ 109 | \usepackage[normalem]{ulem} 110 | % avoid problems with \sout in headers with hyperref: 111 | \pdfstringdefDisableCommands{\renewcommand{\sout}{}} 112 | $endif$ 113 | \setlength{\parindent}{0pt} 114 | \setlength{\parskip}{6pt plus 2pt minus 1pt} 115 | \setlength{\emergencystretch}{3em} % prevent overfull lines 116 | $if(numbersections)$ 117 | \setcounter{secnumdepth}{5} 118 | $else$ 119 | \setcounter{secnumdepth}{0} 120 | $endif$ 121 | $if(verbatim-in-note)$ 122 | \VerbatimFootnotes % allows verbatim text in footnotes 123 | $endif$ 124 | $if(lang)$ 125 | \ifxetex 126 | \usepackage{polyglossia} 127 | \setmainlanguage{$mainlang$} 128 | \else 129 | \usepackage[$lang$]{babel} 130 | \fi 131 | $endif$ 132 | 133 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 134 | %Changes borrowed from @cboettig, added by @jhollist 135 | % A modified page layout 136 | \textwidth 6.75in 137 | \oddsidemargin -0.15in 138 | \evensidemargin -0.15in 139 | \textheight 9in 140 | \topmargin -0.5in 141 | \usepackage{lineno} % add 142 | $if(linenumbers)$ 143 | \linenumbers % turns line numbering on 144 | $endif$ 145 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 146 | 147 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 148 | %%Packages and layout changes by @jhollist 09/15/2014 149 | \usepackage{ragged2e} 150 | \usepackage[font=$capsize$]{caption} 151 | $if(spacing)$ 152 | \usepackage[$spacing$]{setspace} 153 | $endif$ 154 | \usepackage{parskip} 155 | \usepackage{fancyhdr} 156 | \pagestyle{fancy} 157 | \fancyhf{} 158 | \renewcommand{\headrulewidth}{0pt} 159 | \rfoot{\today} 160 | \lfoot{\thepage} 161 | %%Changed default abstract width 162 | %\renewenvironment{abstract}{% 163 | 164 | \renewenvironment{abstract}{ 165 | \hfill\begin{minipage}{1\textwidth} 166 | \rule{\textwidth}{1pt}\vspace{5pt} 167 | \normalsize 168 | \begin{justify} 169 | \bfseries\abstractname\vspace{5pt} 170 | \end{justify}} 171 | {\par\noindent\rule{\textwidth}{1pt}\end{minipage} 172 | } 173 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 174 | 175 | $if(title)$ 176 | \title{$title$} 177 | $endif$ 178 | $if(subtitle)$ 179 | \subtitle{$subtitle$} 180 | $endif$ 181 | \author{ 182 | $for(author)$ 183 | $if(author.name)$ 184 | $author.name$ 185 | $else$ 186 | $author$ 187 | $endif$ 188 | $endfor$ 189 | } 190 | \date{$date$} 191 | $for(header-includes)$ 192 | $header-includes$ 193 | $endfor$ 194 | 195 | \begin{document} 196 | %%Edited by @jhollist 09/15/2014 197 | %%Adds title from YAML 198 | \begin{singlespace} 199 | $if(title)$ 200 | \begin{center} 201 | \huge $title$ 202 | \end{center} 203 | $endif$ 204 | %%Adds Author, correspond email asterisk, and affilnum from YAML 205 | $if(author)$ 206 | \begin{center} 207 | \large 208 | $for(author)$ 209 | $if(author.name)$ 210 | $author.name$$if(author.affilnum)$$if(author.email)$ \textsuperscript{*}$endif$ \textsuperscript{$author.affilnum$} $endif$ 211 | $else$ 212 | $author$ 213 | $endif$ 214 | $endfor$ 215 | \end{center} 216 | $endif$ 217 | %%Adds affiliations from YAML 218 | \begin{justify} 219 | $if(affiliation)$ 220 | \footnotesize \emph{ 221 | $for(affiliation)$ 222 | \\* 223 | \textsuperscript{$affiliation.affilnum$}$affiliation.affil$\\* 224 | $endfor$ 225 | } 226 | $endif$ 227 | %%Adds corresponding author email(s) from YAML 228 | $if(author)$ 229 | \\[0.1cm] 230 | \footnotesize \emph{ 231 | \textsuperscript{*} corresponding author: 232 | $for(author)$ 233 | $if(author.email)$ 234 | $author.email$ 235 | $endif$ 236 | $endfor$ 237 | } 238 | $endif$ 239 | \end{justify} 240 | %%Adds date from YAML 241 | $if(date)$ 242 | \begin{center} 243 | \small \emph{$date$} \\ 244 | \end{center} 245 | $endif$ 246 | \normalsize 247 | 248 | $if(abstract)$ 249 | \begin{abstract} 250 | $abstract$ 251 | \end{abstract} 252 | $endif$ 253 | \end{singlespace} 254 | 255 | $for(include-before)$ 256 | $include-before$ 257 | 258 | $endfor$ 259 | $if(toc)$ 260 | { 261 | \hypersetup{linkcolor=black} 262 | \setcounter{tocdepth}{$toc-depth$} 263 | \tableofcontents 264 | } 265 | $endif$ 266 | 267 | $body$ 268 | 269 | $if(natbib)$ 270 | $if(biblio-files)$ 271 | $if(biblio-title)$ 272 | $if(book-class)$ 273 | \renewcommand\bibname{$biblio-title$} 274 | $else$ 275 | \renewcommand\refname{$biblio-title$} 276 | $endif$ 277 | $endif$ 278 | \bibliography{$biblio-files$} 279 | 280 | $endif$ 281 | $endif$ 282 | $if(biblatex)$ 283 | \printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$ 284 | 285 | $endif$ 286 | $for(include-after)$ 287 | $include-after$ 288 | 289 | $endfor$ 290 | \end{document} -------------------------------------------------------------------------------- /vignettes/fws_submission/components/default_jwh.latex: -------------------------------------------------------------------------------- 1 | \documentclass[$if(fontsize)$$fontsize$,$endif$$if(lang)$$lang$,$endif$$if(papersize)$$papersize$,$endif$$for(classoption)$$classoption$$sep$,$endfor$]{$documentclass$} 2 | \usepackage[T1]{fontenc} 3 | \usepackage{lmodern} 4 | \usepackage{amssymb,amsmath} 5 | \usepackage{ifxetex,ifluatex} 6 | \usepackage{fixltx2e} % provides \textsubscript 7 | % use upquote if available, for straight quotes in verbatim environments 8 | \IfFileExists{upquote.sty}{\usepackage{upquote}}{} 9 | \ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex 10 | \usepackage[utf8]{inputenc} 11 | $if(euro)$ 12 | \usepackage{eurosym} 13 | $endif$ 14 | \else % if luatex or xelatex 15 | \ifxetex 16 | \usepackage{mathspec} 17 | \usepackage{xltxtra,xunicode} 18 | \else 19 | \usepackage{fontspec} 20 | \fi 21 | \defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase} 22 | \newcommand{\euro}{€} 23 | $if(mainfont)$ 24 | \setmainfont{$mainfont$} 25 | $endif$ 26 | $if(sansfont)$ 27 | \setsansfont{$sansfont$} 28 | $endif$ 29 | $if(monofont)$ 30 | \setmonofont[Mapping=tex-ansi]{$monofont$} 31 | $endif$ 32 | $if(mathfont)$ 33 | \setmathfont(Digits,Latin,Greek){$mathfont$} 34 | $endif$ 35 | \fi 36 | % use microtype if available 37 | \IfFileExists{microtype.sty}{\usepackage{microtype}}{} 38 | $if(geometry)$ 39 | \usepackage[$for(geometry)$$geometry$$sep$,$endfor$]{geometry} 40 | $endif$ 41 | $if(natbib)$ 42 | \usepackage{natbib} 43 | \bibliographystyle{$if(biblio-style)$$biblio-style$$else$plainnat$endif$} 44 | $endif$ 45 | $if(biblatex)$ 46 | \usepackage{biblatex} 47 | $if(biblio-files)$ 48 | \bibliography{$biblio-files$} 49 | $endif$ 50 | $endif$ 51 | $if(listings)$ 52 | \usepackage{listings} 53 | $endif$ 54 | $if(lhs)$ 55 | \lstnewenvironment{code}{\lstset{language=Haskell,basicstyle=\small\ttfamily}}{} 56 | $endif$ 57 | $if(highlighting-macros)$ 58 | $highlighting-macros$ 59 | $endif$ 60 | $if(verbatim-in-note)$ 61 | \usepackage{fancyvrb} 62 | $endif$ 63 | $if(tables)$ 64 | \usepackage{longtable,booktabs} 65 | $endif$ 66 | $if(graphics)$ 67 | \usepackage{graphicx} 68 | % Redefine \includegraphics so that, unless explicit options are 69 | % given, the image width will not exceed the width of the page. 70 | % Images get their normal width if they fit onto the page, but 71 | % are scaled down if they would overflow the margins. 72 | \makeatletter 73 | \def\ScaleIfNeeded{% 74 | \ifdim\Gin@nat@width>\linewidth 75 | \linewidth 76 | \else 77 | \Gin@nat@width 78 | \fi 79 | } 80 | \makeatother 81 | \let\Oldincludegraphics\includegraphics 82 | {% 83 | \catcode`\@=11\relax% 84 | \gdef\includegraphics{\@ifnextchar[{\Oldincludegraphics}{\Oldincludegraphics[width=\ScaleIfNeeded]}}% 85 | }% 86 | $endif$ 87 | \ifxetex 88 | \usepackage[setpagesize=false, % page size defined by xetex 89 | unicode=false, % unicode breaks when used with xetex 90 | xetex]{hyperref} 91 | \else 92 | \usepackage[unicode=true]{hyperref} 93 | \fi 94 | \hypersetup{breaklinks=true, 95 | bookmarks=true, 96 | pdfauthor={$author-meta$}, 97 | pdftitle={$title-meta$}, 98 | colorlinks=true, 99 | citecolor=$if(citecolor)$$citecolor$$else$blue$endif$, 100 | urlcolor=$if(urlcolor)$$urlcolor$$else$blue$endif$, 101 | linkcolor=$if(linkcolor)$$linkcolor$$else$magenta$endif$, 102 | pdfborder={0 0 0}} 103 | \urlstyle{same} % don't use monospace font for urls 104 | $if(links-as-notes)$ 105 | % Make links footnotes instead of hotlinks: 106 | \renewcommand{\href}[2]{#2\footnote{\url{#1}}} 107 | $endif$ 108 | $if(strikeout)$ 109 | \usepackage[normalem]{ulem} 110 | % avoid problems with \sout in headers with hyperref: 111 | \pdfstringdefDisableCommands{\renewcommand{\sout}{}} 112 | $endif$ 113 | \setlength{\parindent}{0pt} 114 | \setlength{\parskip}{6pt plus 2pt minus 1pt} 115 | \setlength{\emergencystretch}{3em} % prevent overfull lines 116 | $if(numbersections)$ 117 | \setcounter{secnumdepth}{5} 118 | $else$ 119 | \setcounter{secnumdepth}{0} 120 | $endif$ 121 | $if(verbatim-in-note)$ 122 | \VerbatimFootnotes % allows verbatim text in footnotes 123 | $endif$ 124 | $if(lang)$ 125 | \ifxetex 126 | \usepackage{polyglossia} 127 | \setmainlanguage{$mainlang$} 128 | \else 129 | \usepackage[$lang$]{babel} 130 | \fi 131 | $endif$ 132 | 133 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 134 | %Changes borrowed from @cboettig, added by @jhollist 135 | % A modified page layout 136 | \textwidth 6.75in 137 | \oddsidemargin -0.15in 138 | \evensidemargin -0.15in 139 | \textheight 9in 140 | \topmargin -0.5in 141 | \usepackage{lineno} % add 142 | $if(linenumbers)$ 143 | \linenumbers % turns line numbering on 144 | $endif$ 145 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 146 | 147 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 148 | %%Packages and layout changes by @jhollist 09/15/2014 149 | \usepackage{ragged2e} 150 | \usepackage[font=$capsize$]{caption} 151 | $if(spacing)$ 152 | \usepackage[$spacing$]{setspace} 153 | $endif$ 154 | \usepackage{parskip} 155 | \usepackage{fancyhdr} 156 | \pagestyle{fancy} 157 | \fancyhf{} 158 | \renewcommand{\headrulewidth}{0pt} 159 | \rfoot{\today} 160 | \lfoot{\thepage} 161 | %%Changed default abstract width 162 | %\renewenvironment{abstract}{% 163 | 164 | \renewenvironment{abstract}{ 165 | \hfill\begin{minipage}{1\textwidth} 166 | \rule{\textwidth}{1pt}\vspace{5pt} 167 | \normalsize 168 | \begin{justify} 169 | \bfseries\abstractname\vspace{5pt} 170 | \end{justify}} 171 | {\par\noindent\rule{\textwidth}{1pt}\end{minipage} 172 | } 173 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 174 | 175 | $if(title)$ 176 | \title{$title$} 177 | $endif$ 178 | $if(subtitle)$ 179 | \subtitle{$subtitle$} 180 | $endif$ 181 | \author{ 182 | $for(author)$ 183 | $if(author.name)$ 184 | $author.name$ 185 | $else$ 186 | $author$ 187 | $endif$ 188 | $endfor$ 189 | } 190 | \date{$date$} 191 | $for(header-includes)$ 192 | $header-includes$ 193 | $endfor$ 194 | 195 | \begin{document} 196 | %%Edited by @jhollist 09/15/2014 197 | %%Adds title from YAML 198 | \begin{singlespace} 199 | $if(title)$ 200 | \begin{center} 201 | \huge $title$ 202 | \end{center} 203 | $endif$ 204 | %%Adds Author, correspond email asterisk, and affilnum from YAML 205 | $if(author)$ 206 | \begin{center} 207 | \large 208 | $for(author)$ 209 | $if(author.name)$ 210 | $author.name$$if(author.affilnum)$$if(author.email)$ \textsuperscript{*}$endif$ \textsuperscript{$author.affilnum$} $endif$ 211 | $else$ 212 | $author$ 213 | $endif$ 214 | $endfor$ 215 | \end{center} 216 | $endif$ 217 | %%Adds affiliations from YAML 218 | \begin{justify} 219 | $if(affiliation)$ 220 | \footnotesize \emph{ 221 | $for(affiliation)$ 222 | \\* 223 | \textsuperscript{$affiliation.affilnum$}$affiliation.affil$\\* 224 | $endfor$ 225 | } 226 | $endif$ 227 | %%Adds corresponding author email(s) from YAML 228 | $if(author)$ 229 | \\[0.1cm] 230 | \footnotesize \emph{ 231 | \textsuperscript{*} corresponding author: 232 | $for(author)$ 233 | $if(author.email)$ 234 | $author.email$ 235 | $endif$ 236 | $endfor$ 237 | } 238 | $endif$ 239 | \end{justify} 240 | %%Adds date from YAML 241 | $if(date)$ 242 | \begin{center} 243 | \small \emph{$date$} \\ 244 | \end{center} 245 | $endif$ 246 | \normalsize 247 | 248 | $if(abstract)$ 249 | \begin{abstract} 250 | $abstract$ 251 | \end{abstract} 252 | $endif$ 253 | \end{singlespace} 254 | 255 | $for(include-before)$ 256 | $include-before$ 257 | 258 | $endfor$ 259 | $if(toc)$ 260 | { 261 | \hypersetup{linkcolor=black} 262 | \setcounter{tocdepth}{$toc-depth$} 263 | \tableofcontents 264 | } 265 | $endif$ 266 | 267 | $body$ 268 | 269 | $if(natbib)$ 270 | $if(biblio-files)$ 271 | $if(biblio-title)$ 272 | $if(book-class)$ 273 | \renewcommand\bibname{$biblio-title$} 274 | $else$ 275 | \renewcommand\refname{$biblio-title$} 276 | $endif$ 277 | $endif$ 278 | \bibliography{$biblio-files$} 279 | 280 | $endif$ 281 | $endif$ 282 | $if(biblatex)$ 283 | \printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$ 284 | 285 | $endif$ 286 | $for(include-after)$ 287 | $include-after$ 288 | 289 | $endfor$ 290 | \end{document} -------------------------------------------------------------------------------- /vignettes/fws_submission/components/manuscript.latex: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | %% Original default rstudio/pandoc latex file 3 | %% upated by @jhollist 09/15/2014 4 | %% inspired by @cboetting https://github.com/cboettig/template and 5 | %% @rmflight blog posts: 6 | %% http://rmflight.github.io/posts/2014/07/analyses_as_packages.html 7 | %% http://rmflight.github.io/posts/2014/07/vignetteAnalysis.html). 8 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 9 | 10 | \documentclass[$if(fontsize)$$fontsize$,$endif$$if(lang)$$lang$,$endif$$if(papersize)$$papersize$,$endif$$for(classoption)$$classoption$$sep$,$endfor$]{$documentclass$} 11 | \usepackage[T1]{fontenc} 12 | \usepackage{lmodern} 13 | \usepackage{amssymb,amsmath} 14 | \usepackage{ifxetex,ifluatex} 15 | \usepackage{fancyhdr} 16 | \usepackage{fixltx2e} % provides \textsubscript 17 | % use upquote if available, for straight quotes in verbatim environments 18 | \IfFileExists{upquote.sty}{\usepackage{upquote}}{} 19 | \ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex 20 | \usepackage[utf8]{inputenc} 21 | $if(euro)$ 22 | \usepackage{eurosym} 23 | $endif$ 24 | \else % if luatex or xelatex 25 | \ifxetex 26 | \usepackage{mathspec} 27 | \usepackage{xltxtra,xunicode} 28 | \else 29 | \usepackage{fontspec} 30 | \fi 31 | \defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase} 32 | \newcommand{\euro}{€} 33 | $if(mainfont)$ 34 | \setmainfont{$mainfont$} 35 | $endif$ 36 | $if(sansfont)$ 37 | \setsansfont{$sansfont$} 38 | $endif$ 39 | $if(monofont)$ 40 | \setmonofont[Mapping=tex-ansi]{$monofont$} 41 | $endif$ 42 | $if(mathfont)$ 43 | \setmathfont(Digits,Latin,Greek){$mathfont$} 44 | $endif$ 45 | \fi 46 | % use microtype if available 47 | \IfFileExists{microtype.sty}{\usepackage{microtype}}{} 48 | $if(geometry)$ 49 | \usepackage[$for(geometry)$$geometry$$sep$,$endfor$]{geometry} 50 | $endif$ 51 | $if(natbib)$ 52 | \usepackage{natbib} 53 | \bibliographystyle{$if(biblio-style)$$biblio-style$$else$plainnat$endif$} 54 | $endif$ 55 | $if(biblatex)$ 56 | \usepackage{biblatex} 57 | $if(biblio-files)$ 58 | \bibliography{$biblio-files$} 59 | $endif$ 60 | $endif$ 61 | $if(listings)$ 62 | \usepackage{listings} 63 | $endif$ 64 | $if(lhs)$ 65 | \lstnewenvironment{code}{\lstset{language=Haskell,basicstyle=\small\ttfamily}}{} 66 | $endif$ 67 | $if(highlighting-macros)$ 68 | $highlighting-macros$ 69 | $endif$ 70 | $if(verbatim-in-note)$ 71 | \usepackage{fancyvrb} 72 | $endif$ 73 | $if(tables)$ 74 | \usepackage{longtable,booktabs} 75 | $endif$ 76 | $if(graphics)$ 77 | \usepackage{graphicx} 78 | % Redefine \includegraphics so that, unless explicit options are 79 | % given, the image width will not exceed the width of the page. 80 | % Images get their normal width if they fit onto the page, but 81 | % are scaled down if they would overflow the margins. 82 | \makeatletter 83 | \def\ScaleIfNeeded{% 84 | \ifdim\Gin@nat@width>\linewidth 85 | \linewidth 86 | \else 87 | \Gin@nat@width 88 | \fi 89 | } 90 | \makeatother 91 | \let\Oldincludegraphics\includegraphics 92 | {% 93 | \catcode`\@=11\relax% 94 | \gdef\includegraphics{\@ifnextchar[{\Oldincludegraphics}{\Oldincludegraphics[width=\ScaleIfNeeded]}}% 95 | }% 96 | $endif$ 97 | \ifxetex 98 | \usepackage[setpagesize=false, % page size defined by xetex 99 | unicode=false, % unicode breaks when used with xetex 100 | xetex]{hyperref} 101 | \else 102 | \usepackage[unicode=true]{hyperref} 103 | \fi 104 | \hypersetup{breaklinks=true, 105 | bookmarks=true, 106 | pdfauthor={$author-meta$}, 107 | pdftitle={$title-meta$}, 108 | colorlinks=true, 109 | citecolor=$if(citecolor)$$citecolor$$else$blue$endif$, 110 | urlcolor=$if(urlcolor)$$urlcolor$$else$blue$endif$, 111 | linkcolor=$if(linkcolor)$$linkcolor$$else$magenta$endif$, 112 | pdfborder={0 0 0}} 113 | \urlstyle{same} % don't use monospace font for urls 114 | $if(links-as-notes)$ 115 | % Make links footnotes instead of hotlinks: 116 | \renewcommand{\href}[2]{#2\footnote{\url{#1}}} 117 | $endif$ 118 | $if(strikeout)$ 119 | \usepackage[normalem]{ulem} 120 | % avoid problems with \sout in headers with hyperref: 121 | \pdfstringdefDisableCommands{\renewcommand{\sout}{}} 122 | $endif$ 123 | \setlength{\parindent}{0pt} 124 | \setlength{\parskip}{6pt plus 2pt minus 1pt} 125 | \setlength{\emergencystretch}{3em} % prevent overfull lines 126 | $if(numbersections)$ 127 | \setcounter{secnumdepth}{5} 128 | $else$ 129 | \setcounter{secnumdepth}{0} 130 | $endif$ 131 | $if(verbatim-in-note)$ 132 | \VerbatimFootnotes % allows verbatim text in footnotes 133 | $endif$ 134 | $if(lang)$ 135 | \ifxetex 136 | \usepackage{polyglossia} 137 | \setmainlanguage{$mainlang$} 138 | \else 139 | \usepackage[$lang$]{babel} 140 | \fi 141 | $endif$ 142 | 143 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 144 | %Changes borrowed from @cboettig, added by @jhollist 145 | % A modified page layout 146 | \textwidth 6.75in 147 | \oddsidemargin -0.15in 148 | \evensidemargin -0.15in 149 | \textheight 9in 150 | \topmargin -0.5in 151 | \usepackage{lineno} % add 152 | $if(linenumbers)$ 153 | \linenumbers % turns line numbering on 154 | $endif$ 155 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 156 | 157 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 158 | %%Packages and layout changes by @jhollist 09/15/2014 159 | \usepackage{ragged2e} 160 | \usepackage[font=$capsize$]{caption} 161 | $if(spacing)$ 162 | \usepackage[$spacing$]{setspace} 163 | $endif$ 164 | \usepackage{parskip} 165 | \usepackage{fancyhdr} 166 | \pagestyle{fancy} 167 | \fancyhf{} 168 | \renewcommand{\headrulewidth}{0pt} 169 | \rfoot{\today} 170 | \lfoot{\thepage} 171 | %%Changed default abstract width and added lines 172 | \renewenvironment{abstract}{ 173 | \hfill\begin{minipage}{1\textwidth} 174 | \rule{\textwidth}{1pt}\vspace{5pt} 175 | \normalsize 176 | \begin{justify} 177 | \bfseries\abstractname\vspace{5pt} 178 | \end{justify}} 179 | {\par\noindent\rule{\textwidth}{1pt}\end{minipage} 180 | } 181 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 182 | 183 | $if(title)$ 184 | \title{$title$} 185 | $endif$ 186 | $if(subtitle)$ 187 | \subtitle{$subtitle$} 188 | $endif$ 189 | \author{ 190 | $for(author)$ 191 | $if(author.name)$ 192 | $author.name$ 193 | $else$ 194 | $author$ 195 | $endif$ 196 | $endfor$ 197 | } 198 | \date{$date$} 199 | $for(header-includes)$ 200 | $header-includes$ 201 | $endfor$ 202 | 203 | \begin{document} 204 | %%Edited by @jhollist 09/15/2014 205 | %%Adds title from YAML 206 | \begin{singlespace} 207 | $if(title)$ 208 | \begin{center} 209 | \huge $title$ 210 | \end{center} 211 | $endif$ 212 | $if(running)$ 213 | \rhead{Running head: $running$} 214 | $endif$ 215 | %%Adds Author, correspond email asterisk, and affilnum from YAML 216 | \begin{center} 217 | \large 218 | $for(author)$ 219 | $if(author.name)$ 220 | $author.name$$if(author.affilnum)$$if(author.email)$ \textsuperscript{*}$endif$ \textsuperscript{$author.affilnum$} $endif$ 221 | $else$ 222 | $author$ 223 | $endif$ 224 | $endfor$ 225 | \end{center} 226 | %%Adds affiliations from YAML 227 | \begin{justify} 228 | \footnotesize \emph{ 229 | $for(affiliation)$ 230 | \\* 231 | \textsuperscript{$affiliation.affilnum$}$affiliation.affil$\\* 232 | $endfor$ 233 | } 234 | %%Adds corresponding author email(s) from YAML 235 | \newcounter{num} 236 | \setcounter{num}{1} 237 | \\[0.1cm] 238 | \footnotesize \emph{ 239 | $for(author)$ 240 | $if(author.email)$ 241 | \ifnum\value{num}=1% 242 | \textsuperscript{*} corresponding author: 243 | \fi 244 | $author.email$ 245 | \stepcounter{num} 246 | $endif$ 247 | $endfor$ 248 | } 249 | \end{justify} 250 | %%Adds date from YAML 251 | $if(date)$ 252 | \begin{center} 253 | \small \emph{$date$} \\ 254 | \end{center} 255 | $endif$ 256 | \normalsize 257 | 258 | $if(abstract)$ 259 | \begin{abstract} 260 | $abstract$ 261 | \end{abstract} 262 | $endif$ 263 | \end{singlespace} 264 | 265 | $for(include-before)$ 266 | $include-before$ 267 | 268 | $endfor$ 269 | $if(toc)$ 270 | { 271 | \hypersetup{linkcolor=black} 272 | \setcounter{tocdepth}{$toc-depth$} 273 | \tableofcontents 274 | } 275 | $endif$ 276 | 277 | $body$ 278 | 279 | $if(natbib)$ 280 | $if(biblio-files)$ 281 | $if(biblio-title)$ 282 | $if(book-class)$ 283 | \renewcommand\bibname{$biblio-title$} 284 | $else$ 285 | \renewcommand\refname{$biblio-title$} 286 | $endif$ 287 | $endif$ 288 | \bibliography{$biblio-files$} 289 | 290 | $endif$ 291 | $endif$ 292 | $if(biblatex)$ 293 | \printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$ 294 | 295 | $endif$ 296 | $for(include-after)$ 297 | $include-after$ 298 | 299 | $endfor$ 300 | \end{document} --------------------------------------------------------------------------------