Giter Site home page Giter Site logo

krmp_varsens's Introduction

Variance Sensitivity

To Do

  • clean repo
  • re-calculate IVI
  • translate jags to gamma distribution
  • incorporate random slope / intercept for year with correlation
  • examine brood mass options

Intro

Investigating variance sensitivity among breeding Peregrine Falcons in response to environmental conditions and brood demand.

File Organization

├── Data
│     ├── Clean IVI years 2013-2019.csv  <- data used for analysis - cleaned by Rebekah
│     ├── ivi_eh.csv                     <- new ivi data with fixed errors
│     ├── ____ .parquet                  <- all parquet files are jags outputs converted to dataframes for easy manipulation/viz
│     ├── 
│     ├── 
│     └── 
├── Scripts 
│     ├──  simulation.R         <- simulate data to ensure variance is being captured properly by whatever model we use
│     │                            - nlme model for simplicity / jags for thorough understanding and benefits from bayesian framework
│     ├──  jags.R               <- Real Data using similar model structure to that tested in simulation.R
│     ├──  jags_v_lme4.R        <- Comparisons between lme4 and jags models
│     ├──  jags_gamma.R         <- Gamma distribution, heterogenous resids, random intercepts 
│     ├──  jags_gaus.R          <- log transformed ivi, heterogenous resids, random intercepts
│     ├──  02_jags_gaus.R       <- log transformed ivi, het resids, random intercepts, random slopes and correlation between ranefs
│     ├──  brms.R               <- 02_jags_gaus.R model minus het resids. Quick modeling of ranef covariance using lme4 syntax, with a stan backend
│     └──  ivi_scratch.R        <- Programmatically calculate IVI, produces ivi_eh.csv
└── Figures
      ├── beta_chickage.jpg     <- from jags.R - het resid variance by year
      ├── betas_broodsize.jpg   <- from jags.R - het resid variance by year
      ├── betas_broodsize.jpg   <- from jags.R - het resid variance by year
      ├── sigma_CIs.jpg         <- from jags.R - het resid variance by year
      ├── chickage-year.jpg     <- from jags.R - het resid variance by year
      └── broodsize-year.jpg    <- from jags.R - het resid variance by year



Current status

02_jags_gaus.R runs the most up-to-date model based on comments from Kim / Rebekah.

The model includes

  • random intercept for year and nest site, and random slopes for chickage and chicks nested in years.
  • The model estimates ranef from a covariance matrix of slopes/intercepts which allows us to estimate the level of covariance between yearly intercepts and the effects of chickage/chicks.
  • The model also estimates independent residual variance by year, but this can be commented out if need be. It's important to note that estimating residual variance independantly by year eats into the variation explained by other parameters such as chicks and chickage. This is demonstrated below.

Heterogenous Residuals

This is the 02_jags_gaus model with heterogenous residuals turned on.

Residual variance by year. The estimate visualized here is sigma, and associated uncertainty in the estimate of sigma stemming from the shape of the posterior:

The effect of chickage within the same model where yearly variation in the effect of chickage is captured by the random slope.

Covariance between yearly intercept and random slopes for chicks and chickage

Homogenous Residuals

If we assume residual variance is homogenous across years, varying slopes for chickage then steps up to capture that yearly variation.

We plot the residuals by year below to see if there are yearly patterns not explained in the model. It looks pretty uniform

Still moderate covariance between intercepts and slope, and the covariance is in the direction you would predict, lower intercept leads to more pronounced decrease in IVI as brood size increases.

Conclusion

Residual variance among years is captured by letting our slopes and intercepts vary. Moderate covariance between yearly intercepts and slopes.

Contributors

  • Rebekah McKinnon
  • Kim Mathot
  • Kevin Hawkshaw
  • Erik Hedlin
  • Alastair Franke

krmp_varsens's People

Contributors

emhedlin avatar rebekahmckinnon avatar

Stargazers

JwongXyan Myou avatar

Watchers

James Cloos avatar Robert avatar  avatar  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.