Title: | Useful Functions for Ridit Analysis |
---|---|
Description: | Functions to compute ridit scores of vectors, compute mean ridits and their standard errors for vectors compared to a reference vector, as described in Fleiss (1981, ISBN:0-471-06428-9), and compute means/SEs for multiple groups in matrices. Data can be either counts or proportions. Emphasis is on ridit analysis of ordered categorical data such as Likert items and pain-rating scales. |
Authors: | Eric Bohlman |
Maintainer: | Eric Bohlman <[email protected]> |
License: | GPL-2 | GPL-3 | MIT + file LICENSE |
Version: | 0.1 |
Built: | 2024-11-05 05:27:20 UTC |
Source: | https://github.com/cran/ridittools |
Functions to compute ridit scores of vectors, compute mean ridits and their standard errors for vectors compared to a reference vector, as described in Fleiss (1981, ISBN:0-471-06428-9), and compute means/SEs for multiple groups in matrices. Data can be either counts or proportions. Emphasis is on ridit analysis of ordered categorical data such as Likert items and pain-rating scales.
The DESCRIPTION file:
Package: | ridittools |
Type: | Package |
Title: | Useful Functions for Ridit Analysis |
Version: | 0.1 |
Date: | 2018-03-11 |
Author: | Eric Bohlman |
Maintainer: | Eric Bohlman <[email protected]> |
Description: | Functions to compute ridit scores of vectors, compute mean ridits and their standard errors for vectors compared to a reference vector, as described in Fleiss (1981, ISBN:0-471-06428-9), and compute means/SEs for multiple groups in matrices. Data can be either counts or proportions. Emphasis is on ridit analysis of ordered categorical data such as Likert items and pain-rating scales. |
License: | GPL-2 | GPL-3 | MIT + file LICENSE |
LazyData: | TRUE |
NeedsCompilation: | no |
Packaged: | 2018-03-14 16:26:47 UTC; ebohlman |
Date/Publication: | 2018-03-14 17:25:50 UTC |
Repository: | https://ebohlman.r-universe.dev |
RemoteUrl: | https://github.com/cran/ridittools |
RemoteRef: | HEAD |
RemoteSha: | d2da0f6a16bab9267ca44af94c7f46635d0cb9e9 |
Index of help topics:
acc Vehicle accident injuries flu.age Flu subtype by age group handgun Favorability of handgun ban by party meanridit Compute mean ridit of group given reference group meanridits Compute mean ridits of multiple groups riditsrefgroup Utility to determine reference group. Primarily for internal use/ ridittools-package Useful Functions for Ridit Analysis semiauto Favorability of semiautomatic weapons ban by party seridit Compute standard error of mean ridit for group given reference group seriditdiff Compute standard error of difference between two mean ridits seridits Compute standard errors of mean ridits of multiple groups toridit Compute ridit scores for group
Eric Bohlman
Maintainer: Eric Bohlman <[email protected]>
Fleiss, Joseph L., (1981), Statistical Methods for Rates and Proportions. New York: John Wiley & Sons.
ref <- acc[ , 1] toridit(ref) g <- acc[ , 2] meanridit(g, ref) seridit(g, ref) meanridits(flu.age, 2, "H3") meanridits(flu.age, 2) # Uses group totals as reference seridits(handgun, 2, 1)
ref <- acc[ , 1] toridit(ref) g <- acc[ , 2] meanridit(g, ref) seridit(g, ref) meanridits(flu.age, 2, "H3") meanridits(flu.age, 2) # Uses group totals as reference seridits(handgun, 2, 1)
Counts of motor vehicle accident injuries; rows are ordered by increasing severity First column is total injuries for all drivers; second is injuries to slightly intoxicated drivers
acc
acc
7x2 matrix of counts
Fleiss, pp. 152-153
acc
acc
Cross-tabulation of influenza virus subtypes by age group
flu.age
flu.age
4x5 matrix of counts; rows are age groups in increasing order, columns are viral subtypes
http://cdc.gov/flu/weekly for week ending 24 Feb 2018
flu.age
flu.age
Likert ratings of American favorability toward a handgun ban, cross-tabulated by political party identification.
handgun
handgun
5x4 matrix of counts; rows are ratings, first column is total responses, remaining columns are Democrats, independents, and Republicans.
These data were originally specified as proportions and were derived by multiplication by sample sizes. As such, the first column slightly differs, due to rounding error, from the row sums of the remaining columns.
YouGov poll of 1500 adult Americans, Feb. 25-27 2018
handgun
handgun
Compute mean ridit for a group given a reference group
meanridit(v, ref)
meanridit(v, ref)
v |
Vector of counts or proportions |
ref |
Vector of counts or proportions to use as reference group |
The group's mean ridit
Eric Bohlman
Fleiss, J.,L., (1981), Statistical Methods for Rates and Proportions. New York: John Wiley & Sons., p.153
# PolitiFact ratings in order of increasing truthfulness (8 Mar 2018) obama <- c(9, 71, 70, 161, 165, 123) trump <- c(77, 169, 114, 78, 60, 24) # Probability that a random Trump statement is at least as truthful as a random Obama statement meanridit(trump, obama) ## The function is currently defined as function (v, ref) { sum(to.ridit(ref) * v)/sum(v) }
# PolitiFact ratings in order of increasing truthfulness (8 Mar 2018) obama <- c(9, 71, 70, 161, 165, 123) trump <- c(77, 169, 114, 78, 60, 24) # Probability that a random Trump statement is at least as truthful as a random Obama statement meanridit(trump, obama) ## The function is currently defined as function (v, ref) { sum(to.ridit(ref) * v)/sum(v) }
Computes mean ridits of multiple groups in a crosstab matrix. Groups can be either rows or columns, with the other dimension representing the response categories.
meanridits(x, margin, ref = NULL)
meanridits(x, margin, ref = NULL)
x |
matrix of cross-tabulated counts or proportions |
margin |
1 for groups in rows, 2 for groups in columns |
ref |
if omitted, use totals across groups as reference group if vector of counts (or proportions), use as reference group otherwise, number (or name if it exists) of group to use as reference |
vector of mean ridits
using group totals as reference will not give meaningful results if data are proportions
Eric Bohlman
meanridits(flu.age, 2) meanridits(flu.age, 2, "H3") meanridits(handgun, 2, 1) meanridits(handgun, 2, rowSums(handgun[ , 2:4])) ## The function is currently defined as function (x, margin, ref = NULL) { apply(x, margin, meanridit, riditsrefgroup(x, margin, ref)) }
meanridits(flu.age, 2) meanridits(flu.age, 2, "H3") meanridits(handgun, 2, 1) meanridits(handgun, 2, rowSums(handgun[ , 2:4])) ## The function is currently defined as function (x, margin, ref = NULL) { apply(x, margin, meanridit, riditsrefgroup(x, margin, ref)) }
For internal use.
riditsrefgroup(x, margin, ref = NULL)
riditsrefgroup(x, margin, ref = NULL)
x |
matrix of counts or proportions |
margin |
margin that represents groups. 1 for rows, 2 for columns |
ref |
group to use as reference. if omitted, use totals across groups. if a vector, use it. otherwise use the group with its number (or name if available) |
vector of counts/proportions to use as reference group
Eric Bohlman
## The function is currently defined as function (x, margin, ref = NULL) { if (length(ref) > 1) { refgroup <- ref } else if (length(ref) == 1) { if (margin == 1) { refgroup <- x[ref, ] } else { refgroup <- x[, ref] } } else { refgroup <- apply(x, 3 - margin, sum) } }
## The function is currently defined as function (x, margin, ref = NULL) { if (length(ref) > 1) { refgroup <- ref } else if (length(ref) == 1) { if (margin == 1) { refgroup <- x[ref, ] } else { refgroup <- x[, ref] } } else { refgroup <- apply(x, 3 - margin, sum) } }
Likert ratings of American favorability toward a ban on semi-automatic weapons, cross-tabulated by political party identification.
semiauto
semiauto
5x4 matrix of counts; rows are ratings, first column is total responses, remaining columns are Democrats, independents, and Republicans.
These data were originally specified as proportions and were derived by multiplication by sample sizes. As such, the first column slightly differs, due to rounding error, from the row sums of the remaining columns.
YouGov poll of 1500 adult Americans, Feb. 25-27 2018
semiauto
semiauto
Given a vector of counts for a group and a vector of counts for a reference group, computes the standard error of the mean ridit for the group.
seridit(v, ref)
seridit(v, ref)
v |
same as |
ref |
same as |
standard error of mean ridit
Eric Bohlman
Fleiss, J.,L., (1981), Statistical Methods for Rates and Proportions. New York: John Wiley & Sons, p. 154
# PolitiFact ratings in order of increasing truthfulness (8 Mar 2018) obama <- c(9, 71, 70, 161, 165, 123) trump <- c(77, 169, 114, 78, 60, 24) # Result is approximately standard normal (meanridit(trump, obama) - 0.5) / seridit(trump, obama) ## The function is currently defined as function (v, ref) { N <- sum(ref) n <- sum(v) term1 <- (n + 1)/N term2 <- 1/(N * (N + n - 1)) term3 <- sum((ref + v)^3)/(N * (N + n) * (N + n - 1)) (1/(2 * sqrt(3 * n))) * sqrt(1 + term1 + term2 - term3) }
# PolitiFact ratings in order of increasing truthfulness (8 Mar 2018) obama <- c(9, 71, 70, 161, 165, 123) trump <- c(77, 169, 114, 78, 60, 24) # Result is approximately standard normal (meanridit(trump, obama) - 0.5) / seridit(trump, obama) ## The function is currently defined as function (v, ref) { N <- sum(ref) n <- sum(v) term1 <- (n + 1)/N term2 <- 1/(N * (N + n - 1)) term3 <- sum((ref + v)^3)/(N * (N + n) * (N + n - 1)) (1/(2 * sqrt(3 * n))) * sqrt(1 + term1 + term2 - term3) }
Takes the same data as meanridits()
, bui returns standard errors rather than means.
seridits(x, margin, ref = NULL)
seridits(x, margin, ref = NULL)
x |
same as for |
margin |
same as for |
ref |
same as for |
note that if the results include the reference group, its standard error will not be meaningful; by definition its mean ridit will be exactly 0.5
a vector of standard errors for each group's mean ridits
Eric Bohlman
(meanridits(semiauto, 2, 1) - 0.5) / seridits(semiauto, 2, 1) ## The function is currently defined as function (x, margin, ref = NULL) { apply(x, margin, se.ridit, riditsrefgroup(x, margin, ref)) }
(meanridits(semiauto, 2, 1) - 0.5) / seridits(semiauto, 2, 1) ## The function is currently defined as function (x, margin, ref = NULL) { apply(x, margin, se.ridit, riditsrefgroup(x, margin, ref)) }
Computes the approximate standard error of the difference between the mean ridits of two groups. This does not depend on the reference group the mean ridits are relative to, only on the sizes of the two groups.
seriditdiff(g1, g2)
seriditdiff(g1, g2)
g1 |
vector of counts (not ridits) for first group |
g2 |
vector of counts (not ridits) for second group |
the order of the two groups doesn't matter.
approximate standard error of difference between mean ridits
Eric Bohlman
Fleiss, J.,L., (1981), Statistical Methods for Rates and Proportions. New York: John Wiley & Sons., p. 155
seriditdiff(semiauto[ , "Ind"], semiauto[ , "Rep"]) ## The function is currently defined as function(g1, g2) { sqrt(sum(g1) + sum(g2)) / (2 * sqrt(3 * sum(g1) * sum(g2))) }
seriditdiff(semiauto[ , "Ind"], semiauto[ , "Rep"]) ## The function is currently defined as function(g1, g2) { sqrt(sum(g1) + sum(g2)) / (2 * sqrt(3 * sum(g1) * sum(g2))) }
Computes the vector of ridit scores corresponding to a vector of counts or proportions.
toridit(v)
toridit(v)
v |
vector of counts or proportions |
vector of ridit scores
Eric Bohlman
Fleiss, J.,L., (1981), Statistical Methods for Rates and Proportions. New York: John Wiley & Sons, p. 152
# PolitiFact ratings for Barack Obama in order of increasing truthfulness (8 Mar 2018) toridit(c(9, 71, 70, 161, 165, 123)) # counts toridit(c(.02, .12, .12, .27, .28, .21)) # proportions ## The function is currently defined as function (v) { (cumsum(v) - 0.5 * v)/sum(v) }
# PolitiFact ratings for Barack Obama in order of increasing truthfulness (8 Mar 2018) toridit(c(9, 71, 70, 161, 165, 123)) # counts toridit(c(.02, .12, .12, .27, .28, .21)) # proportions ## The function is currently defined as function (v) { (cumsum(v) - 0.5 * v)/sum(v) }