I am making the convergence graph of the chains generated using the traceplot function. However, see what unusual lines are appearing on the chart. How would you go about removing them?
data: https://drive.google.com/file/d/1iOuGbjNI_caLWBIz4s7hZX5GlfhLrwr9/view?usp=sharing
Below are the codes.
require(rstan)
library(boa)
library(bayesplot)
library(rstanarm)
library(ggplot2)
library(dplyr)
setwd("C:\Users\Desktop")
dados = read.table("dados.csv", header = T, sep=";", dec = ",")
dados$periodo = as.factor(dados$periodo)
dados <- dados %>% mutate(proporcao = (dados$resposta)/60)
dados <- dados %>% mutate(logdose = log(dados$concentracao))
dados <- dados %>% mutate(Período = dados$periodo)
dados<- mutate(dados,
C_resposta=60-resposta)
dados <- dados %>% dplyr::mutate(Period = ifelse(periodo %in% c("24h","24h","24h","24h","24h",
"48h","48h","48h","48h","48h",
"72h","72h","72h","72h","72h"),c("Experiment Duration: 24h",
"Experiment Duration: 24h",
"Experiment Duration: 24h",
"Experiment Duration: 24h",
"Experiment Duration: 24h",
"Experiment Duration: 48h",
"Experiment Duration: 48h",
"Experiment Duration: 48h",
"Experiment Duration: 48h",
"Experiment Duration: 48h",
"Experiment Duration: 72h",
"Experiment Duration: 72h",
"Experiment Duration: 72h",
"Experiment Duration: 72h",
dados2 = dados[c(1:5),]
n = length(dados2$logdose)
y = dados2$resposta
logistic_example24 <- "data {
int<lower=0> N;
vector[N] x;
int<lower=0> y[N];
int<lower=0> n[N];
}
parameters {
real beta1;
real beta2;
}
model {
beta1 ~ normal(0,100);
beta2 ~ normal(0,100);
y ~ binomial_logit(n, beta1 + beta2 * x);
}"
logistic_fit24 <- stan(model_code = logistic_example24,
data = list(N = dim(dados2)[1], n = dados2$total,
x = dados2$logdose, y = dados2$resposta),
chain = 3, iter = 11000, warmup = 1000,
thin = 10, refresh = 0)
x11()
par(cex=1.5,cex.lab=1.3)
traceplot(logistic_fit24,inc_warmup=T,ncol=1,col="black")+
xlab("Itera??es") +
theme_bw() + theme(axis.title = element_text(size = 28,color="black"),
axis.text = element_text(size = 24,color="black"),
strip.text.x = element_text(size = 22,color="black"))
Note that when using the stan_trace function, these atypical lines do not appear, however, my interest is in using the traceplot function due to aesthetics.
x11()
stan_trace(logistic_fit24)
question from:
https://stackoverflow.com/questions/65943693/removing-atypical-internal-lines-from-the-chain-convergence-graph-using-a-tracep