This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
library(readxl)
JAA_Age <- read_excel("D:/JAA_OTOLITOS/JAA_Idade.xlsx",
sheet= "JAA_Idade", range = "A1:C576")
You can also embed plots, for example:
library(rstan)
## Loading required package: StanHeaders
## Loading required package: ggplot2
## rstan (Version 2.21.2, GitRev: 2e1f913d3ca3)
## For execution on a local, multicore CPU with excess RAM we recommend calling
## options(mc.cores = parallel::detectCores()).
## To avoid recompilation of unchanged Stan programs, we recommend calling
## rstan_options(auto_write = TRUE)
## Do not specify '-march=native' in 'LOCAL_CPPFLAGS' or a Makevars file
library(pander)
dataList = list(
'TL'=JAA_Age$Length,
'AGE'=JAA_Age$Age,
'N'= length(JAA_Age$Length)
)
# Initial values of MCMC chains based on data:
initslst <- lapply(1:4,function(i) {
list(Linf = rnorm(1,50,5), k=runif(1,0,0.5), sigma=runif(1,0,5), t0=rnorm(1,0,0.1))
})
stanfit.JAA <- stan(file = 'LVB_Only.stan',
data = dataList ,
init = initslst,
chains = 4,
iter = 10000 ,
warmup = 2000 ,
thin = 1,
verbose = F,
cores = 3)
summary(stanfit.JAA)
## $summary
## mean se_mean sd 2.5% 25%
## sigma 2.3528092 6.300729e-04 0.075651591 2.2087984 2.3013288
## t0 -0.8503934 7.567391e-04 0.085501440 -1.0192826 -0.9077829
## Linf 45.3104933 6.202514e-03 0.663454615 44.0627309 44.8461349
## k 0.1773513 6.830548e-05 0.007040984 0.1639721 0.1724422
## lp__ -1345.4619943 1.280781e-02 1.411708107 -1349.0219429 -1346.1676795
## 50% 75% 97.5% n_eff Rhat
## sigma 2.3511530 2.4022530 2.5068700 14416.32 0.9999536
## t0 -0.8500368 -0.7922310 -0.6855015 12765.99 1.0000319
## Linf 45.2948282 45.7544593 46.6487591 11441.60 1.0000402
## k 0.1772670 0.1820586 0.1914346 10625.65 1.0000475
## lp__ -1345.1408425 -1344.4222978 -1343.6906718 12148.98 1.0001134
##
## $c_summary
## , , chains = chain:1
##
## stats
## parameter mean sd 2.5% 25% 50%
## sigma 2.3541284 0.075429966 2.2096061 2.3025776 2.3525764
## t0 -0.8491314 0.084693621 -1.0160665 -0.9059365 -0.8486640
## Linf 45.3034939 0.658929663 44.0592174 44.8536123 45.2887111
## k 0.1774459 0.006982161 0.1641015 0.1726049 0.1774275
## lp__ -1345.4406557 1.393513620 -1348.9245755 -1346.1419756 -1345.1274911
## stats
## parameter 75% 97.5%
## sigma 2.4033693 2.5071570
## t0 -0.7924355 -0.6838805
## Linf 45.7399073 46.6402671
## k 0.1820330 0.1915038
## lp__ -1344.4180175 -1343.6944792
##
## , , chains = chain:2
##
## stats
## parameter mean sd 2.5% 25% 50%
## sigma 2.3521678 0.076649872 2.2109871 2.3006372 2.3487739
## t0 -0.8515706 0.084876658 -1.0164914 -0.9082055 -0.8517092
## Linf 45.3162809 0.657357361 44.0710322 44.8617467 45.3056759
## k 0.1772629 0.006926823 0.1639033 0.1724511 0.1770696
## lp__ -1345.4878628 1.432857124 -1349.0914222 -1346.1890697 -1345.1616156
## stats
## parameter 75% 97.5%
## sigma 2.4031407 2.5103422
## t0 -0.7929363 -0.6900001
## Linf 45.7612050 46.6275498
## k 0.1818524 0.1912054
## lp__ -1344.4345959 -1343.6870065
##
## , , chains = chain:3
##
## stats
## parameter mean sd 2.5% 25% 50%
## sigma 2.3525448 0.075848171 2.207602 2.3006973 2.3509932
## t0 -0.8514984 0.086858123 -1.023807 -0.9101929 -0.8505107
## Linf 45.3189031 0.675812769 44.055230 44.8365397 45.3052843
## k 0.1772610 0.007193579 0.163571 0.1721655 0.1771408
## lp__ -1345.4786776 1.391588779 -1349.022690 -1346.2048175 -1345.1771448
## stats
## parameter 75% 97.5%
## sigma 2.4010152 2.5066879
## t0 -0.7927890 -0.6858649
## Linf 45.7714072 46.6698833
## k 0.1821613 0.1914804
## lp__ -1344.4397657 -1343.7032828
##
## , , chains = chain:4
##
## stats
## parameter mean sd 2.5% 25% 50%
## sigma 2.3523959 0.074663105 2.2077598 2.3012381 2.3518500
## t0 -0.8493732 0.085545870 -1.0167552 -0.9070260 -0.8494801
## Linf 45.3032953 0.661527202 44.0673719 44.8349638 45.2805142
## k 0.1774354 0.007057577 0.1641971 0.1725292 0.1774261
## lp__ -1345.4407811 1.427968628 -1349.0155144 -1346.1285677 -1345.0963461
## stats
## parameter 75% 97.5%
## sigma 2.401843 2.5004867
## t0 -0.790961 -0.6831506
## Linf 45.745784 46.6464276
## k 0.182134 0.1915055
## lp__ -1344.403050 -1343.6811566
Note that the echo = FALSE
parameter was added to the code chunk to prevent printing of the R code that generated the plot.
library(bayesplot)
## This is bayesplot version 1.8.0
## - Online documentation and vignettes at mc-stan.org/bayesplot
## - bayesplot theme set to bayesplot::theme_default()
## * Does _not_ affect other ggplot2 plots
## * See ?bayesplot_theme_set for details on theme setting
color_scheme_set("mix-green-blue")
pairs(stanfit.JAA, pars = c("Linf", "k","t0", "sigma"))
mcmc_combo(stanfit.JAA,pars = c("Linf", "k", "t0", "sigma"))
mcmc_acf(stanfit.JAA,pars = c("Linf", "k", "t0", "sigma"))