Git Product home page Git Product logo

borealbirdsandforestry's Introduction

---
title: "RunningAlbertosModels"
author: "Tati Micheletti"
date: "3/15/2018"
output: pdf_document
header-includes:
  - \usepackage{color}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, eval=FALSE)
```

## Updating SpaDES.core and reproducible

The present project needs the most updated version of SpaDES and reproducible R packages in their development versions, as well as updated dependencies of these packages. Restart your R session so it is clear. you can use a shortcut Ctrl-shift-F10 if you are in Rstudio. If you have any of our packages or their dependencies, please update them first. Get latest versions of key SpaDES packages from CRAN. Update any versions of these dependencies that are already on your machine.

```{r packages}
dependencies <- tools::package_dependencies("SpaDES", recursive = TRUE)
update.packages(oldPkgs = unlist(dependencies), ask = FALSE) 
```

Install the latest version of the SpaDES packages and any dependencies not yet installed:
```{r updateSpaDES}
install.packages("SpaDES", dependencies = TRUE) # install "suggested" packages too with TRUE
```

Restart again your R session so it is clear and install `reproducible` and `SpaDES.core`.
``` {r SpaDES.core}
reproducible::Require("devtools") # installs (if needed) and loads devtools
devtools::install_github("PredictiveEcology/SpaDES.core", ref = "development")
```
## To load previously saved outputs:

To load previously saved outputs, run the following lines and see below how to access the results:
```{r loading}
library(SpaDES)
workDirectory <- getwd()
paths <- list(
  cachePath = file.path(workDirectory, "cache"),
  modulePath = file.path(workDirectory, "modules"),
  inputPath = file.path(workDirectory, "inputs"),
  outputPath = file.path(workDirectory, "outputs")
)
setPaths(modulePath = paths$modulePath, 
         inputPath = paths$inputPath, 
         outputPath = paths$outputPath, 
         cachePath = paths$cachePath)
mySimList <- readRDS(file.path(outputPath(mySimOut), "Results_List.rds"))
```

## To run the module: glmerBirdModels (Alberto's models)

### Sourcing global script: Using all parameters as is

In order to run Alberto's models as they are, it is only necessary to run the following line: 
```{r run}
source('global.R')
```

It is possible to access the results by typing *`mySimOut$`* appended with the following codes:  

\textcolor{blue}{data}: raw data used for the models  
\textcolor{blue}{birdSpecies}`: species run for the models  
\textcolor{blue}{models}: results of the models  
\textcolor{blue}{disturbanceDimension}: disturbance dimensions used in for subsetting the data for the models  
\textcolor{blue}{typeDisturbance}: type of disturbances accessed in the models  
\textcolor{blue}{dataName}: name of the dataset used for the analysis  
\textcolor{blue}{plotAbundDist}: Plot of relative abundance per disturbance type, dimension and species on varying disturbance proportions  
\textcolor{blue}{plotCoeff}: Plot of coefficients of bird models  
\textcolor{blue}{plotDistSec}: Plot of disturbance sectors per area size  
\textcolor{blue}{plotList}: Data table of all models estimates, and std.error of % of disturbance per species, type and dimension of disturbance  
\textcolor{blue}{tableSampling}: Table with the number of samples for each type and dimension  
\textcolor{blue}{tableAIC}: Table with all AIC values for all models  

However, to change parameters for Alberto's models, it is necessary to run all the following chunks, making modifications accordingly:

### Global script: Changing parameters

Global script for the glmerBirdModels

```{r loadLib}
library(SpaDES)
```

Set the directories and paths

```{r setDir}
workDirectory <- getwd()
paths <- list(
  cachePath = file.path(workDirectory, "cache"),
  modulePath = file.path(workDirectory, "modules"),
  inputPath = file.path(workDirectory, "inputs"),
  outputPath = file.path(workDirectory, "outputs")
)
setPaths(modulePath = paths$modulePath, inputPath = paths$inputPath, outputPath = paths$outputPath, cachePath = paths$cachePath)
```

List the modules to use

```{r modules}
modules <- list("glmerBirdModels")
```

Set simulation and module parameters
```{r param}
times <- list(start = 1985, end = 1985, timeunit = "year")
parameters <- list(
  .globals = list(.plotInitialTime = 1),
  glmerBirdModels = list(cropping = TRUE, cropForModel = FALSE)
)

objects = list(birdSpecies = c("BBWA", "BLPW", "BOCH", "BRCR",
                               "BTNW", "CAWA", "CMWA","CONW",
                               "OVEN", "PISI", "RBNU", "SWTH",
                               "TEWA", "WETA", "YRWA"),
               typeDisturbance = c("Transitional", "Permanent","Both"), 
               disturbanceDimension = c("local", "neighborhood", "LocalUndisturbed"),
               dataName = "Final_points_BEAD_final.csv")
```

Simulation setup

```{r setupSpaDES}
mySim <- simInit(times = times, params = parameters, modules = modules, paths =  paths, objects = objects)
mySimOut <- spades(mySim, debug = TRUE)
```

To save the outputs

```{r save}
saveRDS(mySimOut, file.path(outputPath(mySimOut), "Results.rds"))
```

borealbirdsandforestry's People

Contributors

tati-micheletti avatar ianmseddy avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.