Likert density function
dlikert(x, prob, labels = names(prob))
the likert distributed vector
a vector of probabilities or counts; if named, the output is a factor
a vector of values, defaults to names(prob) or 1:length(prob), if numeric, the output is numeric
a vector of the densities
x <- 1:5
prob <- c(.1, .2, .4, .2, .1)
dlikert(x, prob)
#> 1 2 3 4 5
#> 0.1 0.2 0.4 0.2 0.1
x <- c("A", "C", "B", "B")
prob <- c(A = 10, B = 20, C = 30)
dlikert(x, prob)
#> A C B B
#> 0.1666667 0.5000000 0.3333333 0.3333333
# specify labels if prob not named and not 1:length(prob)
labels <- -2:2
x <- sample(labels, 10, replace = TRUE)
prob <- rep(1, length(labels)) # uniform probability
dlikert(x, prob, labels)
#> 2 0 1 -2 -2 0 -1 -2 -1 1
#> 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2