Giter Site home page Giter Site logo

zuranojp / bbgdm Goto Github PK

View Code? Open in Web Editor NEW

This project forked from skiptoniam/bbgdm

0.0 2.0 0.0 3.55 MB

bbgdm: Assess uncertainty in Generalised Dissimilarity Models via a Bayesian bootstrap

License: GNU General Public License v2.0

R 89.79% C++ 10.21%

bbgdm's Introduction

BBGDM

Travis-CI Build Status codecov.io License: GPL v2

BBGDM is a R package for running Generalized Dissimilarity Models with Bayesian Bootstrap for parameter estimation. To install package run the following command in your R terminal

install.packages(c('devtools'))
devtools::install_github('skiptoniam/bbgdm')
Load the required libraries, we need vegan for the dune dataset.
library(bbgdm)
library(vegan)
Run bbgdm on the famous dune meadow data

The dune meadow vegetation data, dune, has cover class values of 30 species on 20 sites. Make the abundance data presence/absence.

data(dune)
data(dune.env)
dune_pa <- ifelse(dune>0,1,0)
Fit a bbgdm

Now we have a species by sites matrix of vegetation data and the associated environmental data for these sites.

form <- ~1+A1
fm1 <- bbgdm(form,dune_pa, dune.env,family="binomial",link='logit',
             dism_metric="number_non_shared",spline_type = 'ispline',
             nboot=100, geo=FALSE,optim.meth='nlmnib',control = bbgdm.control(cores = 8))
Print model summary

Here we print out the basic details of the model.

print(fm1)
##  A Bayesian Bootstrap GDM fitted against:
##  20 sites,
##  30 species and 
##  190 dissimilarities used as observations in the model.
## 
##  A total of 100 Bayesian Bootstraps were ran.
## 
##  Spline base parameter estimates are: 
##  (Intercept) 0.6346
##  x_1 0
##  x_2 0.0172
##  x_3 0.6756
Plot diagnostics

Using the diagnostics function we can extract Random Qunatile Residuals for plotting.

resids <- diagnostics(fm1)
par(mfrow=c(2,2))
plot(resids)

Plot response curves

We can use as.response to look at the spline responses in our BBGDM. The black line represents the median fit, while the grey shaded area is the uncertainty in this fit.

response <- as.response(fm1)
par(mfrow=c(1,1))
plot(response)

Run 'Wald-like' test on parameters
library(xtable)
wt <- bbgdm.wald.test(fm1)
tab <- xtable(wt)
print(tab, type = "html")
bbgdm\_W bbgdm\_df bbgdm\_p-value
intercept 9.19 1.00 0.00
A1 1.60 3.00 0.66
##### Predict BBGDM model
#generate some random spatial autocorrelated data.
library(raster)
set.seed(123)
xy <- expand.grid(x=seq(145, 150, 0.1), y=seq(-40, -35, 0.1))
d <- as.matrix(dist(xy))
w <- exp(-1/nrow(xy) * d)
ww <- chol(w)
xy$z <- t(ww) %*% rnorm(nrow(xy), 0, 0.1)
xy$z <- scales::rescale(xy$z,range(dune.env$A1))
coordinates(xy) <- ~x+y
r <- rasterize(xy, raster(points2grid(xy)), 'z')
#give it the same name as variable in bbgdm model.
names(r)<- 'A1'
r2 <- raster(r)
res(r2) <- 0.05
r2 <- resample(r, r2)
#use this layer to predict turnover.
pred.dune.sim.dat <- predict(fm1,r2,uncertainty = TRUE)
## using default three cell neighbourhood to estimate dissimilarity
#plot the data and the turnover predictions, and error.
colram <- colorRampPalette(c("darkblue","yellow","red"))
colram.se <- colorRampPalette(c('antiquewhite','pink','red'))
par(mfrow=c(1,3),mar=c(3,2,2,6))
plot(r2,main='Simulated A1')
plot(pred.dune.sim.dat[[1]],col=colram(100),main='BBGDM turnover')
plot(pred.dune.sim.dat[[2]],col=colram.se(100),main='BBGDM CV of turnover')

bbgdm's People

Contributors

skiptoniam avatar

Watchers

James Cloos avatar Juan Pablo Zurano 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.