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
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_D; | |
int<lower = 1> N_ind; | |
real B; | |
int <lower = 1, upper = N_D> D_class[N_ind]; | |
real<lower = 0, upper = B> Delta; // Width of distance bins | |
vector<lower = 0, upper = B>[N_D] Midpt; // Interval mid-points | |
} | |
transformed data { | |
vector<lower = 0, upper = 1>[N_D] pi = 2 * Midpt / square(B) * Delta; |
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 |
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 | |
int<lower = 1> N_D; | |
real B; | |
int <lower = 1, upper = N_D> D_class[N_ind]; | |
real<lower = 0, upper = B> Delta; // Width of distance bins | |
vector<lower = 0, upper = B>[N_D] Midpt; // Interval mid-points |
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_sites; | |
int<lower = 0> N_ind; | |
int<lower = 0> N_z; | |
real<lower = 0> B; | |
vector[N_sites] Habitat; | |
vector[N_sites] Wind; | |
int<lower = 0, upper = 1> Y[N_ind + N_z]; | |
vector<lower = 0, upper = B>[N_ind] D; | |
int<lower = 1, upper = N_sites> Site[N_ind]; |
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 { |