Likert density function

dlikert(x, prob, labels = names(prob))

Arguments

x

the likert distributed vector

prob

a vector of probabilities or counts; if named, the output is a factor

labels

a vector of values, defaults to names(prob) or 1:length(prob), if numeric, the output is numeric

Value

a vector of the densities

Examples

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