jbryer / likert

Package to analyze likert based items.
305 stars 124 forks source link

Grouping and pre-summarised data fails in sample demo/PreSummarized.R. #97

Closed imhogan closed 5 years ago

imhogan commented 5 years ago

Hi, lines 11-12 in demo/PreSummarized.R - see the following excerpts from the console:

> lgmass <- likert(summary=MathAnxietyGender[,2:ncol(MathAnxietyGender)], 
+                grouping=MathAnxietyGender$Group)
seem to cause a problem:
> print(lgmass)
    Group Strongly Disagree  Disagree   Neutral     Agree Strongly Agree
1  Female         14.285714 14.285714 14.285714 35.714286      21.428571

> summary(lgmass)
    Group      Item      low neutral      high     mean        sd
1  Female 14.285714 28.57143       0  57.14286 2.750000 1.0164313

> plot(lgmass)
Error in `$<-.data.frame`(`*tmp*`, "Item", value = list()) : 
  replacement has 0 rows, data has 28

Passing the entire data frame seems to work a bit better:

> lgmass <- likert(summary=MathAnxietyGender, grouping=MathAnxietyGender$Group)
> print(lgmass)
    Group                                                                      Item Strongly Disagree  Disagree   Neutral     Agree Strongly Agree
1  Female                                                  I find math interesting.         14.285714 14.285714 14.285714 35.714286      21.428571
> summary(lgmass)
    Group                                                                      Item       low   neutral      high     mean        sd
1  Female                                                  I find math interesting. 28.571429 14.285714  57.14286 3.357143 1.3489209
> plot(lgmass)
Error in valid.data(rep(units, length.out = length(x)), data) : 
  VECTOR_ELT() can only be applied to a 'list', not a 'character'

A plot is produced but only contains the titles. image

jbryer commented 5 years ago

It seems there are too many items to display on a single plot. This is an issue with ggplot2. You can make the plotting window larger, or try saving the output using the ggsave function with a larger plot size.

On Fri, Oct 26, 2018 at 12:46 AM Ian Hogan notifications@github.com wrote:

Hi, lines 11-12 in demo/PreSummarized.R - see the following excerpts from the console:

lgmass <- likert(summary=MathAnxietyGender[,2:ncol(MathAnxietyGender)],

  • grouping=MathAnxietyGender$Group) seem to cause a problem: print(lgmass) Group Strongly Disagree Disagree Neutral Agree Strongly Agree 1 Female 14.285714 14.285714 14.285714 35.714286 21.428571

summary(lgmass) Group Item low neutral high mean sd 1 Female 14.285714 28.57143 0 57.14286 2.750000 1.0164313

plot(lgmass) Error in $<-.data.frame(*tmp*, "Item", value = list()) : replacement has 0 rows, data has 28


Passing the entire data frame seems to work a bit better:

lgmass <- likert(summary=MathAnxietyGender, grouping=MathAnxietyGender$Group) print(lgmass) Group Item Strongly Disagree Disagree Neutral Agree Strongly Agree 1 Female I find math interesting. 14.285714 14.285714 14.285714 35.714286 21.428571 summary(lgmass) Group Item low neutral high mean sd 1 Female I find math interesting. 28.571429 14.285714 57.14286 3.357143 1.3489209 plot(lgmass) Error in valid.data(rep(units, length.out = length(x)), data) : VECTOR_ELT() can only be applied to a 'list', not a 'character'

A plot is produced but only contains the titles. [image: image] https://user-images.githubusercontent.com/13305325/47545113-36768b00-d936-11e8-8bb5-7fde1ac4269d.png

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jbryer/likert/issues/97, or mute the thread https://github.com/notifications/unsubscribe-auth/AAmEj3h2cqzZV7wENTOdMAfPJwJ5zfbQks5uopOZgaJpZM4X7hnh .

imhogan commented 5 years ago

Hi Jason,  no worries, when I tried plotting less variables then it did work. I am not sure why the pre-sumarised grouping example call fails though. Blessings,Ian Hogan.Mobile: +61 (0) 417 013553Ian MacDonald Hogan IT Services

On Tuesday, 30 October 2018, 2:01:30 am AEDT, Jason Bryer <notifications@github.com> wrote:  

It seems there are too many items to display on a single plot. This is an issue with ggplot2. You can make the plotting window larger, or try saving the output using the ggsave function with a larger plot size.

On Fri, Oct 26, 2018 at 12:46 AM Ian Hogan notifications@github.com wrote:

Hi, lines 11-12 in demo/PreSummarized.R - see the following excerpts from the console:

lgmass <- likert(summary=MathAnxietyGender[,2:ncol(MathAnxietyGender)],

  • grouping=MathAnxietyGender$Group) seem to cause a problem: print(lgmass) Group Strongly Disagree Disagree Neutral Agree Strongly Agree 1 Female 14.285714 14.285714 14.285714 35.714286 21.428571

summary(lgmass) Group Item low neutral high mean sd 1 Female 14.285714 28.57143 0 57.14286 2.750000 1.0164313

plot(lgmass) Error in $<-.data.frame(*tmp*, "Item", value = list()) : replacement has 0 rows, data has 28


Passing the entire data frame seems to work a bit better:

