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(nimble) | |
library(coda) | |
## Data | |
k <- 10 | |
x <- c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) | |
y <- c(1, 2, 2, 6, 4, 5, 8, 9, 9, 9, 10) | |
n <- length(x) | |
## Code |
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(nimble) | |
library(dplyr) | |
# Data | |
set.seed(123) | |
n <- 40 | |
omega <- 0.4 | |
lambda <- 3 | |
y <- rbinom(n, 1, omega) * rpois(n, lambda) |
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(rstan) | |
options(mc.cores = parallel::detectCores()) | |
rstan_options(auto_write = TRUE) | |
## | |
set.seed(20180816) | |
N <- 100 | |
Y <- rnorm(N, 4, 1) |
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
# KFAS model with offset | |
set.seed(20180830) | |
T <- 100 | |
sigma <- 0.05 | |
dens <- rep(NA, T) | |
dens[1] <- 0.5 | |
for (t in 2:T) | |
dens[t] <- exp(rnorm(1, log(dens[t - 1]), sigma)) | |
area <- rep(c(10, 20), T / 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
--- | |
title: "fit negative binomial to Poisson data" | |
output: html_notebook | |
--- | |
## Data | |
```{r} | |
library(ggplot2) | |
library(magrittr) |
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(sf) | |
library(jpndistrict) | |
library(stringr) | |
library(ggplot2) | |
# 札幌市 | |
sapporo <- jpn_cities(jis_code = sprintf("%05d", 1101:1110)) | |
ggplot(sapporo) + | |
geom_sf(aes(fill = city_code)) + | |
scale_fill_discrete(name = "区", |
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
# | |
# Estimating "wiggly" covariate relationships using Gaussian Process | |
# | |
# cf. Section 10.14 of | |
# Kéry and Royle (2016) "Applied Hierarchical Modeling in Ecology" Vol.1 | |
# | |
library(rstan) | |
options(mc.cores = parallel::detectCores()) | |
rstan_options(auto_write = 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
data { | |
int<lower = 1> M; | |
int<lower = 1> J; | |
int<lower = 0, upper = 1> Y[M, J]; | |
vector[M] VegHt; | |
matrix[M, J] Wind; | |
vector[M] XvegHt; | |
vector[M] Xwind; | |
} | |
transformed data { |
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
data { | |
int<lower = 1> N_ind; // Number of individuals | |
int<lower = 1> N_z; // Number of augment observed data | |
vector<lower = 0>[N_ind] X; // Observed distance | |
int<lower = 0, upper = 1> Y[N_ind + N_z]; // Augumented inds. have y=0 by | |
// definition | |
real B; // Strip half-width | |
// Larger than max observed distance | |
} | |
parameters { |
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
data { | |
int<lower = 1> N_ind; // Number of individuals | |
int<lower = 1> N_z; // Number of augment observed data | |
int<lower = 0, upper = 1> Y[N_ind + N_z]; // Augumented inds. have y=0 by | |
// definition | |
real B; // Strip half-width | |
// Larger than max observed distance | |
int<lower = 1> N_D; // N intervals | |
int<lower = 1, upper = N_D> D_class[N_ind]; // Distance class | |
real<lower = 0, upper = B> Delta; // Width of distance bins |