[R] [External] Re: [External] Re: Help please

Richard M. Heiberger rmh @end|ng |rom temp|e@edu
Thu Mar 11 19:48:46 CET 2021


The likert() function in library(likert) is not the same as
the likert() function in library(HH).

The likert function in the likert package creates an object that needs to be plotted.
For the likert package you left out the line
        plot(likert::likert(scrounging))
This plot is not consistent with what your initial email said it was looking for.


Both Jim Lemon and I gave you plots that are consistent with your description.
You could probably get a similar plot from likert::likert(), but not by the lines you are using.
The likert::likert() function does not work with the table that HH::likert() and barplot() are using.
look at str(l29) to see what it needs

The likert package and the HH package cannot be loaded simultaneously.
Their use the same function names in incompatible ways.

How to get the ?likert::likert plot using HH:

HH::likert(t(sapply(items29, table)), as.percent=TRUE, positive.order=TRUE)

Here is a complete example using Jim Lemon's data.



## NO library() statements!
## The likert and HH packages have incompatible usage
## of the same function names.

## this is the example from ?likert::likert
data(pisaitems, package="likert")
items29 <- pisaitems[,substr(names(pisaitems), 1,5) == 'ST25Q']
names(items29) <- c("Magazines", "Comic books", "Fiction",
                    "Non-fiction books", "Newspapers")
## plot using likert package
l29 <- likert::likert(items29)
likert:::plot.likert(l29)


## plot using HH package
HH::likert(t(sapply(items29, table)), as.percent=TRUE,
           positive.order=TRUE, main="HH::likert")

HH::likert(t(sapply(items29, table)), as.percent=TRUE,
           positive.order=TRUE, main="HH::likert",
           auto.key=list(columns=2),
           scales=list(y=list(tck=c(0,2)))) ## prettier



## Jim Lemon's example
scrounging <- data.frame(
  behav=sample(c("inactive","active","foraging","snoozing"),50,TRUE),
  substr=sample(c("tree","ground","vine","air"),50,TRUE))

scroungeTable <- t(table(scrounging))
scroungeTable
HH::likert(scroungeTable)

## I don't think Jim Lemon's example can be used directly in the likert package.
## look at
str(l29)
## and notice that it must include both raw data and the table
l29$results
head(l29$items)


## For any further discussion on this list please include the output from
dput(head(yourRealData))
## in the body of the email.

## Jim's example is based on base graphics barplot
## The HH likert() function is based on lattice barchart.
## the likert package's likert:::plot.likert() function is based on ggplot.


________________________________________
From: R-help <r-help-bounces using r-project.org> on behalf of Rasmus Liland <jral using posteo.no>
Sent: Thursday, March 11, 2021 09:03
To: Areti Panopoulou
Cc: r-help
Subject: [External] Re: [R] [External] Re:  Help please

Dear Areti,

this dcast data.frame presents the same
info as Jim's barplot

        reshape2::dcast(data=scrounging, formula=behav~substr, fun.aggregate=length)

yielding

             behav air ground tree vine
        1   active   5      4    3    3
        2 foraging   2      1    3    4
        3 inactive   0      4    4    5
        4 snoozing   3      5    1    3

I tried to use likert by the example in
the example in ?likert::likert

        library(likert)
        data(pisaitems)
        items29 <- pisaitems[,substr(names(pisaitems), 1,5) == 'ST25Q']
        names(items29) <- c("Magazines", "Comic books", "Fiction",
                           "Non-fiction books", "Newspapers")
        l29 <- likert(items29)
        l29
        lapply(items29, levels)

like this

        u <- unique(scrounging$behav)
        levels.behav <- c("inactive", u[u!="inactive"])
        scrounging$behav <- factor(x=scrounging$behav, levels=levels.behav)
        u <- unique(scrounging$substr)
        levels.substr <- c("ground", u[u!="ground"])
        scrounging$substr <- factor(x=scrounging$substr, levels=levels.substr)
        likert::likert(scrounging)

yielding

            Item inactive active foraging snoozing
        1  behav       36     20       20       24
        2 substr       20     28       30       22

but I doubt this is meaningful ...

Best,
Rasmus



More information about the R-help mailing list