From f4d72862f3b89616529e6c4671d6a23028c33400 Mon Sep 17 00:00:00 2001 From: Timm Nawrocki Date: Wed, 2 Oct 2024 17:37:09 -0800 Subject: [PATCH] Create script order Added script order to folder and script names to show order of execution. Updated Readme for final archival and publication. --- .../01_Cloud_ScikitLearnInstance.md | 0 .../PrepareStudyArea.py | 0 .../01_Covariate_Elevation.py | 0 .../02_Covariate_Roughness.py | 0 .../01_Covariate_Waterbody.py | 0 .../02_Mask_WaterIce.py | 0 .../01_Covariate_Vegetation.py | 0 .../02_Covariate_Barren.py | 0 .../03_Covariate_ForestEdge.py | 0 .../04_Covariate_TundraEdge.py | 0 .../01-createDeployMetadata_GPS.R | 0 .../01-formatParturienceVariable.R | 0 .../01-importDataSeparateCSV_GPS.R | 0 .../02-formatData_GPS.R | 0 .../03b-cleanLocations_GPS.R | 0 .../04-formatForCalvingSeason.R | 0 .../explore-animatePaths.R | 0 .../explore-interpolateData_GPS.R | 0 .../01-generateDistributions.R | 0 .../02-generateConvexHulls.py | 0 .../03-createRandomStartPoints.py | 0 .../04-createRandomPaths.R | 0 .../05-convertToShapefile.py | 0 .../06-extractCovariates.R | 0 .../07-summarizeByPath.R | 0 .../08-extractSelection.R | 0 .../09-removeConfidentialInfo.R | 0 .../explore-amtPackage.R | 0 .../01-formatData_VHF.R | 0 .../01-formatData_VHF_Togiak.R | 0 .../01_Extract_Grids.R | 0 .../01_Prepare_Data.R | 0 .../02_Selection_TrainTest.py | 0 .../03_Selection_Predict.py | 0 .../04a_Summary_Statistics.R | 0 .../04b_Summary_Obs_vs_Random.R | 0 .../05_Plot_Correlation.R | 0 .../06_Plot_CovariateImportances.R | 0 .../07_Plot_HeightDiversity.R | 0 .../01_Selection_Predict_Points.py | 0 .../02_Index_CalculateDifference.R | 0 .../03_Index_SummarizeDifference.R | 0 .../04_Plot_DifferenceIndex.R | 0 .../01_Convert_Rasters.R | 0 .../02_Merge_Rasters.R | 0 .../03_Apply_Mask.py | 0 .../04_Distance_To_Selected.py | 0 .../05_Prepare_Validation.py | 0 .../06_Selection_ProximalAccuracy.R | 4 +- README.md | 33 ++-- .../archive/DataExtract_Grids_Tundra.R | 101 ------------- .../archive/DataExtract_MergeGrids.R | 70 --------- ...tatPrediction_CompareConfidenceIntervals.R | 54 ------- .../02a-exploratory-CollinearityVIF.py | 45 ------ .../02b-exploratoryModel_maternal.R | 93 ------------ .../02b-exploratoryModel_nonmaternal.R | 142 ------------------ .../03-finalModel_maternal.R | 92 ------------ .../03-finalModel_nonmaternal.R | 92 ------------ 58 files changed, 22 insertions(+), 704 deletions(-) rename cloudCompute/newInstance_machineLearning.md => 00_cloud_management/01_Cloud_ScikitLearnInstance.md (100%) rename {data_StudyAreaBoundary => 01_data_studyarea}/PrepareStudyArea.py (100%) rename data_Topography/PrepareCovariate_Elevation.py => 02_data_topography/01_Covariate_Elevation.py (100%) rename data_Topography/PrepareCovariate_Roughness.py => 02_data_topography/02_Covariate_Roughness.py (100%) rename data_Hydrography/PrepareCovariate_LakePond.py => 03_data_hydrography/01_Covariate_Waterbody.py (100%) rename data_Hydrography/PrepareMask_WaterIce.py => 03_data_hydrography/02_Mask_WaterIce.py (100%) rename data_Vegetation/PrepareCovariate_Vegetation.py => 04_data_vegetation/01_Covariate_Vegetation.py (100%) rename data_Vegetation/PrepareCovariate_Barren.py => 04_data_vegetation/02_Covariate_Barren.py (100%) rename data_Vegetation/PrepareCovariate_ForestEdge.py => 04_data_vegetation/03_Covariate_ForestEdge.py (100%) rename data_Vegetation/PrepareCovariate_TundraEdge.py => 04_data_vegetation/04_Covariate_TundraEdge.py (100%) rename {data_Telemetry => 05_data_telemetry}/01-createDeployMetadata_GPS.R (100%) rename {data_Telemetry => 05_data_telemetry}/01-formatParturienceVariable.R (100%) rename {data_Telemetry => 05_data_telemetry}/01-importDataSeparateCSV_GPS.R (100%) rename {data_Telemetry => 05_data_telemetry}/02-formatData_GPS.R (100%) rename {data_Telemetry => 05_data_telemetry}/03b-cleanLocations_GPS.R (100%) rename {data_Telemetry => 05_data_telemetry}/04-formatForCalvingSeason.R (100%) rename {data_Telemetry => 05_data_telemetry}/explore-animatePaths.R (100%) rename {data_Telemetry => 05_data_telemetry}/explore-interpolateData_GPS.R (100%) rename {data_Paths => 06_data_paths}/01-generateDistributions.R (100%) rename {data_Paths => 06_data_paths}/02-generateConvexHulls.py (100%) rename {data_Paths => 06_data_paths}/03-createRandomStartPoints.py (100%) rename {data_Paths => 06_data_paths}/04-createRandomPaths.R (100%) rename {data_Paths => 06_data_paths}/05-convertToShapefile.py (100%) rename {data_Paths => 06_data_paths}/06-extractCovariates.R (100%) rename {data_Paths => 06_data_paths}/07-summarizeByPath.R (100%) rename {data_Paths => 06_data_paths}/08-extractSelection.R (100%) rename {data_Paths => 06_data_paths}/09-removeConfidentialInfo.R (100%) rename {data_Paths => 06_data_paths}/explore-amtPackage.R (100%) rename {data_Validation => 07_data_validation}/01-formatData_VHF.R (100%) rename {data_Validation => 07_data_validation}/01-formatData_VHF_Togiak.R (100%) rename geospatial_AnalyticGrids/DataExtract_Grids.R => 08_data_grids/01_Extract_Grids.R (100%) rename statistics_PathSelection/01-dataPrep.R => 09_statistics_selection/01_Prepare_Data.R (100%) rename statistics_PathSelection/HabitatTrainTest.py => 09_statistics_selection/02_Selection_TrainTest.py (100%) rename statistics_PathSelection/HabitatPredict_Grids.py => 09_statistics_selection/03_Selection_Predict.py (100%) rename statistics_PathSelection/summaryStatistics_Calf_VS_NoCalf.R => 09_statistics_selection/04a_Summary_Statistics.R (100%) rename statistics_PathSelection/summaryStatistics_Obs_VS_Random.R => 09_statistics_selection/04b_Summary_Obs_vs_Random.R (100%) rename statistics_PathSelection/summaryStatistics_PlotCorrelation.R => 09_statistics_selection/05_Plot_Correlation.R (100%) rename statistics_PathSelection/summaryStatistics_PlotCovariateImportances.R => 09_statistics_selection/06_Plot_CovariateImportances.R (100%) rename statistics_PathSelection/summaryStatistics_VegetationHeights.R => 09_statistics_selection/07_Plot_HeightDiversity.R (100%) rename statistics_MaternalTradeoffIndex/HabitatPredict_ObservedPoints.py => 10_statistics_difference/01_Selection_Predict_Points.py (100%) rename statistics_MaternalTradeoffIndex/MaternalTradeoff_CalculateTradeoff.R => 10_statistics_difference/02_Index_CalculateDifference.R (100%) rename statistics_MaternalTradeoffIndex/MaternalTradeoff_SummarizeTradeoff.R => 10_statistics_difference/03_Index_SummarizeDifference.R (100%) rename statistics_MaternalTradeoffIndex/MaternalTradeoff_PlotDistribution.R => 10_statistics_difference/04_Plot_DifferenceIndex.R (100%) rename postprocess_Habitat/HabitatPrediction_ConvertToRaster.R => 11_postprocess_rasters/01_Convert_Rasters.R (100%) rename postprocess_Habitat/HabitatPrediction_MergeRasters.R => 11_postprocess_rasters/02_Merge_Rasters.R (100%) rename postprocess_Habitat/HabitatPrediction_ApplyMask.py => 11_postprocess_rasters/03_Apply_Mask.py (100%) rename postprocess_Habitat/HabitatPrediction_CalculateEuclideanDistance.py => 11_postprocess_rasters/04_Distance_To_Selected.py (100%) rename postprocess_Habitat/HabitatPrediction_PrepareVHFValidation.py => 11_postprocess_rasters/05_Prepare_Validation.py (100%) rename statistics_PathSelection/summaryStatistics_IndependentValidation.R => 11_postprocess_rasters/06_Selection_ProximalAccuracy.R (91%) delete mode 100644 geospatial_AnalyticGrids/archive/DataExtract_Grids_Tundra.R delete mode 100644 geospatial_AnalyticGrids/archive/DataExtract_MergeGrids.R delete mode 100644 postprocess_Habitat/HabitatPrediction_CompareConfidenceIntervals.R delete mode 100644 statistics_PathSelection/02a-exploratory-CollinearityVIF.py delete mode 100644 statistics_PathSelection/02b-exploratoryModel_maternal.R delete mode 100644 statistics_PathSelection/02b-exploratoryModel_nonmaternal.R delete mode 100644 statistics_PathSelection/03-finalModel_maternal.R delete mode 100644 statistics_PathSelection/03-finalModel_nonmaternal.R diff --git a/cloudCompute/newInstance_machineLearning.md b/00_cloud_management/01_Cloud_ScikitLearnInstance.md similarity index 100% rename from cloudCompute/newInstance_machineLearning.md rename to 00_cloud_management/01_Cloud_ScikitLearnInstance.md diff --git a/data_StudyAreaBoundary/PrepareStudyArea.py b/01_data_studyarea/PrepareStudyArea.py similarity index 100% rename from data_StudyAreaBoundary/PrepareStudyArea.py rename to 01_data_studyarea/PrepareStudyArea.py diff --git a/data_Topography/PrepareCovariate_Elevation.py b/02_data_topography/01_Covariate_Elevation.py similarity index 100% rename from data_Topography/PrepareCovariate_Elevation.py rename to 02_data_topography/01_Covariate_Elevation.py diff --git a/data_Topography/PrepareCovariate_Roughness.py b/02_data_topography/02_Covariate_Roughness.py similarity index 100% rename from data_Topography/PrepareCovariate_Roughness.py rename to 02_data_topography/02_Covariate_Roughness.py diff --git a/data_Hydrography/PrepareCovariate_LakePond.py b/03_data_hydrography/01_Covariate_Waterbody.py similarity index 100% rename from data_Hydrography/PrepareCovariate_LakePond.py rename to 03_data_hydrography/01_Covariate_Waterbody.py diff --git a/data_Hydrography/PrepareMask_WaterIce.py b/03_data_hydrography/02_Mask_WaterIce.py similarity index 100% rename from data_Hydrography/PrepareMask_WaterIce.py rename to 03_data_hydrography/02_Mask_WaterIce.py diff --git a/data_Vegetation/PrepareCovariate_Vegetation.py b/04_data_vegetation/01_Covariate_Vegetation.py similarity index 100% rename from data_Vegetation/PrepareCovariate_Vegetation.py rename to 04_data_vegetation/01_Covariate_Vegetation.py diff --git a/data_Vegetation/PrepareCovariate_Barren.py b/04_data_vegetation/02_Covariate_Barren.py similarity index 100% rename from data_Vegetation/PrepareCovariate_Barren.py rename to 04_data_vegetation/02_Covariate_Barren.py diff --git a/data_Vegetation/PrepareCovariate_ForestEdge.py b/04_data_vegetation/03_Covariate_ForestEdge.py similarity index 100% rename from data_Vegetation/PrepareCovariate_ForestEdge.py rename to 04_data_vegetation/03_Covariate_ForestEdge.py diff --git a/data_Vegetation/PrepareCovariate_TundraEdge.py b/04_data_vegetation/04_Covariate_TundraEdge.py similarity index 100% rename from data_Vegetation/PrepareCovariate_TundraEdge.py rename to 04_data_vegetation/04_Covariate_TundraEdge.py diff --git a/data_Telemetry/01-createDeployMetadata_GPS.R b/05_data_telemetry/01-createDeployMetadata_GPS.R similarity index 100% rename from data_Telemetry/01-createDeployMetadata_GPS.R rename to 05_data_telemetry/01-createDeployMetadata_GPS.R diff --git a/data_Telemetry/01-formatParturienceVariable.R b/05_data_telemetry/01-formatParturienceVariable.R similarity index 100% rename from data_Telemetry/01-formatParturienceVariable.R rename to 05_data_telemetry/01-formatParturienceVariable.R diff --git a/data_Telemetry/01-importDataSeparateCSV_GPS.R b/05_data_telemetry/01-importDataSeparateCSV_GPS.R similarity index 100% rename from data_Telemetry/01-importDataSeparateCSV_GPS.R rename to 05_data_telemetry/01-importDataSeparateCSV_GPS.R diff --git a/data_Telemetry/02-formatData_GPS.R b/05_data_telemetry/02-formatData_GPS.R similarity index 100% rename from data_Telemetry/02-formatData_GPS.R rename to 05_data_telemetry/02-formatData_GPS.R diff --git a/data_Telemetry/03b-cleanLocations_GPS.R b/05_data_telemetry/03b-cleanLocations_GPS.R similarity index 100% rename from data_Telemetry/03b-cleanLocations_GPS.R rename to 05_data_telemetry/03b-cleanLocations_GPS.R diff --git a/data_Telemetry/04-formatForCalvingSeason.R b/05_data_telemetry/04-formatForCalvingSeason.R similarity index 100% rename from data_Telemetry/04-formatForCalvingSeason.R rename to 05_data_telemetry/04-formatForCalvingSeason.R diff --git a/data_Telemetry/explore-animatePaths.R b/05_data_telemetry/explore-animatePaths.R similarity index 100% rename from data_Telemetry/explore-animatePaths.R rename to 05_data_telemetry/explore-animatePaths.R diff --git a/data_Telemetry/explore-interpolateData_GPS.R b/05_data_telemetry/explore-interpolateData_GPS.R similarity index 100% rename from data_Telemetry/explore-interpolateData_GPS.R rename to 05_data_telemetry/explore-interpolateData_GPS.R diff --git a/data_Paths/01-generateDistributions.R b/06_data_paths/01-generateDistributions.R similarity index 100% rename from data_Paths/01-generateDistributions.R rename to 06_data_paths/01-generateDistributions.R diff --git a/data_Paths/02-generateConvexHulls.py b/06_data_paths/02-generateConvexHulls.py similarity index 100% rename from data_Paths/02-generateConvexHulls.py rename to 06_data_paths/02-generateConvexHulls.py diff --git a/data_Paths/03-createRandomStartPoints.py b/06_data_paths/03-createRandomStartPoints.py similarity index 100% rename from data_Paths/03-createRandomStartPoints.py rename to 06_data_paths/03-createRandomStartPoints.py diff --git a/data_Paths/04-createRandomPaths.R b/06_data_paths/04-createRandomPaths.R similarity index 100% rename from data_Paths/04-createRandomPaths.R rename to 06_data_paths/04-createRandomPaths.R diff --git a/data_Paths/05-convertToShapefile.py b/06_data_paths/05-convertToShapefile.py similarity index 100% rename from data_Paths/05-convertToShapefile.py rename to 06_data_paths/05-convertToShapefile.py diff --git a/data_Paths/06-extractCovariates.R b/06_data_paths/06-extractCovariates.R similarity index 100% rename from data_Paths/06-extractCovariates.R rename to 06_data_paths/06-extractCovariates.R diff --git a/data_Paths/07-summarizeByPath.R b/06_data_paths/07-summarizeByPath.R similarity index 100% rename from data_Paths/07-summarizeByPath.R rename to 06_data_paths/07-summarizeByPath.R diff --git a/data_Paths/08-extractSelection.R b/06_data_paths/08-extractSelection.R similarity index 100% rename from data_Paths/08-extractSelection.R rename to 06_data_paths/08-extractSelection.R diff --git a/data_Paths/09-removeConfidentialInfo.R b/06_data_paths/09-removeConfidentialInfo.R similarity index 100% rename from data_Paths/09-removeConfidentialInfo.R rename to 06_data_paths/09-removeConfidentialInfo.R diff --git a/data_Paths/explore-amtPackage.R b/06_data_paths/explore-amtPackage.R similarity index 100% rename from data_Paths/explore-amtPackage.R rename to 06_data_paths/explore-amtPackage.R diff --git a/data_Validation/01-formatData_VHF.R b/07_data_validation/01-formatData_VHF.R similarity index 100% rename from data_Validation/01-formatData_VHF.R rename to 07_data_validation/01-formatData_VHF.R diff --git a/data_Validation/01-formatData_VHF_Togiak.R b/07_data_validation/01-formatData_VHF_Togiak.R similarity index 100% rename from data_Validation/01-formatData_VHF_Togiak.R rename to 07_data_validation/01-formatData_VHF_Togiak.R diff --git a/geospatial_AnalyticGrids/DataExtract_Grids.R b/08_data_grids/01_Extract_Grids.R similarity index 100% rename from geospatial_AnalyticGrids/DataExtract_Grids.R rename to 08_data_grids/01_Extract_Grids.R diff --git a/statistics_PathSelection/01-dataPrep.R b/09_statistics_selection/01_Prepare_Data.R similarity index 100% rename from statistics_PathSelection/01-dataPrep.R rename to 09_statistics_selection/01_Prepare_Data.R diff --git a/statistics_PathSelection/HabitatTrainTest.py b/09_statistics_selection/02_Selection_TrainTest.py similarity index 100% rename from statistics_PathSelection/HabitatTrainTest.py rename to 09_statistics_selection/02_Selection_TrainTest.py diff --git a/statistics_PathSelection/HabitatPredict_Grids.py b/09_statistics_selection/03_Selection_Predict.py similarity index 100% rename from statistics_PathSelection/HabitatPredict_Grids.py rename to 09_statistics_selection/03_Selection_Predict.py diff --git a/statistics_PathSelection/summaryStatistics_Calf_VS_NoCalf.R b/09_statistics_selection/04a_Summary_Statistics.R similarity index 100% rename from statistics_PathSelection/summaryStatistics_Calf_VS_NoCalf.R rename to 09_statistics_selection/04a_Summary_Statistics.R diff --git a/statistics_PathSelection/summaryStatistics_Obs_VS_Random.R b/09_statistics_selection/04b_Summary_Obs_vs_Random.R similarity index 100% rename from statistics_PathSelection/summaryStatistics_Obs_VS_Random.R rename to 09_statistics_selection/04b_Summary_Obs_vs_Random.R diff --git a/statistics_PathSelection/summaryStatistics_PlotCorrelation.R b/09_statistics_selection/05_Plot_Correlation.R similarity index 100% rename from statistics_PathSelection/summaryStatistics_PlotCorrelation.R rename to 09_statistics_selection/05_Plot_Correlation.R diff --git a/statistics_PathSelection/summaryStatistics_PlotCovariateImportances.R b/09_statistics_selection/06_Plot_CovariateImportances.R similarity index 100% rename from statistics_PathSelection/summaryStatistics_PlotCovariateImportances.R rename to 09_statistics_selection/06_Plot_CovariateImportances.R diff --git a/statistics_PathSelection/summaryStatistics_VegetationHeights.R b/09_statistics_selection/07_Plot_HeightDiversity.R similarity index 100% rename from statistics_PathSelection/summaryStatistics_VegetationHeights.R rename to 09_statistics_selection/07_Plot_HeightDiversity.R diff --git a/statistics_MaternalTradeoffIndex/HabitatPredict_ObservedPoints.py b/10_statistics_difference/01_Selection_Predict_Points.py similarity index 100% rename from statistics_MaternalTradeoffIndex/HabitatPredict_ObservedPoints.py rename to 10_statistics_difference/01_Selection_Predict_Points.py diff --git a/statistics_MaternalTradeoffIndex/MaternalTradeoff_CalculateTradeoff.R b/10_statistics_difference/02_Index_CalculateDifference.R similarity index 100% rename from statistics_MaternalTradeoffIndex/MaternalTradeoff_CalculateTradeoff.R rename to 10_statistics_difference/02_Index_CalculateDifference.R diff --git a/statistics_MaternalTradeoffIndex/MaternalTradeoff_SummarizeTradeoff.R b/10_statistics_difference/03_Index_SummarizeDifference.R similarity index 100% rename from statistics_MaternalTradeoffIndex/MaternalTradeoff_SummarizeTradeoff.R rename to 10_statistics_difference/03_Index_SummarizeDifference.R diff --git a/statistics_MaternalTradeoffIndex/MaternalTradeoff_PlotDistribution.R b/10_statistics_difference/04_Plot_DifferenceIndex.R similarity index 100% rename from statistics_MaternalTradeoffIndex/MaternalTradeoff_PlotDistribution.R rename to 10_statistics_difference/04_Plot_DifferenceIndex.R diff --git a/postprocess_Habitat/HabitatPrediction_ConvertToRaster.R b/11_postprocess_rasters/01_Convert_Rasters.R similarity index 100% rename from postprocess_Habitat/HabitatPrediction_ConvertToRaster.R rename to 11_postprocess_rasters/01_Convert_Rasters.R diff --git a/postprocess_Habitat/HabitatPrediction_MergeRasters.R b/11_postprocess_rasters/02_Merge_Rasters.R similarity index 100% rename from postprocess_Habitat/HabitatPrediction_MergeRasters.R rename to 11_postprocess_rasters/02_Merge_Rasters.R diff --git a/postprocess_Habitat/HabitatPrediction_ApplyMask.py b/11_postprocess_rasters/03_Apply_Mask.py similarity index 100% rename from postprocess_Habitat/HabitatPrediction_ApplyMask.py rename to 11_postprocess_rasters/03_Apply_Mask.py diff --git a/postprocess_Habitat/HabitatPrediction_CalculateEuclideanDistance.py b/11_postprocess_rasters/04_Distance_To_Selected.py similarity index 100% rename from postprocess_Habitat/HabitatPrediction_CalculateEuclideanDistance.py rename to 11_postprocess_rasters/04_Distance_To_Selected.py diff --git a/postprocess_Habitat/HabitatPrediction_PrepareVHFValidation.py b/11_postprocess_rasters/05_Prepare_Validation.py similarity index 100% rename from postprocess_Habitat/HabitatPrediction_PrepareVHFValidation.py rename to 11_postprocess_rasters/05_Prepare_Validation.py diff --git a/statistics_PathSelection/summaryStatistics_IndependentValidation.R b/11_postprocess_rasters/06_Selection_ProximalAccuracy.R similarity index 91% rename from statistics_PathSelection/summaryStatistics_IndependentValidation.R rename to 11_postprocess_rasters/06_Selection_ProximalAccuracy.R index 86873bc..833a5a9 100644 --- a/statistics_PathSelection/summaryStatistics_IndependentValidation.R +++ b/11_postprocess_rasters/06_Selection_ProximalAccuracy.R @@ -1,9 +1,9 @@ # --------------------------------------------------------------------------- -# Calculate Independent Validation +# Calculate proximal accuracy # Author: Timm Nawrocki, Alaska Center for Conservation Science # Last Updated: 2021-10-06 # Usage: Script should be executed in R 4.1.0+. -# Description: "Calculate Independent Validation" calculates the proximity accuracy of independent VHF validation data relative to landscape mean distance to habitat. +# Description: "Calculate proximal accuracy" calculates the proximity accuracy of independent VHF validation data relative to landscape mean distance to habitat. # --------------------------------------------------------------------------- # Define version diff --git a/README.md b/README.md index a7e8771..01bf478 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,18 @@ -# Calving Season Habitat Preferences of Moose in Southwest Alaska -Scripts for processing GPS telemetry data and analyzing properties of movement and space use of migratory and resident moose. - -This project is a collaboration between the Alaska Center for Conservation Science and the Alaska Department of Fish and Game. +# Calving Season Habitat Selection of Moose in Southwest Alaska +Calving habitat selection for maternal and non-maternal females and comparison of among individual variation *Authors*: Amanda Droghini, Timm W. Nawrocki, Alaska Center for Conservation Science, University of Alaska Anchorage -*Last updated*: 2021-04-29 +*Last updated*: 2024-10-02 + +*Description*: This repository includes scripts for processing GPS telemetry data, preparing geospatial covariates, analyzing selection patterns among female moose in maternal and non-maternal group, and plotting variation among individuals between both groups along a relative unitless scale. Folders and scripts are numbered in order of execution, except those that contain functions (folders starting with "package_"). This project is a collaboration between the Alaska Center for Conservation Science and the Alaska Department of Fish and Game. + +## Getting Started + +The installation of R, ArcGIS Pro bundled with Python, and an independent Python with the dependencies listed below is required to execute the full suite of scripts included in this repository. The header of each script indicates in what system the script should be executed. -# Prerequisites +### Prerequisites 1. ArcGIS Pro 2.5.2+ 1. Python 3.6.9+ 2. R 4.0.0+ @@ -25,22 +29,25 @@ Amanda Droghini, Timm W. Nawrocki, Alaska Center for Conservation Science, Unive 11. tlocoh 1.40.7+ 12. zoo 1.8.8+ 3. R Studio 1.3.9+ +4. Python 3.8.8+ (Anaconda 2021.05 or later distribution) + 1. scikit-learn 0.24.2+ -# Credits -## Authors +## Credits + +### Authors * **Amanda Droghini** - *Alaska Center for Conservation Science, University of Alaska Anchorage* * **Timm W. Nawrocki** - *Alaska Center for Conservation Science, University of Alaska Anchorage* -## Usage Requirements +### Usage Requirements Use of the scripts included in this repository should be cited as follows: -Droghini, A., and T.W. Nawrocki. 2021. Space Use and Movement Patterns of Moose in Southwest Alaska. Git Repository. Available: https://github.com/accs-uaa/southwest-alaska-moose +Droghini, A., T.W. Nawrocki, J.B. Stetz, P.A. Schuette, A.R. Aderman, and K.E. Colson. 2024. Variation in habitat selection among individuals differs by maternal status for moose in a region with low calf survival. Ecosphere [volume:identifier]. -## Citations -Evans J.S., J. Oakleaf, S. A. Cushman. 2014. An ArcGIS Toolbox for Surface Gradient and Geomorphometric Modeling, version 2.0-0. Available: https://github.com/jeffreyevans/GradientMetrics +### Citations +We referenced the following for the scripts that calculate topographic indices: -Nawrocki, T.W. 2020. Beringian Vegetation. Git Repository. Available: https://github.com/accs-uaa/beringian-vegetation +Evans J.S., J. Oakleaf, S. A. Cushman. 2014. An ArcGIS Toolbox for Surface Gradient and Geomorphometric Modeling, version 2.0-0. Available: https://github.com/jeffreyevans/GradientMetrics ### License diff --git a/geospatial_AnalyticGrids/archive/DataExtract_Grids_Tundra.R b/geospatial_AnalyticGrids/archive/DataExtract_Grids_Tundra.R deleted file mode 100644 index ef1088d..0000000 --- a/geospatial_AnalyticGrids/archive/DataExtract_Grids_Tundra.R +++ /dev/null @@ -1,101 +0,0 @@ -# -*- coding: utf-8 -*- -# --------------------------------------------------------------------------- -# Extract Covariates to Grids -# Author: Timm Nawrocki -# Last Updated: 2020-11-30 -# Usage: Must be executed in R 4.0.0+. -# Description: "Extract Covariates to Grids" extracts data from rasters to prediction grids. -# --------------------------------------------------------------------------- - -# Set root directory -root_folder = 'N:/ACCS_Work/Projects/WildlifeEcology/Moose_SouthwestAlaska/Data' - -# Define input grid list -grid_file = paste(root_folder, - 'Data_Input/grids/gridMinor_selected.xlsx', - sep ='/') - -# Define input folders -grid_folder = 'N:/ACCS_Work/Data/analyses/gridMinor' -edge_folder = paste(root_folder, - 'Data_Input/edge_distance', - sep = '/') -output_folder = paste(root_folder, - 'Data_Output/extracted_grids_tundra', - sep = '/') - -# Install required libraries if they are not already installed. -Required_Packages <- c('dplyr', 'raster', 'rgdal', 'sp', 'stringr') -New_Packages <- Required_Packages[!(Required_Packages %in% installed.packages()[,"Package"])] -if (length(New_Packages) > 0) { - install.packages(New_Packages) -} -# Import required libraries for geospatial processing: dplyr, raster, rgdal, sp, and stringr. -library(dplyr) -library(raster) -library(readxl) -library(rgdal) -library(sp) -library(stringr) - -# Define input grid list -grid_table = read_xlsx(grid_file, sheet = 'minor_grids') -grid_list = pull(grid_table, var = 'Minor') -grid_length = length(grid_list) - -# Create a list of all predictor rasters -predictors_edge = paste(edge_folder, - 'southwestAlaska_TundraEdge.tif', - sep = '/') -predictors_all = predictors_edge -print(paste('Number of predictor rasters: ', length(predictors_all), sep = '')) - -# Generate a stack of all predictor rasters -print('Creating raster stack...') -start = proc.time() -predictor_stack = stack(predictors_all) -end = proc.time() - start -print(end[3]) - -# Loop through all grids with site data and extract covariates to sites -count = 1 -for (grid in grid_list) { - - # Define output csv file - output_csv = paste(output_folder, '/', grid, '.csv', sep = '') - - # If output csv file does not already exist, extract covariates to grid - if (!file.exists(output_csv)) { - print(paste('Extracting predictor data to Grid ', grid, ' (', count, ' of ', grid_length, ')...', sep='')) - - # Create full path to grid raster - grid_file = paste(grid_folder, '/', 'Grid_', grid, '.tif', sep = '') - - # Convert raster to spatial dataframe of points - grid_raster = raster(grid_file) - grid_points = data.frame(rasterToPoints(grid_raster, spatial=FALSE)) - grid_points = grid_points[,1:2] - - # Read site data and extract covariates - print('Extracting covariates...') - start = proc.time() - grid_extracted = data.frame(grid_points, extract(predictor_stack, grid_points)) - end = proc.time() - start - print(end[3]) - - # Find plot level mean values and convert field names to standard - grid_extracted = grid_extracted %>% - rename(tundra_edge = southwestAlaska_TundraEdge) - - # Export data as a csv - write.csv(grid_extracted, file = output_csv, fileEncoding = 'UTF-8') - print(paste('Finished extracting data to Grid ', grid, '.', sep = '')) - print('----------') - } else { - print(paste('File for Grid ', grid, ' already exists.', sep = '')) - print('----------') - } - - # Increase the count by one - count = count + 1 -} diff --git a/geospatial_AnalyticGrids/archive/DataExtract_MergeGrids.R b/geospatial_AnalyticGrids/archive/DataExtract_MergeGrids.R deleted file mode 100644 index 62fe4dd..0000000 --- a/geospatial_AnalyticGrids/archive/DataExtract_MergeGrids.R +++ /dev/null @@ -1,70 +0,0 @@ -# -*- coding: utf-8 -*- -# --------------------------------------------------------------------------- -# Merge extracted grids -# Author: Timm Nawrocki -# Last Updated: 2021-06-26 -# Usage: Must be executed in R 4.0.0+. -# Description: "Merge extracted grids" merges the primary extraction data with the updated tundra edge data. -# --------------------------------------------------------------------------- - -# Set root directory -root_folder = 'N:/ACCS_Work/Projects/WildlifeEcology/Moose_SouthwestAlaska/Data' - -# Define input grids -original_folder = paste(root_folder, - 'Data_Output/extracted_grids', - sep ='/') -tundra_folder = paste(root_folder, - 'Data_Output/extracted_grids_tundra', - sep = '/') - -# Define output folder -output_folder = paste(root_folder, - 'Data_Output/extracted_grids_merge', - sep = '/') - -# Import required libraries for geospatial processing: dplyr, stringr, tidyr. -library(dplyr) -library(stringr) -library(tidyr) - -# Define input grid list -grids_list = list.files(path = original_folder, pattern = 'csv', full.names = FALSE) - -# Loop through grids and merge original with updated tundra data -for (grid in grids_list) { - # Define grid files - original_grid = paste(original_folder, - grid, - sep = '/') - tundra_grid = paste(tundra_folder, - grid, - sep = '/') - output_grid = paste(output_folder, - grid, - sep = '/') - - # Import grid files to tables - original_data = read.csv(original_grid, encoding = 'UTF-8') - tundra_data = read.csv(tundra_grid, encoding = 'UTF-8') - - # Prepare tundra data for merge - tundra_data = tundra_data %>% - mutate(join_name = paste(x, y, sep = '_')) %>% - select(-X, -x, -y) - - # Prepare original data for merge - original_data = original_data %>% - mutate(join_name = paste(x, y, sep = '_')) %>% - select(-X, -tundra_edge) - - # Join original data to tundra edge - merged_data = original_data %>% - left_join(tundra_data, by = 'join_name') %>% - select(-join_name) - - # Export data as a csv - write.csv(merged_data, file = output_grid, fileEncoding = 'UTF-8') - print(paste('Finished extracting data to Grid ', grid, '.', sep = '')) - print('----------') -} diff --git a/postprocess_Habitat/HabitatPrediction_CompareConfidenceIntervals.R b/postprocess_Habitat/HabitatPrediction_CompareConfidenceIntervals.R deleted file mode 100644 index f5cd3eb..0000000 --- a/postprocess_Habitat/HabitatPrediction_CompareConfidenceIntervals.R +++ /dev/null @@ -1,54 +0,0 @@ -# -*- coding: utf-8 -*- -# --------------------------------------------------------------------------- -# Plot prediction distributions -# Author: Timm Nawrocki, Alaska Center for Conservation Science -# Last Updated: 2021-08-29 -# Usage: Script should be executed in R 4.0.0+. -# Description: "Plot prediction distributions" creates a plot of the distribution of standardized predictions by calf status. -# --------------------------------------------------------------------------- - -# Set root directory -drive = 'N:' -root_folder = 'ACCS_Work' - -# Define input data -data_folder = paste(drive, - root_folder, - 'Projects/WildlifeEcology/Moose_SouthwestAlaska/Data', - sep = '/') -nocalf_file = paste(data_folder, - 'Data_Output/data_package/version_1.2_20210820', - 'allPoints_Observed_Predicted_0.csv', - sep = '/') - -# Import libraries -library(boot) -library(dplyr) -library(ggplot2) -library(RColorBrewer) -library(simpleboot) -library(tidyr) - -# Import data to data frame and pivot to long form -nocalf_data = read.csv(nocalf_file) -nocalf_data = nocalf_data %>% - select(-mooseyear_id, -pointID, -calf_status, -deployment_id, -fullPath_id, - -calf_select, - calf_ci95, -nocalf_select, -nocalf_ci95, -x, -y) %>% - pivot_longer(!fullPoint_id, names_to = 'iteration', values_to = 'selection') - -# Generate list of CID -nocalf_ids = nocalf_data %>% - select(fullPoint_id) %>% - unique() -nocalf_ids = nocalf_ids[['fullPoint_id']] - -# Subset the data to a point of choice for comparison -subset = nocalf_data %>% - filter(fullPoint_id == nocalf_ids[10]) - -# Convert subset data to vector -d = subset[['selection']] - -# Calculate confidence intervals by bootstrap (compare these to the confidence interval width raster values) -boot.obj = one.boot(d, FUN = mean, R = 500) -boot.ci(boot.obj, conf = 0.95, type = 'all') \ No newline at end of file diff --git a/statistics_PathSelection/02a-exploratory-CollinearityVIF.py b/statistics_PathSelection/02a-exploratory-CollinearityVIF.py deleted file mode 100644 index 8a1b6f4..0000000 --- a/statistics_PathSelection/02a-exploratory-CollinearityVIF.py +++ /dev/null @@ -1,45 +0,0 @@ -# coding: utf-8 - -# Original code from: https://github.com/SushmithaPulagam/Fixing-Multicollinearity - -# Import required libraries -import pandas as pd -import os -from statsmodels.stats.outliers_influence import variance_inflation_factor - -# Define outputs -output_filepath = "C:\\ACCS_Work\\Projects\\Moose_SouthwestAlaska\\Data_03_Output\\pathSelectionFunction" - -# Define inputs -input_filepath = "C:\\ACCS_Work\\Projects\\Moose_SouthwestAlaska\\Data_02_Pipeline\\01-dataPrepForAnalyses\\" -maternal = pd.read_csv(os.path.join(input_filepath,"paths_maternal_20221228.csv")) -non_maternal = pd.read_csv(os.path.join(input_filepath,"paths_nonmaternal_20221228.csv")) - -# Define function -# To calculate the VIF scores for all independent features with for loop -def vif_scores(df): - VIF_Scores = pd.DataFrame() - VIF_Scores["Independent Features"] = df.columns - VIF_Scores["VIF Scores"] = [variance_inflation_factor(df.values,i) for i in range(df.shape[1])] - return VIF_Scores - -# Create dataframes with only our independent variables (incl. ones that aren't in the conditional regression/Poisson model) -maternal_independent = maternal.loc[:, 'elevation_mean':'wetsed_mean'] -non_maternal_independent = non_maternal.loc[:, 'elevation_mean':'wetsed_mean'] - -# Only covariates included in conditional Poisson model -maternal_subset = maternal.loc[:, ['forest_edge_mean', 'tundra_edge_mean', - 'alnus_mean', 'salshr_mean', 'roughness_mean', 'wetsed_mean']] -non_maternal_subset = non_maternal.loc[:, ['forest_edge_mean', 'tundra_edge_mean', - 'alnus_mean', 'salshr_mean', 'roughness_mean', 'wetsed_mean']] - -# Calculate VIF scores for all independent variables -vif_maternal = vif_scores(maternal_independent) -vif_non_maternal = vif_scores(non_maternal_independent) - -vif_maternal_subset = vif_scores(maternal_subset) -vif_non_maternal_subset = vif_scores(non_maternal_subset) - -# Export results -vif_maternal.to_csv(path_or_buf=os.path.join(output_filepath,'maternal_vif_scores.csv'), index=False) -vif_non_maternal.to_csv(path_or_buf=os.path.join(output_filepath,'non_maternal_vif_scores.csv'), index=False) \ No newline at end of file diff --git a/statistics_PathSelection/02b-exploratoryModel_maternal.R b/statistics_PathSelection/02b-exploratoryModel_maternal.R deleted file mode 100644 index 23a38b8..0000000 --- a/statistics_PathSelection/02b-exploratoryModel_maternal.R +++ /dev/null @@ -1,93 +0,0 @@ -# -*- coding: utf-8 -*- -# --------------------------------------------------------------------------- -# Explore candidate models for habitat selection of maternal moose -# Author: Amanda Droghini -# Last Updated: 2022-12-28 -# Usage: Code chunks must be executed sequentially in RStudio/2022.12.0+353 or RStudio Server installation. -# Description: Run full model on a small number (n=10) of iterations in which every available path is unique. Evaluate model estimates and adjust formula as needed. Code follows recommendations in Muff et al. (2020) and Muff et al. (2021). -# Citations: -# 1) Muff, S., J. Signer, and J. Fieberg. 2020. Accounting for individual‐specific variation in habitat‐selection studies: Efficient estimation of mixed‐effects models using Bayesian or frequentist computation. Journal of Animal Ecology 89(1):80–92. -# 2) Muff, S., J. Signer, and J. Fieberg. 2021. R Code and Output Supporting "Accounting for individual-specific variation in habitat-selection studies: Efficient estimation of mixed-effects models using Bayesian or frequentist computation". Retrieved from the Data Repository for the University of Minnesota, https://doi.org/10.13020/8bhv-dz98. -# --------------------------------------------------------------------------- - -rm(list=ls()) - -#### Define Git directory ---- -git_dir <- "C:/ACCS_Work/GitHub/southwest-alaska-moose/package_Statistics/" - -#### Load packages & functions ---- -source(paste0(git_dir,"init.R")) - -#### Load data ---- -maternal <- read_csv(file=paste(pipeline_dir, - "01-dataPrepForAnalyses", - "paths_maternal_20221228.csv", - sep="/")) - -# Exploratory model run ---- -# Run through a few iterations to see if full model specification will converge -num_iterations <- 10 -sample_iterations <- sample(0:49, size = num_iterations, replace = FALSE) - -# Specify full model formula -full_formula <- formula(response ~ -1 + forest_edge_mean + - tundra_edge_mean + - alnus_mean + - salshr_mean + - roughness_mean + - wetsed_mean + - (0 + forest_edge_mean | animal_id) + - (0 + alnus_mean | animal_id) + - (0 + tundra_edge_mean | animal_id) + - (0 + salshr_mean | animal_id) + - (0 + roughness_mean | animal_id) + - (0 + wetsed_mean | animal_id) + - (1 | strata_id)) - -# Run mixed-effects model -list_results <- exploreModelFit(data = maternal, - sample_ids = sample_iterations, - model_formula = full_formula) - -# Convert list to dataframe -coef_fixed <- data.table::rbindlist(list_results[[1]],use.names=FALSE,idcol=TRUE) - -# Trouble-shoot model formula ---- -# https://cran.r-project.org/web/packages/glmmTMB/vignettes/troubleshooting.html - -# There are a few random effects whose variance is estimated to be zero: tundra_edge_km, roughness_mean, and wetsed_mean that are possibly leading to convergence issues -# Apply natural log transform since covariates were exponentiated -coef_fixed %>% filter(log(lower_95) == 0) %>% - distinct(covariate) - -# Try formula w/o these random effects -# Will also help with over-parameterization -restricted_formula <- formula(response ~ -1 + - forest_edge_mean + - tundra_edge_mean + - alnus_mean + - salshr_mean + - roughness_mean + - wetsed_mean + - (0 + forest_edge_mean | animal_id) + - (0 + alnus_mean | animal_id) + - (0 + salshr_mean | animal_id) + - (1 | strata_id)) - -# Re-run model -list_results <- exploreModelFit(data = maternal, - sample_ids = sample_iterations, - model_formula = restricted_formula) - -# Convert lists to dataframe -coef_fixed <- data.table::rbindlist(list_results[[1]],use.names=FALSE,idcol=TRUE) -coef_random <- data.table::rbindlist(list_results[[2]],use.names=FALSE,idcol=TRUE) - -# Plot random effects ---- - -# Interpretation of random slope coefficients -# From glmmTMB::ranef vignette: "For coef.glmmTMB: a similar list, but containing the overall coefficient value for each level, i.e., the sum of the fixed effect estimate and the random effect value for that level. Conditional variances are not yet available as an option for coef.glmmTMB" - -# Leave them un-exponentiated otherwise range is hard to plot -# Need to add population level B estimate -boxplot(coef_random[,2:4]) \ No newline at end of file diff --git a/statistics_PathSelection/02b-exploratoryModel_nonmaternal.R b/statistics_PathSelection/02b-exploratoryModel_nonmaternal.R deleted file mode 100644 index 5e66c52..0000000 --- a/statistics_PathSelection/02b-exploratoryModel_nonmaternal.R +++ /dev/null @@ -1,142 +0,0 @@ -# -*- coding: utf-8 -*- -# --------------------------------------------------------------------------- -# Explore candidate models for habitat selection of non-maternal moose -# Author: Amanda Droghini -# Last Updated: 2022-12-28 -# Usage: Code chunks must be executed sequentially in RStudio/2022.12.0+353 or RStudio Server installation. -# Description: Run full model on a small number (n=10) of iterations in which every available path is unique. Evaluate model estimates and adjust formula as needed. Code follows recommendations in Muff et al. (2020) and Muff et al. (2021). -# Citations: -# 1) Muff, S., J. Signer, and J. Fieberg. 2020. Accounting for individual‐specific variation in habitat‐selection studies: Efficient estimation of mixed‐effects models using Bayesian or frequentist computation. Journal of Animal Ecology 89(1):80–92. -# 2) Muff, S., J. Signer, and J. Fieberg. 2021. R Code and Output Supporting "Accounting for individual-specific variation in habitat-selection studies: Efficient estimation of mixed-effects models using Bayesian or frequentist computation". Retrieved from the Data Repository for the University of Minnesota, https://doi.org/10.13020/8bhv-dz98. -# --------------------------------------------------------------------------- - -rm(list=ls()) - -#### Define Git directory ---- -git_dir <- "C:/ACCS_Work/GitHub/southwest-alaska-moose/package_Statistics/" - -#### Load packages & functions ---- -source(paste0(git_dir,"init.R")) - -#### Load data ---- -non_maternal <- read_csv(file=paste(pipeline_dir, - "01-dataPrepForAnalyses", - "paths_nonmaternal_20221228.csv", - sep="/")) - -# Exploratory model run ---- -# Run through a few iterations to see if full model specification will converge -num_iterations <- 10 -sample_iterations <- sample(0:49, size = num_iterations, replace = FALSE) - -# Run mixed-effects model ---- - -# Model Attempt #1 - Full model -# Full model formula fails -full_formula <- formula(response ~ -1 + forest_edge_mean + - tundra_edge_mean + - alnus_mean + - salshr_mean + - roughness_mean + - wetsed_mean + - (0 + forest_edge_mean | animal_id) + - (0 + alnus_mean | animal_id) + - (0 + tundra_edge_mean | animal_id) + - (0 + salshr_mean | animal_id) + - (0 + roughness_mean | animal_id) + - (0 + wetsed_mean | animal_id) + - (1 | strata_id)) - -list_results <- exploreModelFit(data = non_maternal, - sample_ids = sample_iterations, - model_formula = full_formula) -# Model warnings: -#1) Model convergence problem; non-positive-definite Hessian matrix. -#2) Model convergence problem; singular convergence -#3) In sqrt(diag(object$cov.fixed)) : NaNs produced - -# Model Attempt #2 -# Try using fewer random effects -# Use same model as maternal females: drop random effects for tundra_edge_km, roughness_mean, and wetsed_mean -restricted_formula <- formula(response ~ -1 + - forest_edge_mean + - tundra_edge_mean + - alnus_mean + - salshr_mean + - roughness_mean + - wetsed_mean + - (0 + forest_edge_mean | animal_id) + - (0 + alnus_mean | animal_id) + - (0 + salshr_mean | animal_id) + - (1 | strata_id)) - - -# Re-run model -list_results <- exploreModelFit(data = non_maternal, - sample_ids = sample_iterations, - model_formula = restricted_formula) -# Some, but not all of the iterations, converged -# Still get "non-positive-definite Hessian matrix" error - -# Convert lists to dataframe -coef_fixed <- data.table::rbindlist(list_results[[1]],use.names=FALSE,idcol=TRUE) - -# All of the random slopes are estimated to be zero -coef_fixed %>% filter(log(lower_95) == 0) %>% - distinct(covariate) - -# Model Attempt #3 - Drop forest_edge_mean as a random effect -restricted_formula <- formula(response ~ -1 + - forest_edge_mean + - tundra_edge_mean + - alnus_mean + - salshr_mean + - roughness_mean + - wetsed_mean + - (0 + alnus_mean | animal_id) + - (0 + salshr_mean | animal_id) + - (1 | strata_id)) - -list_results <- exploreModelFit(data = non_maternal, - sample_ids = sample_iterations, - model_formula = restricted_formula) -coef_fixed <- data.table::rbindlist(list_results[[1]],use.names=FALSE,idcol=TRUE) - -# Model Attempt #4 - Drop roughness as a fixed effect (based on unrealistic estimates) -restricted_formula <- formula(response ~ -1 + - forest_edge_mean + - tundra_edge_mean + - alnus_mean + - salshr_mean + - wetsed_mean + - (0 + alnus_mean | animal_id) + - (0 + salshr_mean | animal_id) + - (1 | strata_id)) - -list_results <- exploreModelFit(data = non_maternal, - sample_ids = sample_iterations, - model_formula = restricted_formula) - -coef_fixed <- data.table::rbindlist(list_results[[1]],use.names=FALSE,idcol=TRUE) - -# That worked without warnings and estimates seem reasonable - -# Model Attempt #5 - Reintroduce some of the random effects -restricted_formula <- formula(response ~ -1 + - forest_edge_mean + - tundra_edge_mean + - alnus_mean + - salshr_mean + - wetsed_mean + - (0 + forest_edge_mean | animal_id) + - (0 + alnus_mean | animal_id) + - (0 + salshr_mean | animal_id) + - (1 | strata_id)) - -list_results <- exploreModelFit(data = non_maternal, - sample_ids = sample_iterations, - model_formula = restricted_formula) - -coef_fixed <- data.table::rbindlist(list_results[[1]],use.names=FALSE,idcol=TRUE) - -# forest_edge random effect has fairly extreme estimates (upper 95% is 1.6 x 10^14), so leave it out and stick with model #4 (no roughness, only alder and salix as random effects) \ No newline at end of file diff --git a/statistics_PathSelection/03-finalModel_maternal.R b/statistics_PathSelection/03-finalModel_maternal.R deleted file mode 100644 index 2152356..0000000 --- a/statistics_PathSelection/03-finalModel_maternal.R +++ /dev/null @@ -1,92 +0,0 @@ -# -*- coding: utf-8 -*- -# --------------------------------------------------------------------------- -# Run final habitat selection function for non-maternal moose -# Author: Amanda Droghini (adroghini@alaska.edu) -# Last Updated: 2022-12-28 -# Usage: Code chunks must be executed sequentially in RStudio/2022.12.0+353 or RStudio Server installation. -# Description: Using the model formula chosen in the exploratory analysis, fit mixed-effects, conditional Poisson regression on 2,000 bootstrap samples. Sampled paths come from a larger set of 500 unique available paths, which are paired to 49 used paths in a ratio of 10 available:1 used. Code follows recommendations in Muff et al. (2020) and Muff et al. (2021). -# Citations: -# 1) Muff, S., J. Signer, and J. Fieberg. 2020. Accounting for individual‐specific variation in habitat‐selection studies: Efficient estimation of mixed‐effects models using Bayesian or frequentist computation. Journal of Animal Ecology 89(1):80–92. -# 2) Muff, S., J. Signer, and J. Fieberg. 2021. R Code and Output Supporting "Accounting for individual-specific variation in habitat-selection studies: Efficient estimation of mixed-effects models using Bayesian or frequentist computation". Retrieved from the Data Repository for the University of Minnesota, https://doi.org/10.13020/8bhv-dz98. -# --------------------------------------------------------------------------- - -rm(list=ls()) - -#### Define Git directory ---- -git_dir <- "C:/ACCS_Work/GitHub/southwest-alaska-moose/package_Statistics/" - -#### Load packages & functions ---- -source(paste0(git_dir,"init.R")) - -#### Load data ---- -maternal <- read_csv(file=paste(pipeline_dir, - "01-dataPrepForAnalyses", - "paths_maternal_20221228.csv", - sep="/")) - -#### Define output csv files ---- -output_fixed <- file.path(paste0(output_dir,"/maternal_fixed_",format(Sys.Date(), "%Y%m%d"), - ".csv")) - -output_random <- file.path(paste0(output_dir,"/maternal_random_",format(Sys.Date(), "%Y%m%d"), - ".csv")) - -# Define parameters for function ---- -boot_sample <- 2000 -sample_size <- 10 -unique_strata <- unique(maternal$strata_id) - -final_formula <- formula(response ~ -1 + - forest_edge_mean + - tundra_edge_mean + - alnus_mean + - salshr_mean + - roughness_mean + - wetsed_mean + - (0 + alnus_mean | animal_id) + - (0 + salshr_mean | animal_id) + - (1 | strata_id)) - -# Run model ---- -model_results <- iterateBootstrap(data = maternal, - n_boot_sample = boot_sample, - n_sample_size = sample_size, - strata = unique_strata, - model_formula = final_formula) - -#### Summarize results ---- - -# Convert list to dataframe -fixed_estimates <- data.table::rbindlist(model_results[[1]],use.names=FALSE,idcol=TRUE) -random_estimates <- data.table::rbindlist(model_results[[2]],use.names=FALSE,idcol=TRUE) - -# Summarize fixed / population-level estimates -final_table <- fixed_estimates %>% - rename(Covariate = covariate) %>% - group_by(Covariate) %>% - arrange(exp_coef, .by_group=TRUE) %>% - summarise("Mean Exp Coef" = mean(exp_coef, na.rm = TRUE), - lower_95 = quantile(exp_coef,0.025), - upper_95 = quantile(exp_coef,0.975), - "Within-Sample Agreement" = (sum(ci_agree)/length(ci_agree)*100)) %>% - mutate("Variable Type" = if_else(grepl("Std.Dev.",Covariate),"Random Effect","Fixed Effect")) %>% - rename("Variable Name" = "Covariate") %>% - select(`Variable Type`, everything()) %>% - arrange(`Variable Type`) - -# Format table ---- - -# Round values -final_table <- as.data.frame(cbind(final_table[,1:2], - sapply(final_table[,3:6], FUN = round, digits = 2))) - -# Combine CI into single column -final_table <- - final_table %>% mutate( - "95% CI" = paste(lower_95, upper_95, sep = ", ")) %>% - select("Variable Name","Mean Exp Coef","95% CI", "Within-Sample Agreement",-c(lower_95, upper_95)) - - -#### Export tables ---- -write_csv(final_table, file=output_fixed) -write_csv(random_estimates, file=output_random) diff --git a/statistics_PathSelection/03-finalModel_nonmaternal.R b/statistics_PathSelection/03-finalModel_nonmaternal.R deleted file mode 100644 index f1553f9..0000000 --- a/statistics_PathSelection/03-finalModel_nonmaternal.R +++ /dev/null @@ -1,92 +0,0 @@ -# -*- coding: utf-8 -*- -# --------------------------------------------------------------------------- -# Run final habitat selection function for non-maternal moose -# Author: Amanda Droghini (adroghini@alaska.edu) -# Last Updated: 2022-12-28 -# Usage: Code chunks must be executed sequentially in RStudio/2022.12.0+353 or RStudio Server installation. -# Description: Using the model formula chosen in the exploratory analysis, fit mixed-effects, conditional Poisson regression on 2,000 bootstrap samples. Sampled paths come from a larger set of 500 unique available paths, which are paired to 49 used paths in a ratio of 10 available:1 used. Code follows recommendations in Muff et al. (2020) and Muff et al. (2021). -# Citations: -# 1) Muff, S., J. Signer, and J. Fieberg. 2020. Accounting for individual‐specific variation in habitat‐selection studies: Efficient estimation of mixed‐effects models using Bayesian or frequentist computation. Journal of Animal Ecology 89(1):80–92. -# 2) Muff, S., J. Signer, and J. Fieberg. 2021. R Code and Output Supporting "Accounting for individual-specific variation in habitat-selection studies: Efficient estimation of mixed-effects models using Bayesian or frequentist computation". Retrieved from the Data Repository for the University of Minnesota, https://doi.org/10.13020/8bhv-dz98. -# --------------------------------------------------------------------------- - -rm(list=ls()) - -#### Define Git directory ---- -git_dir <- "C:/ACCS_Work/GitHub/southwest-alaska-moose/package_Statistics/" - -#### Load packages & functions ---- -source(paste0(git_dir,"init.R")) - -#### Load data ---- -non_maternal <- read_csv(file=paste(pipeline_dir, - "01-dataPrepForAnalyses", - "paths_nonmaternal_20221228.csv", - sep="/")) - -#### Define output CSV file ---- -output_fixed <- file.path(paste0(output_dir,"/nonmaternal_fixed_", - format(Sys.Date(), "%Y%m%d"), - ".csv")) -output_results <- file.path(paste0(output_dir,"/nonmaternal_results_", - format(Sys.Date(), "%Y%m%d"), - ".Rdata")) -# Define parameters for function ---- -boot_sample <- 2000 -sample_size <- 10 -unique_strata <- unique(non_maternal$strata_id) - -# Dropped random slope for alder: Running through all the bootstrap samples leads to non-convergence errors and infinite estimates of the alder random slope. -final_formula <- formula(response ~ -1 + - forest_edge_mean + - tundra_edge_mean + - alnus_mean + - salshr_mean + - wetsed_mean + - roughness_mean + - (1 | strata_id)) - -# Run model ---- -model_results <- iterateBootstrap(data = non_maternal, - n_boot_sample = boot_sample, - n_sample_size = sample_size, - strata = unique_strata, - model_formula = final_formula) - -#### Summarize results ---- - -# Convert list to dataframe -# No random slope estimates for this model -fixed_estimates <- data.table::rbindlist(model_results[[1]],use.names=FALSE,idcol=TRUE) - -# Summarize fixed / population-level estimates -final_table <- fixed_estimates %>% - rename(Covariate = covariate) %>% - group_by(Covariate) %>% - arrange(exp_coef, .by_group=TRUE) %>% - summarise("Mean Exp Coef" = mean(exp_coef, na.rm = TRUE), - lower_95 = quantile(exp_coef,0.025), - upper_95 = quantile(exp_coef,0.975), - "Within-Sample Agreement" = (sum(ci_agree)/length(ci_agree)*100)) %>% - mutate("Variable Type" = if_else(grepl("Std.Dev.",Covariate),"Random Effect","Fixed Effect")) %>% - rename("Variable Name" = "Covariate") %>% - select(`Variable Type`, everything()) %>% - arrange(`Variable Type`) - -# Format table ---- - -# Round values -final_table <- as.data.frame(cbind(final_table[,1:2], - sapply(final_table[,3:6], FUN = round, digits = 2))) - -# Combine CI into single column -final_table <- - final_table %>% mutate( - "95% CI" = paste(lower_95, upper_95, sep = ", ")) %>% - select("Variable Name","Mean Exp Coef","95% CI", - "Within-Sample Agreement",-c(lower_95, upper_95)) - - -#### Export tables ---- -write_csv(final_table, file=output_fixed) -save(model_results, file = output_results) \ No newline at end of file