b_color {bayes4psy}R Documentation

b_color

Description

Bayesian model for comparing colors.

Usage

b_color(
  colors,
  priors = NULL,
  hsv = FALSE,
  warmup = 1000,
  iter = 2000,
  chains = 4,
  seed = NULL,
  refresh = NULL,
  control = NULL,
  suppress_warnings = TRUE
)

Arguments

colors

a data frame of colors either in RGB or HSV format. The first column should be the R (or H) component, the second column should be the G (or S) component and the third column should be the B (or V) component.

priors

List of parameters and their priors - b_prior objects. You can put a prior on the mu_r (mean r component), sigma_r (variance of mu_r), mu_g (mean g component), sigma_g (variance of mu_g), mu_b (mean b component), sigma_b (variance of mu_b), mu_h (mean h component), kappa_h (variance of mu_h), mu_s (mean s component), sigma_s (variance of mu_s), mu_v (mean v component) and sigma_v (variance of mu_v) parameters (default = NULL).

hsv

set to TRUE if colors are provided in HSV format (default = FALSE).

warmup

Integer specifying the number of warmup iterations per chain (default = 1000).

iter

Integer specifying the number of iterations (including warmup, default = 2000).

chains

Integer specifying the number of parallel chains (default = 4).

seed

Random number generator seed (default = NULL).

refresh

Frequency of output (default = NULL).

control

A named list of parameters to control the sampler's behavior (default = NULL).

suppress_warnings

Suppress warnings returned by Stan (default = TRUE).

Value

An object of class 'color_class'

Examples


# priors for rgb
mu_prior <- b_prior(family="uniform", pars=c(0, 255))
sigma_prior <- b_prior(family="uniform", pars=c(0, 100))

# attach priors to relevant parameters
priors_rgb <- list(c("mu_r", mu_prior),
                   c("sigma_r", sigma_prior),
                   c("mu_g", mu_prior),
                   c("sigma_g", sigma_prior),
                   c("mu_b", mu_prior),
                   c("sigma_b", sigma_prior))


# generate data (rgb)
r <- as.integer(rnorm(100, mean=250, sd=20))
r[r > 255] <- 255
r[r < 0] <- 0

g <- as.integer(rnorm(100, mean=20, sd=20))
g[g > 255] <- 255
g[g < 0] <- 0

b <- as.integer(rnorm(100, mean=40, sd=20))
b[b > 255] <- 255
b[b < 0] <- 0

colors_rgb <- data.frame(r=r, g=g, b=b)

# fit
fit_rgb <- b_color(colors=colors_rgb, priors=priors_rgb, chains=1)


# priors for hsv
h_prior <- b_prior(family="uniform", pars=c(0, 2*pi))
sv_prior <- b_prior(family="uniform", pars=c(0, 1))
kappa_prior <- b_prior(family="uniform", pars=c(0, 500))
sigma_prior <- b_prior(family="uniform", pars=c(0, 1))

# attach priors to relevant parameters
priors_hsv <- list(c("mu_h", h_prior),
                   c("kappa_h", kappa_prior),
                   c("mu_s", sv_prior),
                   c("sigma_s", sigma_prior),
                   c("mu_v", sv_prior),
                   c("sigma_v", sigma_prior))

# generate data (hsv)
h <- rnorm(100, mean=2*pi/3, sd=0.5)
h[h > 2*pi] <- 2*pi
h[h < 0] <- 0

s <- rnorm(100, mean=0.9, sd=0.2)
s[s > 1] <- 1
s[s < 0] <- 0

v <- rnorm(100, mean=0.9, sd=0.2)
v[v > 1] <- 1
v[v < 0] <- 0

colors_hsv <- data.frame(h=h, s=s, v=v)

# fit
fit_hsv <- b_color(colors=colors_hsv, hsv=TRUE, priors=priors_hsv, chains=1)



[Package bayes4psy version 1.2.8 Index]