# \donttest{
# priors
mu_prior <- b_prior(family="normal", pars=c(0, 100))
sigma_prior <- b_prior(family="uniform", pars=c(0, 500))
# attach priors to relevant parameters
priors <- list(c("mu_a", mu_prior),
c("sigma_a", sigma_prior),
c("mu_b", mu_prior),
c("sigma_b", sigma_prior),
c("mu_s", sigma_prior),
c("sigma_s", sigma_prior))
# generate data and fit
x <- vector()
y <- vector()
s <- vector()
for (i in 1:5) {
x <- c(x, rep(1:10, 2))
y <- c(y, rnorm(20, mean=1:10, sd=2))
s <- c(s, rep(i, 20))
}
fit1 <- b_linear(x=x, y=y, s=s, priors=priors, chains=1)
fit2 <- b_linear(x=x, y=-2*y, s=s, priors=priors, chains=1)
# a short summary of fitted parameters
summary(fit1)
# a more detailed summary of fitted parameters
print(fit1)
show(fit1)
# plot the fitted distribution against the data
plot(fit1)
plot_fit(fit1)
# plot the fitted distribution against the data,
# plot on the top (group) level
plot(fit1, subjects=FALSE)
plot_fit(fit1, subjects=FALSE)
# traceplot of the fitted parameters
plot_trace(fit1)
# extract parameter values from the fit
parameters <- get_parameters(fit1)
# extract parameter values on the bottom (subject) level from the fit
subject_parameters <- get_subject_parameters(fit1)
# compare means between two fits
compare_means(fit1, fit2=fit2)
# compare means between two fits, use a rope interval for intercept and slope
compare_means(fit1, fit2=fit2, rope_intercept=0.5, rope_slope=0.2)
# visualize difference in means between two fits
plot_means_difference(fit1, fit2=fit2)
# visualize difference in means between two fits,
# use a rope interval for intercept and slope,
# set the number of bins in the histogram
plot_means_difference(fit1, fit2=fit2, rope_intercept=0.5, rope_slope=0.2, bins=20)
# visualize difference in means between two fits, compare only slope
plot_means_difference(fit1, fit2=fit2, par="slope")
# visualize means of a single fit
plot_means(fit1)
# visualize means of two fits
plot_means(fit1, fit2=fit2)
# visualize means of two fits, plot slope only
plot_means(fit1, fit2=fit2, par="slope")
# draw samples from distributions underlying two fits and compare them,
# use a rope interval for intercept and slope
compare_distributions(fit1, fit2=fit2, rope_intercept=0.5, rope_slope=0.2)
# visualize the distribution underlying a fit
plot_distributions(fit1)
# visualize distributions underlying two fits
plot_distributions(fit1, fit2=fit2)
# visualize distributions underlying two fits, plot slope only
plot_distributions(fit1, fit2=fit2, par="slope")
# visualize difference between distributions underlying two fits
plot_distributions_difference(fit1, fit2=fit2)
# visualize difference between distributions underlying two fits,
# use a rope interval for intercept and slope,
# set the number of bins in the histogram
plot_distributions_difference(fit1, fit2=fit2, rope_intercept=0.5, rope_slope=0.2, bins=20)
# visualize difference between distributions underlying two fits, plot slope only
plot_distributions_difference(fit1, fit2=fit2, par="slope")
# }
Run the code above in your browser using DataLab