Package 'ridittools'

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

Help Index


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.

Details

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

Author(s)

Eric Bohlman

Maintainer: Eric Bohlman <[email protected]>

References

Fleiss, Joseph L., (1981), Statistical Methods for Rates and Proportions. New York: John Wiley & Sons.

Examples

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)

Vehicle accident injuries

Description

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

Usage

acc

Format

7x2 matrix of counts

Source

Fleiss, pp. 152-153

Examples

acc

Flu subtype by age group

Description

Cross-tabulation of influenza virus subtypes by age group

Usage

flu.age

Format

4x5 matrix of counts; rows are age groups in increasing order, columns are viral subtypes

Source

http://cdc.gov/flu/weekly for week ending 24 Feb 2018

Examples

flu.age

Favorability of handgun ban by party

Description

Likert ratings of American favorability toward a handgun ban, cross-tabulated by political party identification.

Usage

handgun

Format

5x4 matrix of counts; rows are ratings, first column is total responses, remaining columns are Democrats, independents, and Republicans.

Details

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.

Source

YouGov poll of 1500 adult Americans, Feb. 25-27 2018

Examples

handgun

Compute mean ridit of group given reference group

Description

Compute mean ridit for a group given a reference group

Usage

meanridit(v, ref)

Arguments

v

Vector of counts or proportions

ref

Vector of counts or proportions to use as reference group

Value

The group's mean ridit

Author(s)

Eric Bohlman

References

Fleiss, J.,L., (1981), Statistical Methods for Rates and Proportions. New York: John Wiley & Sons., p.153

Examples

# 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)
  }

Compute mean ridits of multiple groups

Description

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.

Usage

meanridits(x, margin, ref = NULL)

Arguments

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

Value

vector of mean ridits

Note

using group totals as reference will not give meaningful results if data are proportions

Author(s)

Eric Bohlman

Examples

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))
  }

Utility to determine reference group. Primarily for internal use/

Description

For internal use.

Usage

riditsrefgroup(x, margin, ref = NULL)

Arguments

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)

Value

vector of counts/proportions to use as reference group

Author(s)

Eric Bohlman

Examples

## 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)
    }
  }

Favorability of semiautomatic weapons ban by party

Description

Likert ratings of American favorability toward a ban on semi-automatic weapons, cross-tabulated by political party identification.

Usage

semiauto

Format

5x4 matrix of counts; rows are ratings, first column is total responses, remaining columns are Democrats, independents, and Republicans.

Details

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.

Source

YouGov poll of 1500 adult Americans, Feb. 25-27 2018

Examples

semiauto

Compute standard error of mean ridit for group given reference group

Description

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.

Usage

seridit(v, ref)

Arguments

v

same as meanridit(), but must be counts

ref

same as meanridit(), but must be counts

Value

standard error of mean ridit

Author(s)

Eric Bohlman

References

Fleiss, J.,L., (1981), Statistical Methods for Rates and Proportions. New York: John Wiley & Sons, p. 154

Examples

# 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)
  }

Compute standard errors of mean ridits of multiple groups

Description

Takes the same data as meanridits(), bui returns standard errors rather than means.

Usage

seridits(x, margin, ref = NULL)

Arguments

x

same as for meanridits(), but must be counts rather than proportions

margin

same as for meanridits()

ref

same as for meanridits()

Details

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

Value

a vector of standard errors for each group's mean ridits

Author(s)

Eric Bohlman

See Also

meanridits

Examples

(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))
  }

Compute standard error of difference between two mean ridits

Description

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.

Usage

seriditdiff(g1, g2)

Arguments

g1

vector of counts (not ridits) for first group

g2

vector of counts (not ridits) for second group

Details

the order of the two groups doesn't matter.

Value

approximate standard error of difference between mean ridits

Author(s)

Eric Bohlman

References

Fleiss, J.,L., (1981), Statistical Methods for Rates and Proportions. New York: John Wiley & Sons., p. 155

Examples

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)))
}

Compute ridit scores for group

Description

Computes the vector of ridit scores corresponding to a vector of counts or proportions.

Usage

toridit(v)

Arguments

v

vector of counts or proportions

Value

vector of ridit scores

Author(s)

Eric Bohlman

References

Fleiss, J.,L., (1981), Statistical Methods for Rates and Proportions. New York: John Wiley & Sons, p. 152

Examples

# 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)
  }