An S4 class for storing results of normal linear model.
Functions
summary(linear_class): prints a summary of the fit.
print(linear_class): prints a more detailed summary of the fit
show(linear_class): prints a more detailed summary of the fit.
plot(linear_class): plots fitted model against the data. Use this function to explore the quality of your fit. Fit will be plotted on the subject level.
plot(linear_class, subjects='boolean'): plots fitted model against the data. Use this function to explore the quality of your fit. You can plot on the subject level (subjects=TRUE) or on the subjects level (subjects=FALSE).
plot_fit(linear_class): plots fitted model against the data. Use this function to explore the quality of your fit. Fit will be plotted on the subject level.
plot_fit(linear_class, subjects='boolean'): plots fitted model against the data. Use this function to explore the quality of your fit. You can plot on the subject level (subjects=TRUE) or on the subjects level (subjects=FALSE).
plot_trace(linear_class): traceplot for main fitted model parameters.
get_parameters(linear_class): returns a dataframe with values of fitted parameters.
get_subject_parameters(linear_class): returns a dataframe with values of fitted parameters for each subject in the hierarchical model.
compare_means(linear_class, fit2=linear_class): prints difference in slope and intercept between two groups. You can also provide the rope parameter.
plot_means_difference(linear_class, fit2=linear_class): a visualization of the difference between two groups. You can plot only slope or intercept by using the par parameter. You can also provide the rope and bins (number of bins in the histogram) parameters.
plot_means(linear_class): plots density of means. You can plot only slope or intercept by using the par parameter.
plot_means(linear_class, fit2=linear_class): plots density for the first and the second group means. You can plot only slope or intercept by using the par parameter.
compare_distributions(linear_class, fit2=linear_class): draws samples from distribution of the first group and compares them against samples drawn from the distribution of the second group.
plot_distributions(linear_class): a visualization of the fitted distribution.
plot_distributions(linear_class, fit2=linear_class): a visualization of two fitted distribution.
plot_distributions_difference(linear_class, fit2=linear_class): a visualization of the difference between the distribution of the first group and the second group. You can plot only slope or intercept by using the par parameter. You can also provide the rope and bins (number of bins in the histogram) parameters.
class
Slots
extract: Extract from Stan fit.
fit: Stan fit.
data: Raw data for the tested group.
Examples
# priorsmu_prior <- b_prior(family="normal", pars=c(0,100))sigma_prior <- b_prior(family="uniform", pars=c(0,500))# attach priors to relevant parameterspriors <- 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 fitx <- vector()y <- vector()s <- vector()for(i in1: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 parameterssummary(fit1)# a more detailed summary of fitted parametersprint(fit1)show(fit1)# plot the fitted distribution against the dataplot(fit1)plot_fit(fit1)# plot the fitted distribution against the data,# plot on the top (group) levelplot(fit1, subjects=FALSE)plot_fit(fit1, subjects=FALSE)# traceplot of the fitted parametersplot_trace(fit1)# extract parameter values from the fitparameters <- get_parameters(fit1)# extract parameter values on the bottom (subject) level from the fitsubject_parameters <- get_subject_parameters(fit1)# compare means between two fitscompare_means(fit1, fit2=fit2)# compare means between two fits, use a rope interval for intercept and slopecompare_means(fit1, fit2=fit2, rope_intercept=0.5, rope_slope=0.2)# visualize difference in means between two fitsplot_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 histogramplot_means_difference(fit1, fit2=fit2, rope_intercept=0.5, rope_slope=0.2, bins=20)# visualize difference in means between two fits, compare only slopeplot_means_difference(fit1, fit2=fit2, par="slope")# visualize means of a single fitplot_means(fit1)# visualize means of two fitsplot_means(fit1, fit2=fit2)# visualize means of two fits, plot slope onlyplot_means(fit1, fit2=fit2, par="slope")# draw samples from distributions underlying two fits and compare them,# use a rope interval for intercept and slopecompare_distributions(fit1, fit2=fit2, rope_intercept=0.5, rope_slope=0.2)# visualize the distribution underlying a fitplot_distributions(fit1)# visualize distributions underlying two fitsplot_distributions(fit1, fit2=fit2)# visualize distributions underlying two fits, plot slope onlyplot_distributions(fit1, fit2=fit2, par="slope")# visualize difference between distributions underlying two fitsplot_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 histogramplot_distributions_difference(fit1, fit2=fit2, rope_intercept=0.5, rope_slope=0.2, bins=20)# visualize difference between distributions underlying two fits, plot slope onlyplot_distributions_difference(fit1, fit2=fit2, par="slope")