Git Product home page Git Product logo

coda4dummies's Introduction

The 'coda4dummies' R package

Functions to summarize inconvenient rjags or jagsUI coda outputs. Especially helpful when your coda summary contains timeseries variables of different lengths (e.g., when calculating posteriors for variables at daily, weekly, and seasonal timescales within the same model framework). The main function of this package is to streamline the model fitting/ output summarizing process with the least amount of thinking possible. Many functions included here are wrapper functions around functions from the postjags package developed by Michael Fell (https://github.com/fellmk/PostJAGS).

To install the package add the following code to your R script:

install.packages("devtools")
library(devtools)

First download Mike Fell's postjags package, which is a dependency:

devtools::install_github("fellmk/PostJAGS/postjags")
library(postjags)

Then download the coda4dummies package:

devtools::install_github("egreich/coda4dummies", build_vignettes = TRUE)
library(coda4dummies)

Note that you will have to load postjags with library(postjags) everytime you use coda4dummies.

Example

Create a tidyverse-friendly dataframe

# Organize the coda object as a dataframe
df_model <- dumsum(jagsobj = jagsui, type = "jagsUI")

# Connect dates to the dataframe by variable
  df_model <- dateconnect(dfobj = df_model, datevect = DOY, datename = "DOY", identifier = "ID2", varlist = c("dYdX"))
  df_model <- dateconnect(dfobj = df_model, datevect = YIN$TIMESTAMP, datename = "TIMESTAMP", identifier = NULL, varlist = c("WUE.pred", "T.ratio", "T.pred", "ET.pred"))

Save initials for future runs

# inits to save
init_names = names(initslist[[1]]) # get the initial names from the list of initials you used to start the model

# create a saved_state object with initials for next run
# saved_state[[1]] will be the names of the initials
# saved_state[[2]] will be the list of initials
# saved_state[[3]] will be the chain number with lowest deviance
saved_state <- keepvars(codaobj = jagsui, to_keep = init_names, paramlist = params, type="jagsUI")

save(saved_state, file = initfilename) # saving the saved_state locally

Restarting the model with initials based on the lowest deviance chain


load(initfilename) # loading the saved_state

# Create new initials based on the chain with the lowest deviance
new_saved_state <- lowdevrestart(saved_state = saved_state, vary_by = 10)

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.