This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
adf <- data.frame(x=1:100) %>% | |
mutate(y=rnorm(100, 5*x, 90)) | |
#What do we have | |
plot(adf) | |
#examine the output | |
summary(glm(y ~ x, data=adf)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MULTIPOLYGON (((-173.3941876799999875 55.5980717300000009, -168.5559317000000021 54.0107796100000002, -165.6772025799999994 54.5778467100000029, -165.1042097499999954 54.5660556999999997, -164.9849046600000122 54.5636006399999971, -164.9369200099999944 54.5213987699999976, -164.9299005899999884 54.5152252800000028, -164.9050902399999927 54.4934049100000024, -164.8942196200000012 54.4838443399999974, -164.8036491500000125 54.4038111899999990, -164.8030237199999988 54.4032585200000014, -164.7004447299999867 54.3121036300000029, -164.6969431500000098 54.3029074499999993, -164.5301978699999950 53.8649844400000006, -164.5293457399999966 53.8617368299999981, -163.7620149299999923 50.9373064099999979, -164.0171571799999981 50.8472377000000009, -164.1599166299999979 50.8198464999999970, -164.3274076799999932 50.7914016200000020, -164.5069552200000089 50.7410382200000001, -164.7422776100000021 50.7218656800000005, -164.8138120300000082 50.6738661099999987, -164.9352386699999897 50.5929327200000003, -164.98966272999999 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gamma_sample <- structure(list(Duration = c(44, 112, 60, 90, 1, 335, 1370, 425, | |
2920, 3, 3, 420, 10, 60, 4, 365, 330, 90, 335, 60, 60, 60, 0.083, | |
0.083, 24, 15, 5, 12, 956, 120, 90, 15, 10, 10, 54, 120, 16, | |
24, 13, 1800, 308, 365, 35, 1800, 14, 335, 14, 203, 22, 21, 570, | |
153, 1, 730, 122, 155, 183, 90, 21, 488, 60, 155, 40, 28, 105, | |
3, 365, 730, 65, 20, 165, 56, 365, 90, 21, 16, 365, 18, 12, 2, | |
84, 120, 840, 1, 15, 30, 180, 84, 56, 120, 25, 150, 150, 460, | |
810, 4, 4, 5, 910, 550, 2184, 3, 520, 730, 14, 28, 1095, 70, | |
365, 365, 120, 245, 1095, 56, 121, 130, 414, 58, 990, 680, 750, | |
240, 540, 450, 255, 730, 32, 365, 120, 1200, 450, 730, 730, 150, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set.seed(1) | |
x <- 1:150 | |
y <- rbinom(length(x), size = 1, prob = 0.7) | |
seas_m <- runif(length(x), 0.1, 5) | |
shape = 0.4 | |
y_true = exp(2 - 0.5 * seas_m) | |
y <- y*rgamma(length(x), rate = shape / y_true, shape = shape) | |
non_zero <- ifelse(y > 0, 1, 0) | |
d <- data.frame(days_at_sea = y, seas_m = seas_m, non_zero = non_zero) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kelp_mod_noyear <- alist( | |
kelp_s ~ dnorm(mu, sigma), | |
mu <- a[time_idx], | |
a[time_idx] ~ GPL2( Dmat , etasq , rhosq , delta_sq), | |
sigma ~ dcauchy(0,5), | |
etasq ~ dcauchy(0,2), | |
delta_sq ~ dcauchy(0,2), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rethinking) | |
#make a multivariate vector with known correlation | |
sigma_mat <- matrix(c(1,.3, 0.2, | |
0.3, 1, 0.4, | |
0.2, 0.4, 1), nrow=3) | |
z <- rmvnorm(1, c(0,0, 0), sigma_mat) | |
z_2 <- z[2] | |
z[2] <- NA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#from rethinking library for numerically stable log sums | |
log_sum_exp <- function (x) { | |
xmax <- max(x) | |
xsum <- sum(exp(x - xmax)) | |
xmax + log(xsum) | |
} | |
#function for WAIC from an LM | |
waic.lm <- function(mod, n.sims=1e3){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "Bayesian SEM with BRMS" | |
author: "Jarrett Byrnes" | |
date: "12/20/2017" | |
output: html_document | |
--- | |
```{r setup, include=FALSE} | |
#http://sites.tufts.edu/emotiononthebrain/2017/08/12/blog-posting-from-r-markdown-to-wordpress/ | |
knitr::opts_chunk$set(echo = TRUE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(broom) | |
library(sp) | |
library(spdplyr) | |
library(ggplot2) | |
library(ggmap) | |
library(rgdal) | |
library(raster) | |
#read in spatialPolygonsDataFrame (shapefile) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(broom) | |
library(sp) | |
library(spdplyr) | |
library(ggplot2) | |
library(rgdal) | |
library(raster) | |
library(rgeos) | |
library(lubridate) |