lgmass <- likert(summary=MathAnxietyGender, grouping=MathAnxietyGender$Group) print(lgmass) Group Item Strongly Disagree Disagree Neutral Agree Strongly Agree 1 Female I find math interesting. 14.285714 14.285714 14.285714 35.714286 21.428571 summary(lgmass) Group Item low neutral high mean sd 1 Female I find math interesting. 28.571429 14.285714 57.14286 3.357143 1.3489209 plot(lgmass) Error in valid.data(rep(units, length.out = length(x)), data) : VECTOR_ELT() can only be applied to a 'list', not a 'character'

A plot is produced but only contains the titles. [image: image] https://user-images.githubusercontent.com/13305325/47545113-36768b00-d936-11e8-8bb5-7fde1ac4269d.png

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jbryer/likert/issues/97, or mute the thread https://github.com/notifications/unsubscribe-auth/AAmEj3h2cqzZV7wENTOdMAfPJwJ5zfbQks5uopOZgaJpZM4X7hnh .

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

temospena commented 5 years ago

Hi, Thank you for this package! Maybe you can help me with this issue:

I'm having an issue with the plots. When I plot everything as a whole, following the demo, everything looks ok, although I had to add the as.data.frame for the equivalent of "items29" when calling the likert function.

But then, when I try to group with other variable, from the original dataframe, which has 2 factors, it plots something with 16 levels, instead of 8 (they are repeated, as you can see in the image). image I expanded and I can see all of them.

I'm doing this likAQg <- likert(as.data.frame(items8), grouping=AQslimpos$AFF1) str(likAQg$results) likAQgs <- likert(summary = likAQg$results, grouping = likAQg$results[,1]) str(likAQgs) summary(likAQgs)

the summaries look correct

str(likAQgs) List of 5 $ results :'data.frame': 16 obs. of 7 variables: ..$ Group : Factor w/ 2 levels "Faculty/Staff",..: 1 1 1 1 1 1 1 1 2 2 ... ..$ Item : Factor w/ 8 levels "Bicycle theft insurance",..: 1 2 3 4 5 6 7 8 1 2 ... ..$ Not relevant : num [1:16] 3.79 4.08 18.08 15.16 5.54 ... ..$ 2 : num [1:16] 2.92 4.08 13.99 11.08 2.62 ... ..$ 3 : num [1:16] 9.91 9.62 40.23 40.52 10.5 ... ..$ 4 : num [1:16] 41.1 36.4 10.5 14.9 42 ... ..$ Totally relevant: num [1:16] 42.3 45.8 17.2 18.4 39.4 ... $ items : NULL $ grouping: Factor w/ 2 levels "Faculty/Staff",..: 1 1 1 1 1 1 1 1 2 2 ... $ nlevels : num 5 $ levels : chr [1:5] "Not relevant" "2" "3" "4" ...

  • attr(*, "class")= chr "likert"

summary(likAQgs) Group Item low neutral high 1 Faculty/Staff Bicycle theft insurance 6.705539 9.912536 83.38192 2 Faculty/Staff Personal accident insurance 8.163265 9.620991 82.21574 3 Faculty/Staff Helmet supply 32.069971 40.233236 27.69679 4 Faculty/Staff Shower and dressing room on campus 26.239067 40.524781 33.23615 5 Faculty/Staff E-bike battery charging point on campus 8.163265 10.495627 81.34111 6 Faculty/Staff Bike repair service on campus 5.247813 16.909621 77.84257 7 Faculty/Staff Air pump on campus 11.078717 15.743440 73.17784 8 Faculty/Staff Safety bicycle parking at home place 21.282799 13.994169 64.72303 9 Students Bicycle theft insurance 6.020696 13.170273 80.80903 10 Students Personal accident insurance 13.264346 16.650988 70.08467 11 Students Helmet supply 33.678269 32.079022 34.24271 12 Students Shower and dressing room on campus 33.490122 32.737535 33.77234 13 Students E-bike battery charging point on campus 7.714017 13.358420 78.92756 14 Students Bike repair service on campus 12.229539 20.225776 67.54468 15 Students Air pump on campus 11.476952 16.556914 71.96613 16 Students Safety bicycle parking at home place 18.532455 18.814675 62.65287 mean sd 1 4.206186 0.9235139 2 4.163265 1.0324016 3 2.948980 1.2952924 4 3.091837 1.2688718 5 4.103093 1.0255541 6 4.041237 0.8650328 7 3.845361 1.0639961 8 3.608247 1.2629059 9 4.257732 0.9495432 10 3.938144 1.1255964 11 3.020408 1.3391765 12 3.010309 1.2706203 13 4.132653 1.0318411 14 3.775510 1.0603502 15 3.887755 1.0637674 16 3.670103 1.2223752

but the plot not. What am I doing wrong?

Thank you for your time

temospena commented 5 years ago

I tried also to save in a very large plot, and I noticed that the ones that are repeated (only 5) are the ones where the percentages doesn't fit. Any turnaround? rplot

Even reducing the number of variables, its has the same issue image

temospena commented 5 years ago

Apparently it was an issue with the length of the categories str (max 24?). I shortened up them and it works fine now. The issue was already reported here: https://github.com/jbryer/likert/issues/84#issuecomment-394036478 image