0

I am using a dataset that has likert scale responses. I am attaching sample observations from the dataset below.

I am always get an error, can someone help me with this?

Thanks

att<-structure(list(att1_goodofall = c(3L, 3L, 1L, 3L, 3L, 3L, 3L, 
2L, 3L, 3L), att2_pvtdisease = c(3L, 3L, 2L, 2L, 3L, 3L, 3L, 
3L, 3L, 3L), att3_curedisease = c(3L, 1L, 3L, 2L, 2L, 1L, 2L, 
3L, 3L, 3L), att4_timewaste = c(4L, 4L, 2L, 3L, 4L, 4L, 4L, 4L, 
4L, 4L), att5_helpgenerations = c(3L, 3L, 3L, 3L, 2L, 3L, 3L, 
2L, 3L, 3L)), row.names = c(NA, 10L), class = "data.frame")


#labelling the values
for(i in att) {                              
  
    val_lab(att)<-make_labels("0 Strongly disagree 
                                          1 Disagree
                                          2 Neither agree or disagree
                                          3 Agree
                                          4 Strongly agree")
}

#plot_likert function
plot_likert(at)

Error in freq[valid] <- counts : 
NAs are not allowed in subscripted assignments

2 Answers2

0

I'm pretty sure that this is a bug but couldn't tell whether it is a bug in expss or in sjPlot.

However, as workaround you could switch to e.g. sjlabelled::set_labels to label your dataset:

library(sjPlot)
library(expss)

att <- sjlabelled::set_labels(att, labels = make_labels("0 Strongly disagree
                                          1 Disagree
                                          2 Neither agree or disagree
                                          3 Agree
                                          4 Strongly agree"))

sjPlot::plot_likert(att, cat.neutral = 3)

stefan
  • 90,330
  • 6
  • 25
  • 51
  • After I applied the solution, I wanted to do the same for another set of variables. I applied the same solution but did not get the desired result. – Mahir Bhatt Dec 07 '22 at 16:50
  • I see. I tried some simpler examples. And as far as I get it, `sjPlot` doesn't like values coded as `0`, sequences with gaps as in your second example (i.e. 0, 1, 9), ... Perhaps I miss something or the docs are not clear about how to use `plot_likert`. – stefan Dec 07 '22 at 18:07
  • thanks for pointing that out. I also do not find a much information on usage of plot_likert function. But thanks – Mahir Bhatt Dec 12 '22 at 09:29
0

After I applied the solution, I wanted to do the same for another set of variables. I applied the same solution but did not get the desired result.

know<-structure(list(know1_spendmoney = c(0L, 9L, 0L, 0L, 0L), know2_access = c(0L, 
0L, 0L, 0L, 9L), know3_medicalrecords = c(0L, 0L, 1L, 1L, 1L), 
    know4_pharmacy = c(0L, 9L, 9L, 9L, 9L), know5_infoprivacy = c(1L, 
    1L, 1L, 1L, 1L), know6_sharing = c(0L, 1L, 1L, 9L, 9L), know7_police = c(0L, 
    9L, 9L, 0L, 1L), know8_infoselling = c(0L, 0L, 9L, 0L, 1L
    ), know9_insurancecompanies = c(0L, 1L, 1L, 1L, 9L), know10_riskofdiseaseinfo = c(1L, 
    1L, 9L, 9L, 9L)), row.names = c(NA, 5L), class = "data.frame")

know<-sjlabelled::set_labels(know, labels = make_labels("0 False
                                          1 True
                                          9 Don't know"))
plot_likert(know,
  expand.grid = TRUE,
  show.prc.sign = TRUE, coord.flip = TRUE, reverse.scale = T, values = "sum.outside")

Warning: number of items to replace is not a multiple of replacement length

Any idea how I can resolve this? I tried multiple options nothing seems to work