This file contains hidden or 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: "R Notebook" | |
output: html_notebook | |
--- | |
## Fitting diameter class data to Weibull distribution | |
```{r setup} | |
library(cmdstanr) | |
library(ggplot2) |
This file contains hidden or 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: "R Notebook" | |
output: html_notebook | |
--- | |
## Fitting truncated and censored data to Weibull distribution | |
Supposing tree diameter data, fitting truncated and censored data to Weibull distribution. | |
See Chapter 4 [Truncated or Censored Data](https://mc-stan.org/docs/2_28/stan-users-guide/truncated-or-censored-data.html) in the Stan User's Guide. |
This file contains hidden or 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: "R Notebook" | |
output: html_notebook | |
--- | |
Three parameter Weibull distribution | |
```{r} | |
library(ggplot2) | |
library(cmdstanr) |
This file contains hidden or 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
/* | |
* 2-d integral using Simpson's rule | |
* based on | |
* https://statmodeling.hatenablog.com/entry/waic-with-hierarchical-models | |
*/ | |
functions { | |
real f(real z, array[] real theta, real x, real y) { | |
real v; |
This file contains hidden or 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(ggplot2) | |
library(cmdstanr) | |
library(posterior) | |
library(bayesplot) | |
# data | |
set.seed(1234) | |
n <- 160 | |
n_block <- 8 | |
x <- runif(n, 0, 1) |
This file contains hidden or 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: "R Notebook" | |
output: html_notebook | |
--- | |
## Library | |
```{r} | |
library(cmdstanr) | |
``` |
This file contains hidden or 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
functions { | |
/** | |
* Returns log likelihood of N-mixture model | |
* with 2 replicated observations using | |
* bivariate Poisson distibution | |
* | |
* References | |
* Dennis et al. (2015) Computational aspects of N-mixture models. | |
* Biometrics 71:237--246. DOI:10.1111/biom.12246 | |
* Stan users mailing list |
This file contains hidden or 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
# The simplest possible N-mixture model from Section 6.3 of | |
# Applied Hierarchical Modeling in Ecology. | |
library(cmdstanr) | |
set_cmdstan_path("/usr/local/cmdstan") | |
# generate simulated data | |
lambda <- 2.5 # mean abundance | |
p <- 0.4 # detection probability |
This file contains hidden or 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
functions { | |
real partial_sum(int[] dummy_k, | |
int start, int end, | |
int[] count, | |
real lambda, | |
real p) { | |
vector[end - start + 1] lp; | |
for (k in start:end) { | |
if (k - 1 < max(count)) |
This file contains hidden or 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
# | |
# HMM Test for CmdStan 2.24 | |
# | |
library(rstan) | |
options(mc.cores = parallel::detectCores()) | |
library(cmdstanr) | |
set_cmdstan_path("/usr/local/cmdstan") | |
library(extraDistr) |