Title: | Analysis and Visualization Likert Items |
---|---|
Description: | An approach to analyzing Likert response items, with an emphasis on visualizations. The stacked bar plot is the preferred method for presenting Likert results. Tabular results are also implemented along with density plots to assist researchers in determining whether Likert responses can be used quantitatively instead of qualitatively. See the likert(), summary.likert(), and plot.likert() functions to get started. |
Authors: | Jason Bryer [aut, cre] , Kim Speerschneider [ctb] |
Maintainer: | Jason Bryer <[email protected]> |
License: | GPL |
Version: | 2.0.0 |
Built: | 2025-01-12 03:20:08 UTC |
Source: | https://github.com/jbryer/likert |
This will print the absolute value for labeling on axis. Usefull for stacked bar plots where negative values are not negative percentages but represent negative groups.
abs_formatter(x)
abs_formatter(x)
x |
value to be reformatted. |
the absolute value of x.
Adapted from ggExtra package which is no longer available. This is related to an experimental mlpsa plot that will combine the circular plot along with the two individual distributions.
## S3 method for class 'plots' align(gl, ...)
## S3 method for class 'plots' align(gl, ...)
gl |
grid.layout |
... |
graphic elements to combine. |
http://groups.google.com/group/ggplot2/browse_thread/thread/1b859d6b4b441c90 http://ggextra.googlecode.com/svn/trunk/R/align.r
This data set is used in the GapAnalysis
demo and is used to demonstrate
how the likert
package handles a gap analysis.
a data frame with 68 ovservations of 11 variables.
Wrap label text.
label_wrap_mod(value, width = 25)
label_wrap_mod(value, width = 25)
value |
vector (converted using |
width |
the maximum width of each line in characters. Adapted from https://github.com/hadley/ggplot2/wiki/labeller |
This function will provide various statistics about a set of likert items. The resulting object will have the following items:
likert(items, summary, grouping = NULL, factors = NULL, importance, nlevels)
likert(items, summary, grouping = NULL, factors = NULL, importance, nlevels)
items |
data frame containing the likert based items. The variables in the data frame should be factors. |
summary |
a pre-summarized data frame. The first column must be the items and the remaining columns are the levels (e.g. strongly disagree, disagree, etc). |
grouping |
(optional) should the results be summarized by the given grouping variable. |
factors |
a vector with |
importance |
a data frame of the same dimensions as items containing an importance rating for each item. The order of columns should match and the names from items will be used. |
nlevels |
number of possible levels. Only necessary if there are missing levels. |
results
- this data frame will contain a column 'Item', 'Group' (if a
grouping variable was specified, and a column for each level of the
items (e.g. agree, disagree, etc.). The value within each cell corresponds
to the percentage of responses for that level and group.
items
- a copy of the original items data frame.
grouping
- a copy of the original grouping vector.
nlevels
- the number of levels used in the calculations.
a likert class with the following elements: results, items, grouping, nlevels, and summary.
plot.likert
summary.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) summary(l29) plot(l29)
data(pisaitems) items29 <- pisaitems[,substr(names(pisaitems), 1,5) == 'ST25Q'] names(items29) <- c("Magazines", "Comic books", "Fiction", "Non-fiction books", "Newspapers") l29 <- likert(items29) summary(l29) plot(l29)
Bar plot for the results of likert
.
likert.bar.plot(l, group.order, center = (l$nlevels - 1)/2 + 1, ...)
likert.bar.plot(l, group.order, center = (l$nlevels - 1)/2 + 1, ...)
l |
results of |
group.order |
the order in which groups (for grouped items) or items (for non-grouped items) should be plotted. |
center |
specifies which level should be treated as the center. For example,
|
... |
passed to |
likert |
object of type likert. |
plot.likert
likert.heat.plot
likert.bar.plot
likert.density.plot
This funciton will create a visualization that treats the likert items as a continuous variable.
likert.density.plot(likert, facet = TRUE, bw = 0.5, legend, ...)
likert.density.plot(likert, facet = TRUE, bw = 0.5, legend, ...)
likert |
object of type likert. |
facet |
for non-grouped items, should each density distribution be plotted in a separate facet. |
bw |
the smoothing bandwidth. This is often set to the standard deviation but this is often inadequate for Likert type items. The value of 0.5 is used since the difference between any two adjacent levels is one. |
legend |
title for the legend. |
... |
parameters passed to |
plot.likert
Internal method.
likert.heat.plot( likert, low.color = "white", high.color = "blue", text.color = "black", text.size = 4, digits = 2, wrap = 50, ... )
likert.heat.plot( likert, low.color = "white", high.color = "blue", text.color = "black", text.size = 4, digits = 2, wrap = 50, ... )
likert |
object of type likert. |
low.color |
color for low values. |
high.color |
color for high values. |
text.color |
color of text attributes. |
text.size |
size of text attributes. |
digits |
the number of significant digits to print. |
wrap |
width to wrap label text for non-grouped likert objects. |
... |
currently unused. |
plot.likert
likert.bar.plot
Plots a histogram of the number of responses for each item and group (if specified). Negative values (in maroon by default) indicate the number of missing values for that item and group.
likert.histogram.plot( l, xlab = "n", plot.missing = TRUE, bar.color = "grey70", missing.bar.color = "maroon", label.completed = "Completed", label.missing = "Missing", legend.position = "bottom", wrap = ifelse(is.null(l$grouping), 50, 100), order, group.order, panel.arrange = "v", panel.strip.color = "#F0F0F0", text.size = 2.5, ... )
likert.histogram.plot( l, xlab = "n", plot.missing = TRUE, bar.color = "grey70", missing.bar.color = "maroon", label.completed = "Completed", label.missing = "Missing", legend.position = "bottom", wrap = ifelse(is.null(l$grouping), 50, 100), order, group.order, panel.arrange = "v", panel.strip.color = "#F0F0F0", text.size = 2.5, ... )
l |
results of |
xlab |
label used for the x-axis. |
plot.missing |
if TRUE, missing values will be plotted to the left of the x-axis. |
bar.color |
the bar color. |
missing.bar.color |
the color of the bar for missing values. |
label.completed |
the label to use in the legend representing the count of complete values. |
label.missing |
the label to use in the legend representing the count of missing values. |
legend.position |
location of the legend. |
wrap |
number of characters before warping the text in the panel strips. |
order |
the order of the items. |
group.order |
the order in which groups (for grouped items) or items (for non-grouped items) should be plotted. |
panel.arrange |
v for vertical or h for horizontal. |
panel.strip.color |
the color for panels. |
text.size |
text size. |
... |
other ggplot2 parameters. |
Matrix plot (experimental)
likert.matrix.plot(likert, nSample = nrow(likert$items), ...)
likert.matrix.plot(likert, nSample = nrow(likert$items), ...)
likert |
results of |
nSample |
random sample of all rows. This function may take a while
to run with large datasets (including the |
... |
parameters passed to |
likert
results.This function specifies all the plotting options for Likert plots.
likert.options( low.color = "#D8B365", high.color = "#5AB4AC", neutral.color = "grey90", neutral.color.ramp = "white", colors = NULL, plot.percent.low = TRUE, plot.percent.high = TRUE, plot.percent.neutral = TRUE, plot.percents = FALSE, text.size = 3, text.color = "black", centered = TRUE, include.center = TRUE, ordered = TRUE, wrap = 50, wrap.grouping = 50, legend = "Response", ylabel = "Percentage", legend.position = c("bottom", "top", "left", "right", "none"), panel.arrange = "v", panel.strip.color = "#F0F0F0", digits = 2, drop0trailing = FALSE, zero.print = TRUE, ... )
likert.options( low.color = "#D8B365", high.color = "#5AB4AC", neutral.color = "grey90", neutral.color.ramp = "white", colors = NULL, plot.percent.low = TRUE, plot.percent.high = TRUE, plot.percent.neutral = TRUE, plot.percents = FALSE, text.size = 3, text.color = "black", centered = TRUE, include.center = TRUE, ordered = TRUE, wrap = 50, wrap.grouping = 50, legend = "Response", ylabel = "Percentage", legend.position = c("bottom", "top", "left", "right", "none"), panel.arrange = "v", panel.strip.color = "#F0F0F0", digits = 2, drop0trailing = FALSE, zero.print = TRUE, ... )
low.color |
color for low values. |
high.color |
color for high values. |
neutral.color |
color for middle values (if odd number of levels). |
neutral.color.ramp |
second color used when calling |
colors |
vector specifying the colors to use. This must be equal to the number of likert levels. |
plot.percent.low |
whether to plot low percentages. |
plot.percent.high |
whether to plot high percentages. |
plot.percent.neutral |
whether to plot netural percentages. |
plot.percents |
whether to label each category/bar. |
text.size |
size of text attributes. |
text.color |
color of text attributes. |
centered |
if true, the bar plot will be centered around zero such that the lower half of levels will be negative. |
include.center |
if TRUE, include the center level in the plot otherwise the center will be excluded. |
ordered |
reorder items from high to low. |
wrap |
width to wrap label text for item labels |
wrap.grouping |
width to wrap label text for group labels. |
legend |
title for the legend. |
ylabel |
label for the y-axis |
legend.position |
the position for the legend ("left", "right", "bottom", "top", or two-element numeric vector). |
panel.arrange |
how panels for grouped likert items should be arrange.
Possible values are |
panel.strip.color |
the background color for panel labels. |
digits |
the number of significant digits to print. |
drop0trailing |
logical, indicating if trailing zeros, i.e., "0" after the decimal mark, should be removed |
zero.print |
logical, character string or NULL specifying if and how zeros should be formatted specially. |
... |
included for future expansion. |
A data frame of results of the Math Anxiety Scale Survey administered to 20 students in a statistics course. This data frame contains the original data and can be used to verify the pre-summarized procedures.
data frame with 14 rows and 6 columns.
Bai, H., Wang, L., Pan, W., & Frey, M. (2009). Measuring mathematics anxiety: Psychometric analysis of a bidimensional affective scale. Journal of Instructional Psychology, 36 (3), 185- 193.
A data frame of presummarized results of the Math Anxiety Scale Survey administered to 20 students in a statistics course.
data frame with 14 rows and 6 columns.
Bai, H., Wang, L., Pan, W., & Frey, M. (2009). Measuring mathematics anxiety: Psychometric analysis of a bidimensional affective scale. Journal of Instructional Psychology, 36 (3), 185- 193.
A data frame of presummarized results of the Math Anxiety Scale Survey administered to 20 students in a statistics course grouped by gender.
data frame with 28 rows and 7 columns.
Bai, H., Wang, L., Pan, W., & Frey, M. (2009). Measuring mathematics anxiety: Psychometric analysis of a bidimensional affective scale. Journal of Instructional Psychology, 36 (3), 185- 193.
North American (i.e. Canada, Mexico, and United States) results from the 2009 Programme of International Student Assessment (PISA) as provided by the Organization for Economic Co-operation and Development (OECD). See http://www.pisa.oecd.org/ for more information including the code book.
a data frame 66,690 ovservations of 81 variables from North America.
Organization for Economic Co-operation and Development
This is an implementation of the S3 plot generic function. Based upon the
type
parameter this function will call either likert.bar.plot
,
likert.heat.plot
, or likert.density.plot
. See the
help pages for those functions for all the available parameters to customize
the aesthetics of the figure. Although those functions can be plotted directly,
we recommend call the generic plot
function.
## S3 method for class 'likert' plot( x, type = c("bar", "heat", "density"), include.histogram = FALSE, panel.widths = c(3, 1), panel.arrange = "v", panel.strip.color = "#F0F0F0", legend.position = "bottom", group.order, panel.background = element_rect(size = 1, color = "grey70", fill = NA), ... )
## S3 method for class 'likert' plot( x, type = c("bar", "heat", "density"), include.histogram = FALSE, panel.widths = c(3, 1), panel.arrange = "v", panel.strip.color = "#F0F0F0", legend.position = "bottom", group.order, panel.background = element_rect(size = 1, color = "grey70", fill = NA), ... )
x |
the likert items to plot |
type |
the type of plot to create. Current values are bar and heat. |
include.histogram |
if TRUE, a histogram of count of responses is also plotted. |
panel.widths |
if |
panel.arrange |
how panels for grouped likert items should be arrange.
Possible values are |
panel.strip.color |
the background color for panel labels. |
legend.position |
the position for the legend ("left", "right", "bottom", "top", or two-element numeric vector). |
group.order |
the order in which groups (for grouped items) or items (for non-grouped items) should be plotted. |
panel.background |
define background of the plot. See |
... |
other parameters passed passed to |
This is an implementation of the S3 plot generic function. Based upon the
type
parameter this function will call either likert.bar.plot
,
likert.heat.plot
, or likert.density.plot
. See the
help pages for those functions for all the available parameters to customize
the aesthetics of the figure. Although those functions can be plotted directly,
we recommend call the generic plot
function.
## S3 method for class 'likert.gap' plot( x, type = c("bar", "density"), include.histogram = FALSE, panel.widths = c(3, 1), panel.arrange = "v", panel.strip.color = "#F0F0F0", legend.position = "bottom", panel.background = element_rect(size = 1, color = "grey70", fill = NA), satisfaction.label = "Satisfaction", importance.label = "Importance", legend, ... )
## S3 method for class 'likert.gap' plot( x, type = c("bar", "density"), include.histogram = FALSE, panel.widths = c(3, 1), panel.arrange = "v", panel.strip.color = "#F0F0F0", legend.position = "bottom", panel.background = element_rect(size = 1, color = "grey70", fill = NA), satisfaction.label = "Satisfaction", importance.label = "Importance", legend, ... )
x |
the likert items to plot |
type |
the type of plot to create. Current values are bar and heat. |
include.histogram |
if TRUE, a histogram of count of responses is also plotted. |
panel.widths |
if |
panel.arrange |
how panels for grouped likert items should be arrange.
Possible values are |
panel.strip.color |
the background color for panel labels. |
legend.position |
the position for the legend ("left", "right", "bottom", "top", or two-element numeric vector). |
panel.background |
define background of the plot. See |
satisfaction.label |
label used for satisfaction items. |
importance.label |
label used for importance items. |
legend |
title for the legend. |
... |
other parameters passed passed to |
Prints results table.
## S3 method for class 'likert' print(x, ...)
## S3 method for class 'likert' print(x, ...)
x |
the likert class to print. |
... |
parameters passed to |
likert.bar.plot
. The primary purpose is to
suppress the "Stacking not well defined when ymin != 0" warning printed
by ggplot2
for bar plots that have negative bars (i.e. the centered
plots).Print method for likert.bar.plot
. The primary purpose is to
suppress the "Stacking not well defined when ymin != 0" warning printed
by ggplot2
for bar plots that have negative bars (i.e. the centered
plots).
## S3 method for class 'likert.bar.plot' print(x, ...)
## S3 method for class 'likert.bar.plot' print(x, ...)
x |
a plot from |
... |
other parameters passed to ggplot2. |
Prints results table.
## S3 method for class 'likert.gap' print(x, ...)
## S3 method for class 'likert.gap' print(x, ...)
x |
the likert class to print. |
... |
parameters passed to |
likert.heat.plot
.Print method for likert.heat.plot
.
## S3 method for class 'likert.heat.plot' print(p, ...)
## S3 method for class 'likert.heat.plot' print(p, ...)
p |
a plot from |
... |
other parameters passed to ggplot2. |
xtable.likert
.Print method for xtable.likert
.
## S3 method for class 'xlikert' print(x, tabular.environment = "longtable", floating = FALSE, ...)
## S3 method for class 'xlikert' print(x, tabular.environment = "longtable", floating = FALSE, ...)
x |
results of |
tabular.environment |
see |
floating |
see |
... |
other parameters passed to |
This utility function will recode values from an original character
or factor
vector with new values.
recode(x, from, to, to.class = NULL)
recode(x, from, to, to.class = NULL)
x |
the vector whose values will be recoded. |
from |
the old values in x to be recoded. |
to |
the new values. |
to.class |
an 'as.' function representing the desired vector type (i.e. as.character, as.numeric, as.logical, as.numeric). |
a vector with same length of x with recoded values.
test <- letters[sample(5, 10, replace=TRUE)] recode(test, from=letters[1:5], to=paste('Letter', letters[1:5]))
test <- letters[sample(5, 10, replace=TRUE)] recode(test, from=letters[1:5], to=paste('Letter', letters[1:5]))
Reverse the levels of a factor.
reverse.levels(x)
reverse.levels(x)
x |
a factor or a data.frame of factors whose levels will be reverse coded. |
mylevels <- c('Strongly Disagree', 'Disagree', 'Neither', 'Agree', 'Strongly Agree') test <- factor(sample(mylevels[1:5], 10, replace=TRUE)) cbind(test, as.integer(test), as.integer(reverse.levels(test)))
mylevels <- c('Strongly Disagree', 'Disagree', 'Neither', 'Agree', 'Strongly Agree') test <- factor(sample(mylevels[1:5], 10, replace=TRUE)) cbind(test, as.integer(test), as.integer(reverse.levels(test)))
The Survey of Academic Self-Regulation (SASR) is comprised of six factors: self-regulation, intrinsic motivation, extrinsic motivation, self-efficacy, metacognition, and personal relevance and control.
a data frame with 860 ovservations of 63 variables.
Dugan, R., & Andrade, H. (2011). Exploring the construct validity of academic self-regulation using a new self-report questionnaire. The International Journal of Educational and Psychological Assessment, 7(1).
This will start a shiny app included with the package to show many of the features available in the likert package.
shinyLikert()
shinyLikert()
http://rstudio.com/shiny
The summary
function returns a data frame that provides additional
information. It contains 'Item' and 'Group' columns similiar to the results data
frame as well as a column 'low' corresponding to the sum of levels below
neutral, a column 'high' corresponding to the sum of levels above
neutral, and columns 'mean' and 'sd' corresponding to the mean and
standard deviation, respectively, of the results. The numeric values
are determined by as.numeric which will use the values of the factors.
## S3 method for class 'likert' summary(object, center = (object$nlevels - 1)/2 + 1, ordered = TRUE, ...)
## S3 method for class 'likert' summary(object, center = (object$nlevels - 1)/2 + 1, ordered = TRUE, ...)
object |
the likert class to summarize. |
center |
specifies which level should be treated as the center. For example,
|
ordered |
whether the results should be ordered. Currently unsupported for grouped analysis. |
... |
currently unused. |
The summary
function returns a data frame that provides additional
information. It contains 'Item' and 'Group' columns similiar to the results data
frame as well as a column 'low' corresponding to the sum of levels below
neutral, a column 'high' corresponding to the sum of levels above
neutral, and columns 'mean' and 'sd' corresponding to the mean and
standard deviation, respectively, of the results. The numeric values
are determined by as.numeric which will use the values of the factors.
## S3 method for class 'likert.gap' summary(object, ...)
## S3 method for class 'likert.gap' summary(object, ...)
object |
the likert class to summarize. |
... |
parameters passed to |
a list with two data frames with summarized data for satisfaction and importance results separately.
Crate a LaTeX or HTML table of the likert
results.
## S3 method for class 'likert' xtable( x, caption = NULL, label = NULL, align = NULL, digits = NULL, display = NULL, auto = FALSE, include.n = TRUE, include.mean = TRUE, include.sd = TRUE, include.low = TRUE, include.neutral = (x$nlevels%%2 != 0), include.high = TRUE, include.levels = TRUE, include.missing = TRUE, center = (x$nlevels - 1)/2 + 1, ordered = TRUE, ... )
## S3 method for class 'likert' xtable( x, caption = NULL, label = NULL, align = NULL, digits = NULL, display = NULL, auto = FALSE, include.n = TRUE, include.mean = TRUE, include.sd = TRUE, include.low = TRUE, include.neutral = (x$nlevels%%2 != 0), include.high = TRUE, include.levels = TRUE, include.missing = TRUE, center = (x$nlevels - 1)/2 + 1, ordered = TRUE, ... )
x |
likert class object. |
caption |
the table caption. |
label |
the table label. |
align |
column alignments. |
digits |
number of digits to use for numeric columns. |
display |
column formats. |
auto |
Logical, indicating whether to apply automatic format when no
value is passed to align, digits, or display (see |
include.n |
option to include n |
include.mean |
option to include mean |
include.sd |
option to include sd |
include.low |
option to include low |
include.neutral |
option to include neutral |
include.high |
option to include high |
include.levels |
option to include levels |
include.missing |
option to include missing levels. |
center |
specifies which level should be treated as the center. For example,
|
ordered |
whether the results should be ordered. See |
... |
other parameters passed to xtable. |