| Title: | Fit Models to Two-Way Tables with Correlated Ordered Response Categories |
|---|---|
| Description: | Fit a variety of models to two-way tables with ordered categories. Most of the models are appropriate to apply to tables of that have correlated ordered response categories. There is a particular interest in rater data and models for rescore tables. Some utility functions (e.g., Cohen's kappa and weighted kappa) support more general work on rater agreement. Because the names of the models are very similar, the functions that implement them are organized by last name of the primary author of the article or book that suggested the model, with the name of the function beginning with that author's name and an underscore. This may make some models more difficult to locate if one doesn't have the original sources. The vignettes and tests can help to locate models of interest. For more dertaiils see the following references: Agresti, A. (1983) <doi:10.1016/0167-7152(83)90051-2> "A Simple Diagonals-Parameter Symmetry And Quasi-Symmetry Model", Agrestim A. (1983) <doi:10.2307/2531022> "Testing Marginal Homogeneity for Ordinal Categorical Variables", Agresti, A. (1988) <doi:10.2307/2531866> "A Model For Agreement Between Ratings On An Ordinal Scale", Agresti, A. (1989) <doi:10.1016/0167-7152(89)90104-1> "An Agreement Model With Kappa As Parameter", Agresti, A. (2010 ISBN:978-0470082898) "Analysis Of Ordinal Categorical Data", Bhapkar, V. P. (1966) <doi:10.1080/01621459.1966.10502021> "A Note On The Equivalence Of Two Test Criteria For Hypotheses In Categorical Data", Bhapkar, V. P. (1979) <doi:10.2307/2530344> "On Tests Of Marginal Symmetry And Quasi-Symmetry In Two And Three-Dimensional Contingency Tables", Bowker, A. H. (1948) <doi:10.2307/2280710> "A Test For Symmetry In Contingency Tables", Clayton, D. G. (1974) <doi:10.2307/2335638> "Some Odds Ratio Statistics For The Analysis Of Ordered Categorical Data", Cliff, N. (1993) <doi:10.1037/0033-2909.114.3.494> "Dominance Statistics: Ordinal Analyses To Answer Ordinal Questions", Cliff, N. (1996 ISBN:978-0805813333) "Ordinal Methods For Behavioral Data Analysis", Goodman, L. A. (1979) <doi:10.1080/01621459.1979.10481650> "Simple Models For The Analysis Of Association In Cross-Classifications Having Ordered Categories", Goodman, L. A. (1979) <doi:10.2307/2335159> "Multiplicative Models For Square Contingency Tables With Ordered Categories", Ireland, C. T., Ku, H. H., & Kullback, S. (1969) <doi:10.2307/2286071> "Symmetry And Marginal Homogeneity Of An r × r Contingency Table", Ishi-kuntz, M. (1994 ISBN:978-0803943766) "Ordinal Log-linear Models", McCullah, P. (1977) <doi:10.2307/2345320> "A Logistic Model For Paired Comparisons With Ordered Categorical Data", McCullagh, P. (1978) <doi:10.2307/2335224> A Class Of Parametric Models For The Analysis Of Square Contingency Tables With Ordered Categories", McCullagh, P. (1980) <doi:10.1111/j.2517-6161.1980.tb01109.x> "Regression Models For Ordinal Data", Penn State: Eberly College of Science (undated) <https://online.stat.psu.edu/stat504/lesson/11> "Stat 504: Analysis of Discrete Data, 11. Advanced Topics I", Schuster, C. (2001) <doi:10.3102/10769986026003331> "Kappa As A Parameter Of A Symmetry Model For Rater Agreement", Shoukri, M. M. (2004 ISBN:978-1584883210). "Measures Of Interobserver Agreement", Stuart, A. (1953) <doi:10.2307/2333101> "The Estimation Of And Comparison Of Strengths Of Association In Contingency Tables", Stuart, A. (1955) <doi:10.2307/2333387> "A Test For Homogeneity Of The Marginal Distributions In A Two-Way Classification", von Eye, A., & Mun, E. Y. (2005 ISBN:978-0805849677) "Analyzing Rater Agreement: Manifest Variable Methods". |
| Authors: | John R. Donoghue [aut, cre] |
| Maintainer: | John R. Donoghue <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.0.0.3 |
| Built: | 2026-05-16 07:31:08 UTC |
| Source: | https://github.com/cran/ordinalTables |
Solves equation Agresti_f() = 0 for delta by method of bisection..
Agresti_bisection(p, pi_margin, x_low = 0, x_high = 1)Agresti_bisection(p, pi_margin, x_low = 0, x_high = 1)
p |
matrix of observed proportions |
pi_margin |
current value of (row and column) marginal proportion |
x_low |
lower bound for search. Default value is 0.0 |
x_high |
upper bound for search. Default value is 1.0 |
value of kappa that makes the function 0.0
Computes value of lambda parameter
Agresti_compute_lambda(p, pi)Agresti_compute_lambda(p, pi)
p |
matrix of observed proportions |
pi |
matrix of model-supplied proportions |
value of the lambda parameter
Computes the matrix pi of model-based proportions
Agresti_compute_pi(pi_margin, kappa)Agresti_compute_pi(pi_margin, kappa)
pi_margin |
current value of (row and column) marginal proportion |
kappa |
current estimate of kappa coefficient |
matrix of model-based proportions
This parameterization does not match equation (2.2) in the paper, but it yields results that are identical to those in the paper. Agresti, A. (1983), A simple diagonals-parameter symmetry and quasi-symmetry model. Statistics and Probability Letters I, 313-316.
Agresti_create_design_matrix(n_dim)Agresti_create_design_matrix(n_dim)
n_dim |
the size of the date matrix |
the design matrix for the model, that can bee used with ml_for_log_linear
First equation in section 3. Solved for kappa.
Agresti_equation_1(p, pi_margin, kappa)Agresti_equation_1(p, pi_margin, kappa)
p |
matrix of observed proportions |
pi_margin |
current value of (row and column) marginal proportion |
kappa |
current value of coefficient kappa |
Second equation in section 3. Solved for pi_margin.
Agresti_equation_2(p, pi_margin, lambda, kappa)Agresti_equation_2(p, pi_margin, lambda, kappa)
p |
matrix of observed proportions |
pi_margin |
current value of (row and column) marginal proportion |
lambda |
value of quantity lambda defined in third equation |
kappa |
current value of coefficient kappa |
Third equation in section 3. Solved for lambda
Agresti_equation_3(p, pi_margin, kappa)Agresti_equation_3(p, pi_margin, kappa)
p |
matrix of observed proportions |
pi_margin |
current value of (row and column) marginal proportion |
kappa |
current valye of coefficient kappa |
Extracts the quasi-symmetry information from the result provided.
Agresti_extract_delta(result)Agresti_extract_delta(result)
result |
result of call to log_linear_fit() |
list consisting of beta: the beta coefficient se: the standard error of beta z: the ratio beta / se delta: the delta coefficient = exp(2.0 * beta)
Used by Agresti_bisection()
Agresti_f(p, pi_margin, kappa)Agresti_f(p, pi_margin, kappa)
p |
matrix of observed proportions |
pi_margin |
current value of (row and column) marginal proportion |
kappa |
current estimate of kappa coefficient |
Agresti, A. (1989). An agreement model with kappa as a parameter. Statistics and Probability Letters, 7, 271-273.
Agresti_kappa_agreement(n, verbose = FALSE)Agresti_kappa_agreement(n, verbose = FALSE)
n |
matrix of observed counts |
verbose |
should cycle-by-cycle info be printed as messages? The default is FALSE. |
a list containing kappa: value of kappa coefficient pi_margin: value of marginal p-values. They apply to rows and columns chisq: Pearson X^2 df: degrees of freedom expected: fitted frequencies
This parameterization does not match equation (2.2) in the paper, but it yields results that are identical to those in the paper. Agresti, A. (1983), A simple diagonals-parameter symmetry and quasi-symmetry model. Statistics and Probability Letters I, 313-316.
Agresti_simple_diagonals_parameter_quasi_symmetry(n)Agresti_simple_diagonals_parameter_quasi_symmetry(n)
n |
the matrix of observed counts |
a list containing expected: matrix of expected cell frequencies, chisq: Pearson X^2 g_squared: likelihood ratio G^2 df: degrees of freedom beta: the parameter estimated sigma_beta: standard error of beta z: z-score for beta delta: transformation of the the parameter into the model formulation
Agresti_simple_diagonals_parameter_quasi_symmetry(vision_data)Agresti_simple_diagonals_parameter_quasi_symmetry(vision_data)
Computes staring values for marginal pi.
Agresti_starting_values(p)Agresti_starting_values(p)
p |
matrix of observed proportions |
vector containing pi
Computes weighted contrast of the two margins. Agresti, A. (1983). Testing marginal homogeneity for ordinal categorical variables. Biometrics, 39(2), 505-510.
Agresti_w_diff(w, n)Agresti_w_diff(w, n)
w |
a vector of weights to be treated as scores |
n |
matrix of observed counts |
a list containing diff: the weighted contrast computed using weights w sigma_diff: SE(diff) z_diff: z-score for diff
weights = c(-3.0, -1.0, 1.0, 3.0) Agresti_w_diff(weights, vision_data)weights = c(-3.0, -1.0, 1.0, 3.0) Agresti_w_diff(weights, vision_data)
Computes weighted tau from Section 2.1. Agresti, A. (1983). Testing marginal homogeneity for ordinal categorical variables. Biometrics, 39(2), 505-510.
Agresti_weighted_tau(n)Agresti_weighted_tau(n)
n |
matrix of observed counts |
a list containing tau: value of tau-d coefficient sigma_tau: SE(tau) z_tau: z-score for tau
Fits the marginal homogeneity model using WLS.
Bhapkar_marginal_homogeneity(n)Bhapkar_marginal_homogeneity(n)
n |
matrix containing the table to analyze |
See: Bhapkar, V. P. (1966). A Note on the Equivalence of Two Test Criteria for Hypotheses in Categorical Data. Journal of the American Statistical Association, 61(313), pp.228-235.
a list containing the chi-square statistic, the df and p-value.
Bhapkar_marginal_homogeneity(vision_data)Bhapkar_marginal_homogeneity(vision_data)
Fits the quasi-symmetry model using WLS. Bhapkar, V. P. (1979). On tests of marginal symmetry and quasi-symmetry in two and three-dimensional contingency tables. Biometrics 35(2), 417-426.
Bhapkar_quasi_symmetry(n)Bhapkar_quasi_symmetry(n)
n |
the matrix to be analyzed |
a list containing the chi-square and df.
Bhapkar_quasi_symmetry(vision_data)Bhapkar_quasi_symmetry(vision_data)
Computes the test of table symmetry in Bowker (1948). Bowker, A. H. (1948). A test for symmetry in contingency tables. Journal of the American Statistical Association 43, 572-574.
Bowker_symmetry(n)Bowker_symmetry(n)
n |
the matrix to be tested for symmetry |
a list containing the chi-square: Pearson X^2 g_square: likelihood ratio G^2 df: degrees of freedom p-value: p-value for Pearson X^2 expected: fitted values
Bowker_symmetry(vision_data)Bowker_symmetry(vision_data)
Participation in household budgeting by psychiatric patients. Rows are ratings by patient, columns are ratings by relative. 1 - not at all 2 - doing some 3 - doing regularly
budget_actualbudget_actual
## 'budget_actual' A matrix with 3 rows and 3 columns
Schuster, C, (2001). Kappa as a parameter of a symmetry model for rater agreement. Journal of Educational and Behavioral Statistics, 26(3), 331-342.
Ratings of expected participation in household budgeting by psychiatric patients. Rows are ratings by patient, columns are ratings by relative. 1 - not at all 2 - doing some 3 - doing regularly
budget_expectedbudget_expected
## 'budget_expected' a matrix with 3 rows and 3 columns.
Schuster, C, (2001). Kappa as a parameter of a symmetry model for rater agreement. Journal of Educational and Behavioral Statistics, 26(3), 331-342.
The measure is based on the weighted cdfs. No "scores" are used, just the weighted (cumulative sums). Clayton, D. G. (1974) Odds ratio statistics for the analysis of ordered categorical data. Biometrika, 61(3), 525-531.
Clayton_marginal_location(wx, wy)Clayton_marginal_location(wx, wy)
wx |
vector containing frequencies for the first margin of the table |
wy |
vector containing frequencies for the second margin of the table |
a list of results odds_ratios: odds ratios comparing cumulative frequencies of adjacent categories log_theta_hat: log of estimate of the common odds-ratio theta_hat: estimate of the common odds-ratio log_mh_theta_hat: log of the Mantel-Haenssel type odds-ratio mh_theta_hat: Mantel-Haenszel type odds-ratio var_log_theta_hat = variance of the log of the odds-ratios chisq_theta_hat: chi-square for odds-ratio chisq_mh_theta_hat: chi-square for Mantel-Haenszel odds-ratio df: degrees of freedom for chis-square = 1
Clayton_marginal_location(tonsils[1,], tonsils[2,])Clayton_marginal_location(tonsils[1,], tonsils[2,])
Compares marginal location conditional on a stratifying variable. Clayton, D. G. (1974) Odds ratio statistics for the analysis of ordered categorical data. Biometrika, 61(3), 525-531.
Clayton_stratified_marginal_location(mx, my)Clayton_stratified_marginal_location(mx, my)
mx |
matrix with |
my |
matrix with |
a list of results odds_ratios: odds ratios comparing cumulative frequencies of adjacent categories log_theta_hat: log of estimate of the common odds-ratio theta_hat: estimate of the common odds-ratio log_mh_theta_hat: log of the Mantel-Haenssel type odds-ratio mh_theta_hat: Mantel-Haenszel type odds-ratio var_log_theta_hat = variance of the log of the odds-ratios chisq_theta_hat: chi-square for odds-ratio chisq_mh_theta_hat: chi-square for Mantel-Haenszel odds-ratio df: degrees of freedom for chis-square = 1
[Clayton_marginal_location()]
Computes summary, cumulative proportions up to index provided
Clayton_summarize(weights, m)Clayton_summarize(weights, m)
weights |
matrix of counts |
m |
index of summation, weights[1:m] |
a list containing: n: the sum of the weights p: matrix of proportion values gamma: cumulative proportions 1:m
Analysis stratified by column variable j.
Clayton_summarize_stratified(weight_matrix, m)Clayton_summarize_stratified(weight_matrix, m)
weight_matrix |
matrix of cell weights from the table |
m |
the column index to stratify on |
a list containing: n: the number of strata p: matrix of proportion values gamma: cumulative proportions
[Clayton_summarize()]
Quantifies association between two ordinal variables. Clayton, D. G. (1974) Odds ratio statistics for the analysis of oordered categorical data. Biometrika, 61(3), 525-531.
Clayton_two_way_association(f)Clayton_two_way_association(f)
f |
matrix of frequencies |
a list of results log_theta_hat: log odds-ratio measure of association theta_hat: odds-ratio measure of association log_mh_theta_hat: log of Mantel-Haenszel odds-ratio measure of association mh_theta_hat: Mantel-Haenszel odds-ratio measure of association var_log_theta_hat: variance of the log odds-ration measures chisq_theta_hat: chi-square for measure of association chisq_mh_theta_hat: chi-square for Mantel-Haenszel measure of association df: degress of freedom = 1, corr_theta_hat: theta-hat association converted to correlation metric corr_mh_theta_hat: Mantel-Haenszel theta-hat converted to correlation metric
Converts two vectors containing scores and integer frequencies (cell counts) into a d-matrix
Cliff_as_d_matrix(scores, cells, nrow = NULL)Cliff_as_d_matrix(scores, cells, nrow = NULL)
scores |
vector of scores, typically 1:r |
cells |
vector of integer weights, i.e. cell frequencies |
nrow |
number of score categories in table. Default is NULL. If NULL, takes 1:length(scores) |
d-matrix of results
Computes between groups dominance matrix "d".
Cliff_compute_d(x, y)Cliff_compute_d(x, y)
x |
first vector of scores |
y |
second vector of scores |
N X N dominance matrix
Generates counts from table frequencies for 2 category items
Cliff_counts_2(mij)Cliff_counts_2(mij)
mij |
Matrix of counts. |
a list containing wm1m1: for -1, -1 wm10: for -1, 0 wm11: for -1, 1 w00: for 0, 0 w01: for 0, 1 w11: for 1, 1
Generates counts from table frequencies for 3 category items
Cliff_counts_3(mij)Cliff_counts_3(mij)
mij |
Matrix of counts. |
a list containing wm1m1: for -1, -1 wm10: for -1, 0 wm11: for -1, 1 w00: for 0, 0 w01: for 0, 1 w11: for 1, 1
Generates counts from table frequencies for 4 category items
Cliff_counts_4(mij)Cliff_counts_4(mij)
mij |
Matrix of counts. |
a list containing wm1m1: for -1, -1 wm10: for -1, 0 wm11: for -1, 1 w00: for 0, 0 w01: for 0, 1 w11: for 1, 1
Generates counts from table frequencies for 5 category items
Cliff_counts_5(mij)Cliff_counts_5(mij)
mij |
Matrix of counts. |
a list containing wm1m1: for -1, -1 wm10: for -1, 0 wm11: for -1, 1 w00: for 0, 0 w01: for 0, 1 w11: for 1, 1
Generates counts from table frequencies for 6 category items
Cliff_counts_6(mij)Cliff_counts_6(mij)
mij |
Matrix of counts. |
a list containing wm1m1: for -1, -1 wm10: for -1, 0 wm11: for -1, 1 w00: for 0, 0 w01: for 0, 1 w11: for 1, 1
Takes the dominance matrix provided and computes the d-statistics: dw - within-subjects d-statistic db - between-subjects d-statistic db_dw - sum of dw and db, omnibus test of whether one group is higher than the other Cliff, N. (1993). Dominance statistics: Ordinal analyses to answer ordinal questions. Psychological Bulletin, 114(3), 494-509. Cliff, N. (1996). Ordinal methods for behavioral data analysis. Mawhaw NJ: Lawerence Erlbaum.
Cliff_dependent(d_matrix)Cliff_dependent(d_matrix)
d_matrix |
N x N within-subjects dominance matrix |
a list containing dw: within-subjects d-statistic sigma_dw: SE of dw z_dw: z-score for dw db: between-subjects d-statistic sigma_db: SE of db z_db: z-score for db db_dw: sum db + dw, omnibus measure sigma_db_dw: SE of db + dw z_db_dw: z-score of db _ dw cov_db_dw: covariance between db and dw
Cliff_dependent(interference_control_1)Cliff_dependent(interference_control_1)
Computes sum term in covariance db-dw for weighted dominance matrix.
Cliff_dependent_compute_cov(wd)Cliff_dependent_compute_cov(wd)
wd |
weighted dominance matrix |
Compute the sum in the covariance of db+dw
Cliff_dependent_compute_cov_from_d(d_matrix)Cliff_dependent_compute_cov_from_d(d_matrix)
d_matrix |
d-matrix of dominances |
the sum for the covariance term
Takes the dominance matrix provided and computes the d-statistics: dw - within-subjects d-statistic db - between-subjects d-statistic db_dw - sum of db and dw, omnibus test of whether one group is higher than the other Cliff, N. (1993). Dominance statistics: Ordinal analyses to answer ordinal questions. Psychological Bulletin, 114(3), 494-509. Cliff, N. (1996). Ordinal methods for behavioral data analysis. Mawhaw NJ: Lawerence-Erlbaum.
Cliff_dependent_compute_from_matrix(d_matrix)Cliff_dependent_compute_from_matrix(d_matrix)
d_matrix |
N x N within-subjects dominance matrix |
a list containing dw: within-subjects d-statistic sigma_dw: SE of dw z_dw: z-score for dw db: between-susbjects d-statistic sigma_db: SE of db z_db: z-score for db db_dw: sum db + dw, omnibus measure sigma_db_dw: SE of db + dw z_db_dw: z-score of db _ dw cov_db_dw: covariance between db and dw
Cliff_dependent_compute_from_matrix(interference_control_1)Cliff_dependent_compute_from_matrix(interference_control_1)
Takes the r X r table and returns: dw - within-subjects d-statistic db - between-subjects d-statistic db_dw - sum of dw and db, omnibus test of whether one group is higher than the other No intermediate dominance matrix is computed, so this is much faster than Cliff_dependent_compute_from_matrix(). Large number of terms are needed to compute intermediate d_ij_ji. These are contained in separate functions for r <= 6. Results for r [7, 10] are available, but the files are so large that they cause an error if included in the library.
Cliff_dependent_compute_from_table(mij)Cliff_dependent_compute_from_table(mij)
mij |
an r x r table of paired observations |
See: Cliff, N. (1993). Dominance statistics: Ordinal analyses to answer ordinal questions. Psychological Bulletin, 114(3), 494-509. Cliff, N. (1996). Ordinal methods for behavioral data analysis. Mawhaw NJ: Lawerence-Erlbaum.
a list containing dw: within-subjects d-statistic sigma_dw: SE of dw z_dw: z-score for dw db: between-susbjects d-statistic sigma_db: SE of db z_db: z-score for db db_dw: sum db + dw, omnibus measure sigma_db_dw: SE of db + dw z_db_dw: z-score of db _ dw cov_db_dw: covariance between db and dw
[Cliff_dependent_compute_paired_d()]
Cliff_dependent_compute_from_table(movies)Cliff_dependent_compute_from_table(movies)
Computes d-matrix and then analyzes it. This can be time consuming. Try Cliff_dependent_from_table() instead. The current function is provided mainly for comparison & validation. For an example, compare running this function on vision_data to running Cliff_dependent_from_table(vision_data).
Cliff_dependent_compute_paired_d(cells)Cliff_dependent_compute_paired_d(cells)
cells |
r x r matrix of frequencies |
dw - within-subjects d-statistic db - between-subjects d-statistic db_dw - sum of dw and db, omnibus test of whether one group is higher than the other Cliff, N. (1993). Dominance statistics: Ordinal analyses to answer ordinal questions. Psychological Bulletin, 114(3), 494-509. Cliff, N. (1996). Ordinal methods for behavioral data analysis. Mawhaw NJ: Lawerence-Erlbaum.
a list containing dw: within-subjects d-statistic sigma_dw: SE of dw z_dw: z-score for dw db: between-subjects d-statistic sigma_db: SE of db z_db: z-score for db db_dw: sum db + dw, omnibus measure sigma_db_dw: SE of db + dw z_db_dw: z-score of db _ dw cov_db_dw: covariance between db and dw
[Cliff_dependent_compute_from_table()]
Cliff_dependent_compute_paired_d(movies)Cliff_dependent_compute_paired_d(movies)
Computes the independent groups d-statistic comparing the two vectors provided.
Cliff_independent(x, y)Cliff_independent(x, y)
x |
vector of scores for first group |
y |
vector of scores for second group |
list containing d, SE(d) and z(d)
Computes d-statistic from dominance matrix provided.
Cliff_independent_from_matrix(d)Cliff_independent_from_matrix(d)
d |
N X M dominance matrix |
list containing d, SE(d) and z(d)
Computes intermediate d-matrix, so can be slow for large N
Cliff_independent_from_table(n)Cliff_independent_from_table(n)
n |
matrix of counts |
list containing d, SE(d) and z(d)
Computes d-statistic based on scores and integer weights(frequencies) for each group.
Cliff_independent_weighted(x, w_x, y, w_y)Cliff_independent_weighted(x, w_x, y, w_y)
x |
first vector of scores |
w_x |
weights associated with first vector of scores |
y |
second vector of scores |
w_y |
weights associated with second vector of scores |
list containing d, SE(d) and z(d)
Arguments are scores and associated weights. Not useful for tables. Use Cliff_compute_d_matrix instead.
Cliff_weighted_d_matrix(x, y, w.x = rep(1, length(x)), w.y = rep(1, length(y)))Cliff_weighted_d_matrix(x, y, w.x = rep(1, length(x)), w.y = rep(1, length(y)))
x |
first vector of scores |
y |
second vector of scores |
w.x |
first vector of weights, to apply to x. Defaults to vector of 1.0 |
w.y |
second vector of weights, to apply to y. Defaults to vector of 1.0 |
an n X m d-matrix, where n is length(x) and m is length(y)
Based on radiological measurements, the matrix contains the degree of pneumoconiosis in coal workers. 1 = least severe disease and 4 = most severe.
coal_gcoal_g
## 'coal_g' A matrix with 4 rows and 4 columns.
McCullagh, P. (1977). A logistic model for paired comparisons with ordered categorical data. Biometrika, 64(3), 449-453.
N! / product(n[i]!)
constant_of_integration(n, exclude_diagonal = FALSE)constant_of_integration(n, exclude_diagonal = FALSE)
n |
Matrix of observed counts |
exclude_diagonal |
logical. Should the diagonal cells of a square matrix be excluded from the computation. Default is FALSE, |
value of constant of integration for observed matrix provided
1 = slight 2 = moderate 3 = severe
depressiondepression
## 'depression' A matrix with 3 rows and 3 columns.
von Eye, A. & Mun, E. Y. (2005, p.41). Analyzing rater agreement: Manifest variable methods. Mahwah, NJ: Lawrence Erlbaum.
An interrater agreement data set from Shourki, M. M. (2005, p.80). It is agreement study of two clinicians evaluating whether dogs were dehydrated. The lowest score indicates normal, and the highest score indicates dehydrated (above 10 The "g" in the name indicates that this is taken from mine "G" in the original study.
dogsdogs
## 'dogs' A matrix with 4 rows and 4 columns.
Shoukri, M. M. (2005). The measurement of interobserver agreement. New York: Chapman & Hall.
Severity of disturbing dreams in adolescent boys, measured at two ages..
dreamsdreams
## 'dreams' A matrix with 4 rows and 4 columns.
McCullagh, P. (1980, p.117). Regression models for ordinal data. Journal of the Royal Statistical Society, Series B, 42(2), 109-142.
Columns 1 = None 2 = Slight 3 = Moderate
dumpingdumping
## 'dumping' A matrix with 4 rows and 3 columns
Rows Hospital A Hospital B Hospital C Hospital D
Agresti, A. (1984, p. 63). Analysis of ordinal categorical data. Naew York: Wiley.
Ratings of number of hot drinks consumed by cases with cancer of the esophagus, compared with control subjects.
esophageal_canceresophageal_cancer
## 'esophageal_cancer' A matrix with 4 rows and 4 columns.
Agresti, A. (1984, p. 217). Analysis of ordinal categorical data. New York, Wiley.
Takes a set of (value, weight) pairs and converts into unweighted vector (w[i]) for each i Weights are assumed to be integers
expand(x, w)expand(x, w)
x |
Numeric vector of scores. |
w |
Numeric vector of weights. These are assumed to be integers |
new unweighted vector of scores
Computes the "expit" function – inverse of logit.
expit(z)expit(z)
z |
Numeric. Real valued argument to expit() function. |
exp(z) / (1.0 + exp(z))
Family income for two years from US census.
family_incomefamily_income
## 'family_income' A matrix with 2 rows and 7 columns. Rows are years 1960 and 1970. Columns are income range.
McCullagh, P. (1980, p.114). Regression models for ordinal data. Journal of the Royal Statistical Society, Series B, 42(2), 109-142.
1 = best visual acuity 4 = worst visual acuity
gender_visiongender_vision
## 'gender_vision' A matrix with 2 rows for the genders and 4 columns for visual acuity.
McCullagh, P. (1980, p. 119). Regression models for ordinal data. Journal of the Royal Statistical Society, Series B, 42(2), 109-142.
Fits the model where some of the delta parameters are constrained to be equal to one another.
Goodman_constrained_diagonals_parameter_symmetry(n, equality)Goodman_constrained_diagonals_parameter_symmetry(n, equality)
n |
the matrix of observed counts |
equality |
logical vector indicating whether corresponding delta the parameter is part of the equality set. |
a list containing pooled_chisq: Pearson chi-square for the pooled delta values pooled_df: degrees of freedom for pooled chisq omnibus_chisq: Pearson chi-square for overall model fit, subject to equality constraints omnibus_df; degrees of freedom for omnibus_chisq equality_chisq: Pearson chi-square for test that remaining deltas are all equal equality_df: degrees of freedom for equality_chisq delta_pooled: estimate of pooled delta
equality = c(TRUE, TRUE, FALSE) Goodman_diagonals_parameter_symmetry(vision_data)equality = c(TRUE, TRUE, FALSE) Goodman_diagonals_parameter_symmetry(vision_data)
Goodman, L. A. (1979). Multiplicative models for square contingency tables with ordered categories. Biometrika, 66(3), 413-316.
Goodman_diagonals_parameter_symmetry(n)Goodman_diagonals_parameter_symmetry(n)
n |
the matrix of obsever counts |
a list containing individual_chisq: chi-square value for each diagonal individual_df: degrees of freedom for individual_chisq omnibus_chisq: overall chi-square for the model omnibus_df: degrees for freedom for omnibus_chisq equality_chisq: chi-square for test that all delta values are equal equality_df: degrees of freedom from equality_chisq delta: the vector of estimated delta values (without any equality constraints)
Goodman_diagonals_parameter_symmetry(vision_data)Goodman_diagonals_parameter_symmetry(vision_data)
The model has simple closed form solutions when fitting either the unconstrained version of the version that species equality of delta parameters. However, I could not see how to adapt that to the case where specific parameters were constrained to have a specific value. This routine is to fit that model. It will also fit the unconstrained model, but Goodman gives the estimator for that case.
Goodman_fixed_parameter( n, delta, fixed, convergence = 1e-04, max_iter = 50, verbose = FALSE )Goodman_fixed_parameter( n, delta, fixed, convergence = 1e-04, max_iter = 50, verbose = FALSE )
n |
the r X r matrix of observed counts |
delta |
the vector of asymmetry r - 1 parameters |
fixed |
r - 1 logical vector that specifies whether a delta parameter is fixed (TRUE) or allowed to be estimated (FALSE). |
convergence |
maximum change in a parameter across iterations. Default is 1.0e-4 |
max_iter |
maximum number of iterations, Default is 50. |
verbose |
should progress information be printed to the console. Default is FALSE, do not print. |
list containing phi, delta, max_change largest change in parameter for last the iteration, chisq: Pearson chi-square g_squared: likelihood ratio G^2 df: degrees of freedom
[Goodman_diagonals_parameter_symmetry()]
[Goodman_ml()]
fixed <- c(FALSE, TRUE, FALSE) delta <- c(1.0, 1.0, 1.0) phi <- matrix(0.0, nrow=4, ncol=4) diag(phi) = rep(1.0, 4) Goodman_fixed_parameter(vision_data, delta, fixed)fixed <- c(FALSE, TRUE, FALSE) delta <- c(1.0, 1.0, 1.0) phi <- matrix(0.0, nrow=4, ncol=4) diag(phi) = rep(1.0, 4) Goodman_fixed_parameter(vision_data, delta, fixed)
The model has simple closed form solutions when fitting either the unconstrained version of the version that species equality of delta parameters. However, I could not see how to adapt that to the case where specific parameters were constrained to have a specific value. This routine is to fit that model. It will also fit the unconstrained model, but Goodman gives the estimator for that case.
Goodman_ml(n, phi, delta, fixed)Goodman_ml(n, phi, delta, fixed)
n |
the r X r matrix of observed counts |
phi |
the symmetric matrix parameter |
delta |
the vector of asymmetry r - 1 parameters |
fixed |
r - 1 logical vector that specifies whether a delta parameter is fixed (TRUE) or allowed to be estimated (FALSE). |
list containing new estimates of phi amd delta
[Goodman_diagonals_parameter_symmetry()]
fixed <- c(FALSE, TRUE, FALSE) delta <- c(1.0, 1.0, 1.0) phi <- matrix(0.0, nrow=4, ncol=4) for (i in 1:4) { phi[i, i] = 1.0 } Goodman_ml(vision_data, phi, delta, fixed)fixed <- c(FALSE, TRUE, FALSE) delta <- c(1.0, 1.0, 1.0) phi <- matrix(0.0, nrow=4, ncol=4) for (i in 1:4) { phi[i, i] = 1.0 } Goodman_ml(vision_data, phi, delta, fixed)
Fits Goodman's (1979) Model I
Goodman_model_i( n, row_effects = TRUE, column_effects = TRUE, max_iter = 25, verbose = FALSE, exclude_diagonal = FALSE )Goodman_model_i( n, row_effects = TRUE, column_effects = TRUE, max_iter = 25, verbose = FALSE, exclude_diagonal = FALSE )
n |
matrix of observed counts |
row_effects |
should row effects be included in the model? Default is TRUE |
column_effects |
should column effects be included in the model? Default is TRUE |
max_iter |
maximum number of iterations. Default is 10 |
verbose |
logical. Should cycle-by-cycle output be printed? Default is no |
exclude_diagonal |
logical. For square tables, should the cells on the diagonal be excluded? Default is FALSE, include all cells |
a list containing alpha: row effects beta: column effects gamma: row location weights delta: column location weights log_likelihood: log(likelihood) g_squared: G^2 fit measure chisq: X^2 fit measure df: degrees of freedom
Fits Goodman's (1979) Model I*
Goodman_model_i_star( n, max_iter = 25, verbose = FALSE, exclude_diagonal = FALSE )Goodman_model_i_star( n, max_iter = 25, verbose = FALSE, exclude_diagonal = FALSE )
n |
matrix of observed counts |
max_iter |
maximum number of iterations |
verbose |
should cycle-by-cycle information be printed out? Default is FALSE, do not print |
exclude_diagonal |
should the cells along the main diagonal be excluded? Default is FALSE, include all cells |
a list containing alpha: vector of row parameters beta: vector of column parameters theta: vector of common row/column estimates log_likelihood: log(likelihood) at completion g_squared: G^2 fit measure chisq: X^2 fit measure df: degrees of freedom
Fits Goodman's (1979) Model II
Goodman_model_ii( n, rho = 1:nrow(n) - (nrow(n) + 1)/2, sigma = 1:ncol(n) - (ncol(n) + 1)/2, update_rows = TRUE, update_columns = TRUE, max_iter = 25, verbose = FALSE, exclude_diagonal = FALSE )Goodman_model_ii( n, rho = 1:nrow(n) - (nrow(n) + 1)/2, sigma = 1:ncol(n) - (ncol(n) + 1)/2, update_rows = TRUE, update_columns = TRUE, max_iter = 25, verbose = FALSE, exclude_diagonal = FALSE )
n |
matrix of observed counts |
rho |
values of row locations. Default is 1:nrow(n) - (nrow(n) + 1) / 2 |
sigma |
values of column locations. Default is 1:ncol(n) - (ncol(n) + 1) / 2 |
update_rows |
should values of row locations be updated? Default is TRUE, update |
update_columns |
should value of column locations be updated? Default is TRUE, update |
max_iter |
maximum number of iterations to perform. Default is 10 |
verbose |
should cycle-by-cycle output be produced? Default is FALSE |
exclude_diagonal |
logical. Should the diagonal be excluded from the computation. Default is FALSE. |
a list containing alpha: row effects beta: column effects rho: centered row locations mu: row locations sigma: centered column locations nu: column locations log_likelihood: log(likelihood) g_squared: G^2 fit measure chisq: X^2 fit measure df: degrees of freedom
Fits Goodman's (1979) model II*, where row and column effects are equal.
Goodman_model_ii_star( n, exclude_diagonal = FALSE, max_iter = 25, verbose = FALSE )Goodman_model_ii_star( n, exclude_diagonal = FALSE, max_iter = 25, verbose = FALSE )
n |
matrix of observed counts |
exclude_diagonal |
should the cells of the main diagonal be excluded? Default is FALSE, include all cells |
max_iter |
maximum number of iterations |
verbose |
should cycle-by-cycle information be printed out? Default is FALSE, do not print |
a list containing alpha: vector of alpha (row) parameters beta: vector of beta (column) parameters phi: vector of common row/column effects log_likelihood: value of the log(likelihood) function at completion g_squared: G^2 fit measure chisq: X^2 fit measure df: degrees of freedom
null association model
Goodman_null_association( n, max_iter = 25, verbose = FALSE, exclude_diagonal = FALSE )Goodman_null_association( n, max_iter = 25, verbose = FALSE, exclude_diagonal = FALSE )
n |
matrix of observed counts |
max_iter |
maximum number of iterations. Default is 10 |
verbose |
should cycle-by-cycle info be printed? Default is FALSE |
exclude_diagonal |
logical, Should the diagonal be excluded from the computations. Default is FALSE |
a list containing alpha: row effects beta: column effects log_likelihood: log(likelihood) g_squared: G^2 fit measure chisq: X^2 fit measure df: degrees of freedom
Computes the model-based probability for cell i, j
Goodman_pi(phi, delta, i, j)Goodman_pi(phi, delta, i, j)
phi |
symmetry matrix |
delta |
vector of asymmetry parameters |
i |
row index |
j |
column index |
pi for that cell
Computes the full matrix of model-based cell probabilities.
Goodman_pi_matrix(phi, delta)Goodman_pi_matrix(phi, delta)
phi |
the symmetric matrix |
delta |
the vector of asymmetry parameters |
matrix of model-based probabilities
Fits the symmetric association model from Goodman (1979). Note the model is a reparameterized version of the quasi-symmetry model, so the quasi-symmetry model has the same fit indices.
Goodman_symmetric_association_model(n)Goodman_symmetric_association_model(n)
n |
matrix of observed counts |
a list containing x: design matrix used for the glm() regression beta: parameter estimates se: standard errors of beta g_squared: G^2 measure of fit chisq: X^2 measure of fit df: degrees of freedom expected: model-based expected cell counts
Fits Goodman's (1979) uniform association model
Goodman_uniform_association( n, max_iter = 25, verbose = FALSE, exclude_diagonal = FALSE )Goodman_uniform_association( n, max_iter = 25, verbose = FALSE, exclude_diagonal = FALSE )
n |
matrix of observed counts |
max_iter |
maximum number of iterations. Default is 10. |
verbose |
should cycle-by-cycle info be printed out? Default is FALSE |
exclude_diagonal |
logical. Should the cells of the main diagonal be excluded from the computations? Default is FALSE, include all cells. |
a list containing alpha: row effects beta: column effects theta: uniform association parameter log_likelihood: log(likelihood) g_squared: G^2 fit measure chisq: X^2 fit measure df: degrees of freedom
Case where j == r, i == k == k2
handle_max_i_i(i, marginal_pi, kappa, v)handle_max_i_i(i, marginal_pi, kappa, v)
i |
index into marginal_pi |
marginal_pi |
expected proportions for each category |
kappa |
current estimate of kappa coefficient |
v |
symmetry matrix |
second-order derivative
Case where j == r, i != k, i == k2
handle_max_i_k(i, k, marginal_pi, kappa, v)handle_max_i_k(i, k, marginal_pi, kappa, v)
i |
index into pi |
k |
index into v (other is i) |
marginal_pi |
expected proportions for each category |
kappa |
current estimate of kappa coefficient |
v |
symmetry matrix |
second-order derivative
Case where j == r, i != k && i != k2
handle_max_k_k2(i, k, k2, marginal_pi, kappa, v)handle_max_k_k2(i, k, k2, marginal_pi, kappa, v)
i |
index into pi |
k |
first index into marginal_pi |
k2 |
second index into marginal_pi |
marginal_pi |
expected proportions for each category |
kappa |
current estimate of kappa coefficient |
v |
symmetry matrix |
second-order derivative
Case where pi[i, r] with k and k2
handle_one_maximum(i, j, k, k2, marginal_pi, kappa, v)handle_one_maximum(i, j, k, k2, marginal_pi, kappa, v)
i |
first index of pi |
j |
second index of pi |
k |
first index into marginal_pi |
k2 |
second index into marginal_pi |
marginal_pi |
expected proportions for each category |
kappa |
current estimate of kappa coefficient |
v |
symmetry matrix |
second order derivative
Case where i == j, i < r, j < r
handle_tied_below_maximum(j, k, k2, marginal_pi, kappa, v)handle_tied_below_maximum(j, k, k2, marginal_pi, kappa, v)
j |
index of pi |
k |
first index into marginal_pi |
k2 |
second index into marginal_pi |
marginal_pi |
expected proportions for each of the categories |
kappa |
current estimate of kappa coefficient |
v |
symmetry matrix |
derivative
Case where pi[r, r] with k and k2
handle_tied_maximum(k, k2, marginal_pi, kappa, v)handle_tied_maximum(k, k2, marginal_pi, kappa, v)
k |
first index into marginal_pi |
k2 |
second index into marginal_pi |
marginal_pi |
expected proportions for each category |
kappa |
current estimate of kappa coefficient |
v |
symmetry matrix |
second order derivative
Case where i != j, i < r && j < r
handle_untied_below_maximum(i, j, k, k2, marginal_pi, kappa, v)handle_untied_below_maximum(i, j, k, k2, marginal_pi, kappa, v)
i |
first index of pi |
j |
second index of pi |
k |
first index of marginal_pi |
k2 |
second index of marginal_pi |
marginal_pi |
expected proportions of each of the categories |
kappa |
current value of kappa coefficient |
v |
symmetry matrix |
Counts of cases charged with homicide. The rows and columns indicate whether there was an additional charge of a felony occurring in addition to the homicide. The data is actually 3-dimensional. It is stored as 4 related matrices, each with the leading word "homicide_" The rest of the name gives the race of the defendant and the race of the victim, separated by an underscore
homicide_black_blackhomicide_black_black
## 'homicide_black_black' Each is a matrix with 3 rows and 3 columns. Rows are classification by police and columns are classification by the court/prosecutor. 1 = No felony 2 = Possible felony 2 = Felony
Agresti, A. (1984, p. 211). Analysis of ordinal categorical data. New York: Wiley.
Counts of cases charged with homicide. The rows and columns indicate whether there was an additional charge of a felony occurring in addition to the homicide. The data is actually 3-dimensional. It is stored as 4 related matrices, each with the leading word "homicide_" The rest of the name gives the race of the defendant and the race of the victim, separated by an underscore.
homicide_black_whitehomicide_black_white
## 'homicide_black_white' Each is a matrix with 3 rows and 3 columns. Rows are classification by police and columns are classification by the court/prosecutor. 1 = No felony 2 = Possible felony 2 = Felony
Agresti, A. (1984, p. 211). Analysis of ordinal categorical data. New York: Wiley.
Counts of cases charged with homicide. The rows and columns indicate whether there was an additional charge of a felony occurring in addition to the homicide. The data is actually 3-dimensional. It is stored as 4 related matrices, each with the leading word "homicide_" The rest of the name gives the race of the defendant and the race of the victim, separated by an underscore
homicide_white_blackhomicide_white_black
## 'homicide_white_black' Each is a matrix with 3 rows and 3 columns. Rows are classification by police and columns are classification by the court/prosecutor. 1 = No felony 2 = Possible felony 2 = Felony
Agresti, A. (1984, p. 211). Analysis of ordinal categorical data. New York: Wiley.
Counts of cases charged with homicide. The rows and columns indicate whether there was an additional charge of a felony occurring in addition to the homicide. The data is actually 3-dimensional. It is stored as 4 related matrices, each with the leading word "homicide_" The rest of the name gives the race of the defendant and the race of the victim, separated by an underscore
homicide_white_whitehomicide_white_white
## 'homicide_white_white' Each is a matrix with 3 rows and 3 columns. Rows are classification by police and columns are classification by the court/prosecutor. 1 = No felony 2 = Possible felony 2 = Felony
Agresti, A. (1984, p. 211). Analysis of ordinal categorical data. New York: Wiley.
Measures of men's hypothalamus taken from cadavers. First data set.
hypothalamus_1hypothalamus_1
# 'hypothalamus_1' Each set is a dominance matrix (see e.g., Cliff 1996).
Cliff, N. (1996), Ordinal methods for behavioral data analysis. Mahwah NJ: Lawrence Erlbaum.
Measures of men's hypothalamus taken from cadavers. Second data set.
hypothalamus_2hypothalamus_2
# 'hypothalamus_2' Each set is a dominance matrix (see e.g., Cliff 1996).
Cliff, N. (1996), Ordinal methods for behavioral data analysis. Mahwah NJ: Lawrence Erlbaum.
Measures are within subjects, comparing a control condition to two conditions with interference. Interference condition 1 v. interference condition 2
interference_12interference_12
## 'interference_control_1', 'interference_control_2', 'interference_12' Within-persons dominance matrices.
Cliff, N. (1996). Ordinal methods for behavioral data analysis. Mahwah NJ: Lawrence Erlba
Measures are within subjects, comparing a control condition to two conditions with interference. Control v. interference condition 1
interference_control_1interference_control_1
## 'interference_control_1', 'interference_control_2', 'interference_12' Within-persons dominance matrices.
Cliff, N. (1996). Ordinal methods for behavioral data analysis. Mahwah NJ: Lawrence Erlbaum.
Measures are within subjects, comparing a control condition to two conditions with interference. Control v. interference condition 2
interference_control_2interference_control_2
## 'interference_control_1', 'interference_control_2', 'interference_12' Within-persons dominance matrices.
Cliff, N. (1996). Ordinal methods for behavioral data analysis. Mahwah NJ: Lawrence Erlba
Fits the marginal homogeneity model according to the minimum discriminant information. Ireland, C. T., Ku, H. H., & Kullback, S. (1969). Symmetry and marginal homogeneity of an r × r contingency table. Journal of the American Statistical Association, 64(328), 1323-1341.
Ireland_marginal_homogeneity( n, truncated = FALSE, max_iter = 15, verbose = FALSE )Ireland_marginal_homogeneity( n, truncated = FALSE, max_iter = 15, verbose = FALSE )
n |
matrix of observed counts |
truncated |
should the diagonal be excluded. Default is FALSE, include the diagonal. |
max_iter |
maximum number of iterations to perform |
verbose |
should cycle-by-cycle information be printed out. Default is FALSE. |
a list containing mdis: value of the minimum discriminant information statistic (appox chi-squared) df: dgrees of freedom x_star: matrix of model-based counts p_star: matrix of model-based p-values
Ireland_marginal_homogeneity(vision_data)Ireland_marginal_homogeneity(vision_data)
Computes the MDIS between the two matrices provided.
Ireland_mdis(n, x_star, truncated = FALSE)Ireland_mdis(n, x_star, truncated = FALSE)
n |
first matrix (usually observed counts) |
x_star |
second matrix (usually model-based) |
truncated |
should the diagonal be ignored. Default is FALSE, include the diagonal elements. |
value of the MDIS criterion
Renormalize counts to account for truncation of diagonal
Ireland_normalize_for_truncation(n)Ireland_normalize_for_truncation(n)
n |
matrix of observed counts |
matrix n with diagonal set to 0.0
Fit for quasi-symmetry model. Obtained by subtraction, so no model-based probabilities.
Ireland_quasi_symmetry(n, truncated = FALSE)Ireland_quasi_symmetry(n, truncated = FALSE)
n |
matrix of observed counts |
truncated |
should the diagonal be excluded, Default is FALSE, include the diagonal. |
a list with mdis = MDIS value and df = degrees of freedom for quasi-symmetry model
[Ireland_quasi_symmetry_model()]
Ireland_quasi_symmetry(vision_data)Ireland_quasi_symmetry(vision_data)
Fits the model according to the MDIS criterion.
Ireland_quasi_symmetry_model( n, truncated = FALSE, max_iter = 5, verbose = FALSE )Ireland_quasi_symmetry_model( n, truncated = FALSE, max_iter = 5, verbose = FALSE )
n |
matrix of observed counts |
truncated |
should the diagonal be excluded. Default is FALSE, include diagonal cells. |
max_iter |
maximum number of iterations in minimizing the criterion. Default is 4 |
verbose |
logical variable, should cycle-by-cycle info be printed. Defaullt is FALSE. |
a list containing mdis: value of the MDIS at termination df: degrees of freedom x_star: matrix of model-reproduced counts p_star: matrix of model-reproduced p-values
[Ireland_quasi_symmetry()]
Ireland_quasi_symmetry_model(vision_data)Ireland_quasi_symmetry_model(vision_data)
Ireland, C. T., Ku, H. H., & Kullback, S. (1969). Symmetry and marginal homogeneity of an r × r contingency table. Journal of the American Statistical Association, 64(328), 1323-1341.
Ireland_symmetry(n, truncated = FALSE)Ireland_symmetry(n, truncated = FALSE)
n |
matrix of observed counts |
truncated |
should the diagonal be excluded. Default is FALSE, include the diagonal. |
a list containing mdis: value of the minimum discriminant information statistic (appox chi-squared) df: dgrees of freedom x_star: matrix of model-based counts p_star: matrix of model-based p-values
Ireland_symmetry(vision_data)Ireland_symmetry(vision_data)
from stackoverflow: https://stackoverflow.com/questions/24961983/how-to-check-if-a-matrix-has-an-inverse-in-the-r-language
is_invertible(X)is_invertible(X)
X |
Matrix to be tested. It is assumed X is square |
logical: TRUE if inversion succeeds, FALSE otherwise
Determines if its argument is not a valid number.
is_missing_or_infinite(x)is_missing_or_infinite(x)
x |
Numeric. Number of be evaluated |
TRUE if is.na(), is.nan(), or is.infinite() returns TRUE. FALSE otherwise.
Computes Cohen's 1960 kappa coefficient
kappa(n)kappa(n)
n |
matrix of observed counts |
kappa coefficient
Computes the likelihood ratio G^2 measure of fit.
likelihood_ratio_chisq(n, pi, exclude_diagonal = FALSE)likelihood_ratio_chisq(n, pi, exclude_diagonal = FALSE)
n |
Matrix of observed counts |
pi |
Matrix of same dimensions as n. Model-based matrix of predicted proportions |
exclude_diagonal |
logical. Should the diagonal cells of a square matrix be excluded from the computation. Default is FALSE. The effect of setting it to TRUE for non-square matrices may be unintuitive and should he avoided. |
G^2
The first (should be the only) element read from the RData file is returned From: https://stackoverflow.com/questions/5577221/how-can-i-load-an-object-into-a-variable-name-that-i-specify-from-an-r-data-file
loadRData(file_name)loadRData(file_name)
file_name |
Character. Name of the file containing the RData |
usage x <- loadRData(file_name="")
the first object from the restored RData
Computes the multinomial log(likelihood).
log_likelihood(n, pi, exclude_diagonal = FALSE)log_likelihood(n, pi, exclude_diagonal = FALSE)
n |
Matrix of observed counts |
pi |
Matrix of same dimensions as n. Model-based matrix of predicted proportions |
exclude_diagonal |
logical. Should diagonal cells of square matrix be excluded from the computation? Default is FALSE. The effect of setting it to TRUE for non-square matrices may be unintuitive and should he avoided. |
log(likelihood)
Adds indicator variables for the diagonal cells in table n.
log_linear_add_all_diagonals(n, x)log_linear_add_all_diagonals(n, x)
n |
the matrix of observed counts |
x |
the design matrix to be augmented |
new design matrix with nrow(n) columns added. The columns are all 0 unless the row corresponds to a diagonal cell in n, in which case the entry is 1
x <- log_linear_main_effect_design(vision_data) x_prime <- log_linear_add_all_diagonals(vision_data, x)x <- log_linear_main_effect_design(vision_data) x_prime <- log_linear_add_all_diagonals(vision_data, x)
Takes the design matrix provided and appends the new column
log_linear_append_column(x, x_new, position = ncol(x) + 1)log_linear_append_column(x, x_new, position = ncol(x) + 1)
x |
the original design matrix |
x_new |
the column to be appended |
position |
column index within the new matrix for the new column. Defaults to last position = appending the column |
the new design matrix
x <- log_linear_main_effect_design(vision_data) new_column <- c(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1) x_prime <- log_linear_append_column(x, new_column)x <- log_linear_main_effect_design(vision_data) new_column <- c(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1) x_prime <- log_linear_append_column(x, new_column)
Creates missing column names
log_linear_create_coefficient_names(x, n, effect_names = NULL)log_linear_create_coefficient_names(x, n, effect_names = NULL)
x |
the design matrix being modified |
n |
the matrix of observed counts |
effect_names |
user specified names to be applied to effects after the intercept and main effects. Default is NULL |
vector of names to apply to x
Uses the ordinal ranks (1, 2, ..., nrow(n)) as data.
log_linear_create_linear_by_linear(n, centered = FALSE)log_linear_create_linear_by_linear(n, centered = FALSE)
n |
the matrix of observed cell counts |
centered |
should the variables be centered before the product is computed |
a vector containing the new variable
linear <- log_linear_create_linear_by_linear(vision_data) x <- log_linear_equal_weight_agreement_design(vision_data) x_prime <- log_linear_append_column(x, linear)linear <- log_linear_create_linear_by_linear(vision_data) x <- log_linear_equal_weight_agreement_design(vision_data) x_prime <- log_linear_append_column(x, linear)
In the case of an observed 0, epsilon is inserted into the cell before the log is taken.
log_Linear_create_log_n(n, epsilon = 1e-06, all_cells = FALSE)log_Linear_create_log_n(n, epsilon = 1e-06, all_cells = FALSE)
n |
matrix of cell counts |
epsilon |
amount to be inserted into cell with observed 0. |
all_cells |
add epsilon to all cells or just those with 0 observed frequencies |
a list containing: log_n – a vector of log frequencies and dat – modified version of the cell counts data
The model has main effects for rows and for columns, plus an additional parameter for the agreement (diagonal) cells.
log_linear_equal_weight_agreement_design(n, n_raters = 2)log_linear_equal_weight_agreement_design(n, n_raters = 2)
n |
the matrix of cell counts |
n_raters |
number of raters. Currently only 2 (the default) are supported. This is an extension point for future work. |
design matrix for the model
x <- log_linear_equal_weight_agreement_design(vision_data)x <- log_linear_equal_weight_agreement_design(vision_data)
Fits a log-linear model to the data provided, using the design matrix provided. Names for the effects will be "rows1", "cols1" etc. If there are remaining entries, they can be specified as the "effect_names" character vector. This function is a wrapper around a call to glm() that handles some of the details of the call and packages the output in a more convenient form.
log_linear_fit(n, x, effect_names = NULL)log_linear_fit(n, x, effect_names = NULL)
n |
matrix of observed counts to be fit |
x |
design matrix for predictor variables |
effect_names |
character vector of additional names to apply to the columns of x The default is NULL, in which case the columns will be labeled "model1" etc. |
a list containing x: the design matrix beta: the regression parameters se: the vector of standard errors g_squared: G^2 fit measure chisq: X^2 fit measure df: degrees of freedom expected: matrix of expected frequencies
It is intended as a straw-man model as it assumes no agreement beyond chance.
log_linear_main_effect_design(n, n_raters = 2)log_linear_main_effect_design(n, n_raters = 2)
n |
the matrix of cell counts |
n_raters |
number of raters. Currently only 2 (the default) are supported. This is an extension point for future work. |
the design matrix for the model
x <- log_linear_main_effect_design(vision_data)x <- log_linear_main_effect_design(vision_data)
Converts a matrix of data into a vector suitable for use in analysis with the design matrices created. Unlike simply calling vector() on the matrix the resulting vector is organized by rows, then columns. This order corresponds to the order in the design matrix.
log_linear_matrix_to_vector(dat)log_linear_matrix_to_vector(dat)
dat |
the matrix to be converted a vector |
a vector suitable to use as dependent variable, e.g. in a call to glm()
Creates the design matrix for a quasi-symmetry design
log_linear_quasi_symmetry_model_design(n)log_linear_quasi_symmetry_model_design(n)
n |
matrix of observed counts |
design matrix for quasi-symmetry design
Takes the design matrix provided and removes the column in the position specified
log_linear_remove_column(x, position = ncol(x))log_linear_remove_column(x, position = ncol(x))
x |
the original design matrix |
position |
column index within the new matrix for the new column. Defaults to last position |
the new design matrix
x <- log_linear_main_effect_design(vision_data) linear <- log_linear_create_linear_by_linear(vision_data) x_prime <- log_linear_append_column(x, linear) x_again <- log_linear_remove_column(x_prime, ncol(x_prime))x <- log_linear_main_effect_design(vision_data) linear <- log_linear_create_linear_by_linear(vision_data) x_prime <- log_linear_append_column(x, linear) x_again <- log_linear_remove_column(x_prime, ncol(x_prime))
Creates design matrix for symmetry model.
log_linear_symmetry_design(n)log_linear_symmetry_design(n)
n |
matrix of observed counts |
design matrix for the model
Computes the log-odds (logit) for the value provided
logit(p)logit(p)
p |
Numeric. Assumed to lie in interval(0, 1) |
log(p / (1.0 - p))
Computes sums c+ used in maximizing the log(likelihod)
McCullagh_compute_c_plus(phi, alpha)McCullagh_compute_c_plus(phi, alpha)
phi |
matrix of symmetry parameters |
alpha |
vector of asymmetry parameters |
list of c_i_plus and c_plus_i
Compute the linear constraint on psi elements for identifiablity.
McCullagh_compute_condition(psi)McCullagh_compute_condition(psi)
psi |
symmetry matrix |
value of the constraint
Computes cumulative sums for rows,
McCullagh_compute_cumulative_sums(n)McCullagh_compute_cumulative_sums(n)
n |
matrix of observed counts |
R where R[i, ] contains cumulative sum of n[i,]
Computes the model-based cumulative probability matrices pij and qij
McCullagh_compute_cumulatives(psi, delta, alpha, c = 1)McCullagh_compute_cumulatives(psi, delta, alpha, c = 1)
psi |
the matrix of symmetry parameters |
delta |
the scalar asymmetry parameter |
alpha |
the vector of asymmetry parameters |
c |
the normalizing constant for the pis to sum to 1.0 Default value is 1.0 |
list containing matrices pij and qij
Computes the degrees of freedom for the model
McCullagh_compute_df(M, generalized = FALSE)McCullagh_compute_df(M, generalized = FALSE)
M |
the size of the M X M observed matrix |
generalized |
is the generalized model being fit? Default is FALSE, regular model |
Computes gamma from x and beta
McCullagh_compute_gamma(x, beta, s, c)McCullagh_compute_gamma(x, beta, s, c)
x |
predictor variables |
beta |
vector of regression coefficients |
s |
number of rows in the table |
c |
number of score levels in table |
vector of model-based gamma coefficients
Computes value of gamma from phi. Inverse of usual computation.
McCullagh_compute_gamma_from_phi(phi, j, gamma)McCullagh_compute_gamma_from_phi(phi, j, gamma)
phi |
value to compute from |
j |
index to use in computation |
gamma |
vector of gamma values (model-based cumulative logits) |
gamma[j] given phi and gamma[j + 1]
Computes value of gamma[j + 1] from phi.
McCullagh_compute_gamma_plus_1_from_phi(phi, j, gamma)McCullagh_compute_gamma_plus_1_from_phi(phi, j, gamma)
phi |
value used in computation |
j |
index to use in computation |
gamma |
vector of gamma values (model-based cumulative logits) |
gamma[j + 1] given phi and gamma[j]
Coompute the model-based cumulative probabilities pij and qij.
McCullagh_compute_generalized_cumulatives(psi, delta_vec, alpha, c = 1)McCullagh_compute_generalized_cumulatives(psi, delta_vec, alpha, c = 1)
psi |
symmetry matrix |
delta_vec |
vector of asymmetry parameters |
alpha |
vector of asymmetry parameters |
c |
normalizing constant so pis sum to 1. Defaults to 1.0 |
matrices of model-based cumulative probabilities pij and qij
Cpompute matrix pi under generalized model.
McCullagh_compute_generalized_pi(psi, delta_vec, alpha, c = 1)McCullagh_compute_generalized_pi(psi, delta_vec, alpha, c = 1)
psi |
the matrix of symmetry parameters |
delta_vec |
the vector asymmetry parameter |
alpha |
the vector of asymmetry parameters |
c |
the normalizing constant for the pis to sum to 1.0 Default value is 1.0 |
the matrix pi
Computes lambda, log of cumulative odds.
McCullagh_compute_lambda(n, use_half = TRUE)McCullagh_compute_lambda(n, use_half = TRUE)
n |
matrix of observed counts |
use_half |
logical whether of not to add half to the cell count before taking the logit. Default value is TRUE. |
Computes the log(likelihood) for the general nonlinear model.
McCullagh_compute_log_l(n, phi)McCullagh_compute_log_l(n, phi)
n |
matrix of observed counts |
phi |
vector of model-based parameters |
log(likelihood)
Compute the observed sums Nij
McCullagh_compute_Nij(n)McCullagh_compute_Nij(n)
n |
the matrix of observed counts |
a list containing Pij and Qij
Compute the value of the Lagrange multiplier for the constraint on psi.
McCullagh_compute_omega(n, pi)McCullagh_compute_omega(n, pi)
n |
matrix of observed counts |
pi |
matrix of model-based probabilities pi. |
the value of the Lagrange multiplier.
Computes phi based on gamma
McCullagh_compute_phi(gamma, j)McCullagh_compute_phi(gamma, j)
gamma |
vector of gamma parameters |
j |
index of phi to compute |
phi[j]
Compute matrix of model-based logits
McCullagh_compute_phi_matrix(gamma)McCullagh_compute_phi_matrix(gamma)
gamma |
matrix of model-based cumulative odds |
matrix of model-based logits
Compute the regular (non-cumulative) model-based pi values
McCullagh_compute_pi(psi, delta, alpha, c)McCullagh_compute_pi(psi, delta, alpha, c)
psi |
the matrix of symmetry parameters |
delta |
the scalar asymmetry parameter |
alpha |
the vector of asymmetry parameters |
c |
the normalizing constant for the pis to sum to 1.0 Default value is 1.0 |
the matrix pi
Computes matrix of p-values pi based on x and current value of beta.
McCullagh_compute_pi_from_beta(n, x, beta)McCullagh_compute_pi_from_beta(n, x, beta)
n |
matrix of observed counts |
x |
design matrix |
beta |
current values of location model regression parameters |
matrix of model-based pi values
Compute the cell probabilities pi from gamma.
McCullagh_compute_pi_from_gamma(gamma)McCullagh_compute_pi_from_gamma(gamma)
gamma |
matrix of gamma values |
c X c matrix of p-values pi
Computes regression weights w; R_dot_j * (N - R_dot_j[j]) * (n_do_j[j] a= na_dot_j[j+ 1] )
McCullagh_compute_regression_weights(n)McCullagh_compute_regression_weights(n)
n |
matrix of observed counts |
list of w, and sum(w)
Compute sums too use in maximizing log(likelihood)
McCullagh_compute_s_plus(n)McCullagh_compute_s_plus(n)
n |
matrix of observed counts |
list of s_i_plus and s_plus_i
Compute the Newton-Raphson update.
McCullagh_compute_update(gradient, hessian)McCullagh_compute_update(gradient, hessian)
gradient |
gradient vector of log(likelihood) wrt parameters |
hessian |
hessian of log(likelihood) wrt parameters |
vector with update values for each of the parameters
Computes Z, where z is w * lambda.
McCullagh_compute_z(lambda, w)McCullagh_compute_z(lambda, w)
lambda |
cumulative logits |
w |
weights to apply to the logits |
z, sum pf product of lambda
McCullagh, P. (1978). A class of parametric models for the analysis of square contingency tables with ordered categories. Biometrika, 65(2) 413-418.
McCullagh_conditional_symmetry(n, max_iter = 5, verbose = FALSE)McCullagh_conditional_symmetry(n, max_iter = 5, verbose = FALSE)
n |
matrix of observed counts |
max_iter |
maximum number of iterations to maximize the log(likelihood) |
verbose |
should cycle-by-cycle info be printed. Default is FALSE. |
a list containing theta: the asymmetry parameter chisq: chi-square g_squared: likelihood ratio G^2 df: degrees of freedom
McCullagh_conditional_symmetry(vision_data)McCullagh_conditional_symmetry(vision_data)
Computes sums used in maximizing theta.
McCullagh_conditional_symmetry_compute_s(n)McCullagh_conditional_symmetry_compute_s(n)
n |
matrix of observed counts |
list with s_i_plus and s_plus-i
Initializes symmetry matrix phi
McCullagh_conditional_symmetry_initialize_phi(M)McCullagh_conditional_symmetry_initialize_phi(M)
M |
the number of rows/columns in phi |
the phi matrix
Maximizes log(likelihood) wrt phi.
McCullagh_conditional_symmetry_maximize_phi(n)McCullagh_conditional_symmetry_maximize_phi(n)
n |
matrix of observed counts |
phi matrix
Maximizes the log(likelihood) wrt theta.
McCullagh_conditional_symmetry_maximize_theta(n)McCullagh_conditional_symmetry_maximize_theta(n)
n |
matrix of observed counts |
value of asymmetry parameter theta
Computes model-based proportions.
McCullagh_conditional_symmetry_pi(phi, theta)McCullagh_conditional_symmetry_pi(phi, theta)
phi |
the symmetric matrix |
theta |
the asymmetry parameter |
matrix of model-based p-values
Derivative of the condition wrt psi[i, j].
McCullagh_derivative_condition_wrt_psi(i, j)McCullagh_derivative_condition_wrt_psi(i, j)
i |
first index of psi |
j |
second index of psi |
derivative
Derivative of gamma j + 1 wrt phi.
McCullagh_derivative_gamma_plus_1_wrt_phi(gamma, j, phi)McCullagh_derivative_gamma_plus_1_wrt_phi(gamma, j, phi)
gamma |
vector |
j |
index of gamma to take derivative of |
phi |
scalar phi taking derivative wrt |
derivative
Version given in McCullagh isn't right.
McCullagh_derivative_gamma_wrt_phi(gamma, j, phi)McCullagh_derivative_gamma_wrt_phi(gamma, j, phi)
gamma |
vector of cumulative logits |
j |
index of derivative sought |
phi |
scalar phi taking derivative wrt |
derivative
Assumes a logit link is being used.
McCullagh_derivative_gamma_wrt_y(gamma, i, j)McCullagh_derivative_gamma_wrt_y(gamma, i, j)
gamma |
matrix of gamma values |
i |
row index of gamma |
j |
column index of gamma |
derivative
Derivative of Lagrange multiplier wrt scalar delta.
McCullagh_derivative_lagrangian_wrt_delta(n, psi, delta, alpha, c = 1)McCullagh_derivative_lagrangian_wrt_delta(n, psi, delta, alpha, c = 1)
n |
matrix of observed counts |
psi |
symmetry matrix |
delta |
scalar asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing coefficient so that sum o pi = 1. Default value is 1.0 |
value of the derivative
Derivative of Lagrangian wrt delta_vec.
McCullagh_derivative_lagrangian_wrt_delta_vec( n, k, psi, delta_vec, alpha, c = 1 )McCullagh_derivative_lagrangian_wrt_delta_vec( n, k, psi, delta_vec, alpha, c = 1 )
n |
matrix of observed counts |
k |
index of delta_vec to compute derivative wrt |
psi |
matrix of symmetry parameters |
delta_vec |
vector asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
derivative
Derivative of Lagrangian wrt psi[i1, j1].
McCullagh_derivative_lagrangian_wrt_psi(n, i1, j1, psi, delta, alpha, c = 1)McCullagh_derivative_lagrangian_wrt_psi(n, i1, j1, psi, delta, alpha, c = 1)
n |
matrix of observed counts |
i1 |
first index of psi |
j1 |
first index of psi |
psi |
matrix of symmetry parameters |
delta |
scalar asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
derivative
Derivative of log(likelihood) wrt alpha[index].
McCullagh_derivative_log_l_wrt_alpha(n, index, psi, delta, alpha, c = 1)McCullagh_derivative_log_l_wrt_alpha(n, index, psi, delta, alpha, c = 1)
n |
matrix of observed counts |
index |
index of alpha |
psi |
matrix of symmetry parameters |
delta |
scalar asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
derivative
McCullagh, P. (1980). Regression models for ordinal data. Journal of the Royal Stastical Society, Series B, 42(2), 109-142. With assist from appendix of Agresti, (1984). Agresti, A. (1984). Analysis of ordinal categorical data. New York, Wiley, p. 244-246.
McCullagh_derivative_log_l_wrt_beta(n, x, gamma)McCullagh_derivative_log_l_wrt_beta(n, x, gamma)
n |
matrix of observed counts |
x |
design matrix for location |
gamma |
matrix of model-based cumulative logits |
derivative
Derivative of log(likelihood) wrt c.
McCullagh_derivative_log_l_wrt_c(n, psi, delta, alpha, c)McCullagh_derivative_log_l_wrt_c(n, psi, delta, alpha, c)
n |
matrix of observed counts |
psi |
matrix of symmetry parameters |
delta |
scalar asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
derivative
Derivative of log(likelihood) wrt delta (scalar or vector0.
McCullagh_derivative_log_l_wrt_delta(n, psi, delta, alpha, c = 1, k = 1)McCullagh_derivative_log_l_wrt_delta(n, psi, delta, alpha, c = 1, k = 1)
n |
matrix of observed counts |
psi |
matrix of symmetry parameters |
delta |
scalar asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
k |
index into delta_vac. Defaults to 1. |
derivative
Derivative of log(likelihood) wrt delta_vec[k].
McCullagh_derivative_log_l_wrt_delta_vec(n, k, psi, delta_vec, alpha, c = 1)McCullagh_derivative_log_l_wrt_delta_vec(n, k, psi, delta_vec, alpha, c = 1)
n |
matrix of observed counts |
k |
index of delta_vec |
psi |
matrix of symmetry parameters |
delta_vec |
vector asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
derivative
Derivative of log(likelihood) wrt parameters.
McCullagh_derivative_log_l_wrt_params(n, x, beta)McCullagh_derivative_log_l_wrt_params(n, x, beta)
n |
matrix of observed counts |
x |
design matrix for location model |
beta |
vector of regression parameters for location model |
gradient vector
Derivative of log(likelihood) wrt phi[i, j]
McCullagh_derivative_log_l_wrt_phi(n, phi, i, j)McCullagh_derivative_log_l_wrt_phi(n, phi, i, j)
n |
matrix of observed counts |
phi |
matrix of phi-values |
i |
row index of phi |
j |
column index of phi |
derivative
Derivative of log(likelihood) wrt psi.
McCullagh_derivative_log_l_wrt_psi(n, i1, j1, psi, delta, alpha, c = 1)McCullagh_derivative_log_l_wrt_psi(n, i1, j1, psi, delta, alpha, c = 1)
n |
matrix of observed counts |
i1 |
row index of psi |
j1 |
column index of psi |
psi |
matrix of symmetry parameters |
delta |
scalar asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
derivative
Derivative of Lagrange multiplier omega wrt alpha[index].
McCullagh_derivative_omega_wrt_alpha(n, index, psi, delta, alpha, c = 1)McCullagh_derivative_omega_wrt_alpha(n, index, psi, delta, alpha, c = 1)
n |
matrix of observed counts |
index |
index of alpha |
psi |
matrix of symmetry parameters |
delta |
scalar asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing to make pi sum to 1.0. Default is 1.0. |
derivative
Derivative of Lagrange multiplier omega wrt c.
McCullagh_derivative_omega_wrt_c(n, psi, delta, alpha, c)McCullagh_derivative_omega_wrt_c(n, psi, delta, alpha, c)
n |
matrix of observed counts |
psi |
matrix of symmetry parameters |
delta |
scalar asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
derivative
Derivative of Lagrange multiplier omega wrt scalar delta.
McCullagh_derivative_omega_wrt_delta(n, psi, delta, alpha, c = 1)McCullagh_derivative_omega_wrt_delta(n, psi, delta, alpha, c = 1)
n |
matrix of observed counts |
psi |
matrix of symmetry parameters |
delta |
scalar asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
derivative
Derivative of Lagrange multiplier omega wrt vector delta[k].
McCullagh_derivative_omega_wrt_delta_vec(n, k, psi, delta_vec, alpha, c = 1)McCullagh_derivative_omega_wrt_delta_vec(n, k, psi, delta_vec, alpha, c = 1)
n |
matrix of observed counts |
k |
index of delta_vec |
psi |
matrix of symmetry parameters |
delta_vec |
scalar asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
derivative
Derivative of Lagrange multiplier omega wrt psi[i, j].
McCullagh_derivative_omega_wrt_psi(n, i, j, psi, delta, alpha, c = 1)McCullagh_derivative_omega_wrt_psi(n, i, j, psi, delta, alpha, c = 1)
n |
matrix of observed counts |
i |
first index of psi |
j |
second index of psi |
psi |
symmetry matrix |
delta |
scalar or vector asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Defaults to 1.0 |
Derivative of phi wrt gamma.
McCullagh_derivative_phi_wrt_gamma(gamma, j)McCullagh_derivative_phi_wrt_gamma(gamma, j)
gamma |
vector of gamma values |
j |
index of gamma for which to compute the derivative |
derivative
Derivative of pi[i, j] wrt alpha[index].
McCullagh_derivative_pi_wrt_alpha(i, j, index, psi, delta, alpha, c = 1)McCullagh_derivative_pi_wrt_alpha(i, j, index, psi, delta, alpha, c = 1)
i |
row index of pi |
j |
column index of pi |
index |
index of alpha |
psi |
the matrix of symmetry parameters |
delta |
the scalar asymmetry parameter |
alpha |
the vector of asymmetry parameters |
c |
the normalizing constant for the pis to sum to 1.0 Default value is 1.0 |
derivative
Derivative pi[i, j] wrt c.
McCullagh_derivative_pi_wrt_c(i, j, psi, delta, alpha, c)McCullagh_derivative_pi_wrt_c(i, j, psi, delta, alpha, c)
i |
row index of pi |
j |
column index of pi |
psi |
the matrix of symmetry parameters |
delta |
the scalar or vector asymmetry parameter |
alpha |
the vector of asymmetry parameters |
c |
the normalizing constant for the pis to sum to 1.0 |
derivative
Derivative of pi[i, j] wrt delta.
McCullagh_derivative_pi_wrt_delta(i, j, psi, delta, alpha, c = 1)McCullagh_derivative_pi_wrt_delta(i, j, psi, delta, alpha, c = 1)
i |
row index of pi |
j |
column index of pi |
psi |
the matrix of symmetry parameters |
delta |
the scalar asymmetry parameter |
alpha |
the vector of asymmetry parameters |
c |
the normalizing constant for the pis to sum to 1.0 Default value is 1.0 |
derivative
Derivative pi[i, j] wrt delta[k].
McCullagh_derivative_pi_wrt_delta_vec(i, j, k, psi, delta_vec, alpha, c = 1)McCullagh_derivative_pi_wrt_delta_vec(i, j, k, psi, delta_vec, alpha, c = 1)
i |
row index of pi |
j |
column index of pi |
k |
index of delta_vec |
psi |
the matrix of symmetry parameters |
delta_vec |
the vector asymmetry parameter |
alpha |
the vector of asymmetry parameters |
c |
the normalizing constant for the pis to sum to 1.0 Default value is 1.0 |
derivative
Derivative of pi[i, j] wrt psi[i1, j1].
McCullagh_derivative_pi_wrt_psi(i, j, i1, j1, psi, delta, alpha, c = 1)McCullagh_derivative_pi_wrt_psi(i, j, i1, j1, psi, delta, alpha, c = 1)
i |
row index of pi |
j |
column index of pi |
i1 |
row index of psi |
j1 |
column index of psi |
psi |
the matrix of symmetry parameters |
delta |
the scalar asymmetry parameter |
alpha |
the vector of asymmetry parameters |
c |
the normalizing constant for the pis to sum to 1.0 Default value is 1.0 |
derivative
Derivative of pij[i, j] wrt alpha[index]
McCullagh_derivative_pij_wrt_alpha(i, j, index, psi, delta, alpha, c = 1)McCullagh_derivative_pij_wrt_alpha(i, j, index, psi, delta, alpha, c = 1)
i |
row index of pij |
j |
column index of pij |
index |
index of alpha |
psi |
matrix of symmetry parameters |
delta |
scalar or vector of asymmetry parameters |
alpha |
vector of asymmetry parameters |
c |
normalizing constant to make pi sum to 1.0. Default ot 1.0 |
derivative
Derivative pij[i, j] wrt c.
McCullagh_derivative_pij_wrt_c(i, j, psi, delta, alpha, c)McCullagh_derivative_pij_wrt_c(i, j, psi, delta, alpha, c)
i |
row index of pij |
j |
column index of pij |
psi |
matrix of symmetry parameters |
delta |
scalar or vector of asymmetry parameters |
alpha |
vector of asymmetry parameters |
c |
normalizing constant to make pi sum to 1.0 |
derivative
Derivative of pij[i, j] wrt scalar delta.
McCullagh_derivative_pij_wrt_delta(i, j, psi, delta, alpha, c = 1)McCullagh_derivative_pij_wrt_delta(i, j, psi, delta, alpha, c = 1)
i |
row index of pij |
j |
column index of pij |
psi |
matrix of symmetry parameters |
delta |
scalar asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing constant so that pi sum to 1.0. Default value is 1.0 |
derivative
Derivative pij[i,j] wrt vector delta[k].
McCullagh_derivative_pij_wrt_delta_vec(i, j, k, psi, delta_vec, alpha, c = 1)McCullagh_derivative_pij_wrt_delta_vec(i, j, k, psi, delta_vec, alpha, c = 1)
i |
row index of pij |
j |
column index of pij |
k |
index of delta |
psi |
the matrix of symmetry parameters |
delta_vec |
the vector asymmetry parameter |
alpha |
the vector of asymmetry parameters |
c |
the normalizing constant for the pis to sum to 1.0 Default value is 1.0 |
list containing matrices pij and qij
Derivative of pij[a, b] wrt psi[h, k]
McCullagh_derivative_pij_wrt_psi(a, b, h, k, delta, alpha, c = 1)McCullagh_derivative_pij_wrt_psi(a, b, h, k, delta, alpha, c = 1)
a |
row index of pi |
b |
column index of pi |
h |
row index of phi |
k |
column index of phi |
delta |
scalar or vector version of asymmetry parameters |
alpha |
vector of asymmetry parameters |
c |
normalizing constant for to make pi sum to 1. Defaults to 1.0 |
derivative
Extracts the weights to convert cumulative model-based probabilities to regular probabilities.
McCullagh_extract_weights(i, j, M)McCullagh_extract_weights(i, j, M)
i |
row index sought |
j |
column index sought |
M |
the number of rows/columns in observed matrix |
a list containing w_psi for when i == j w_pij for when i < j w_qij for when j < i weight populated with correct entry based on actual i and j
Fit location model
McCullagh_fit_location_regression_model(n, x, max_iter = 5, verbose = FALSE)McCullagh_fit_location_regression_model(n, x, max_iter = 5, verbose = FALSE)
n |
matrix of observed counts |
x |
design matrix for regression model |
max_iter |
maximum number of Fisher scoring iterations |
verbose |
logical: should cycle-by-cycle info be printed out? Default value is FALSE, do not print |
a list containing beta: regression parameter estimates se: matrix of estimated standard errors cov: covariance matrix of parameter estimates g_squared: G^2 likelihood ratio chi-square for model chisq: Pearson chi-square for model df: degrees of freedom
delta now is a vector, varying by index McCullagh, P. (1978). A class of parametric models for the analysis of square contingency tables with ordered categories. Biometrika, 65(2). 413-416.
McCullagh_generalized_palindromic_symmetry( n, max_iter = 15, verbose = FALSE, start_values = FALSE )McCullagh_generalized_palindromic_symmetry( n, max_iter = 15, verbose = FALSE, start_values = FALSE )
n |
matrix of observed counts |
max_iter |
maximum number of iterations to maximize log(likelihood) |
verbose |
should cycle-by-cycle information be printed out? Default is FALSE, do not print |
start_values |
logical should the regular palindomic symmetry model be fit first to get good starting values. Default is FALSE. |
a list containing
a list containing delta: the vector of asymmetry parameter delta sigma_delta: vector of SE(delta) logL: value of log(likelihood) for final estimates chisq: Pearson chi-square for solution df: degrees of freedom for solution chisq psi: matrix of symmetry parameters alpha: c: constraint, sum of pi - values condition: constraint on psi to make model identified, Lagrange multiplier SE: vector of standard errors for all parameters
McCullagh_generalized_palindromic_symmetry(vision_data)McCullagh_generalized_palindromic_symmetry(vision_data)
Computes culuative model probabilities for the generalized model using vector delta.
McCullagh_generalized_pij_qij(i, j, psi, delta_vec, alpha, c1 = 1)McCullagh_generalized_pij_qij(i, j, psi, delta_vec, alpha, c1 = 1)
i |
row index |
j |
column index |
psi |
symmetry matrix |
delta_vec |
vector of delta values |
alpha |
vector of asymmetry values |
c1 |
normalizing value for pi. Defaults to 1.0 |
model-based cumulative probability pi_ij
Generates names to label the parameters.
McCullagh_generate_names(psi, delta, alpha, c)McCullagh_generate_names(psi, delta, alpha, c)
psi |
matrix of symmetry parameters |
delta |
scalar of matrix of asymmetry parameters |
alpha |
vector of asymmetry parameters |
c |
scling factor to ensure sup of pi is 1.0 |
character vector of labels for the SE values
Computes summary statistics needed to compute estimate of delta.
McCullagh_get_statistics(m)McCullagh_get_statistics(m)
m |
matrix of observed counts |
a list containing: N: matrix of sums above and below the diagonal n: vector, size of binomial r: vector, observed sums, number of successes for binomail
Gradient vector of log(likelihood)
McCullagh_gradient_log_l(n, psi, delta, alpha, c = 1)McCullagh_gradient_log_l(n, psi, delta, alpha, c = 1)
n |
matrix of observed counts |
psi |
matrix of symmetry parameters |
delta |
scalar or vector asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
gradient vector of first-order partials wrt log(likelihood0)
Hessian matrix of log(likelihood)
McCullagh_hessian_log_l(n, psi, delta, alpha, c = 1)McCullagh_hessian_log_l(n, psi, delta, alpha, c = 1)
n |
matrix of observed counts |
psi |
matrix of symmetry parameters |
delta |
scalar or vector asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
hessian matrix of second-order partials wrt log(likelihood0)
Initializes the beta vector.
McCullagh_initialize_beta(n, c, v)McCullagh_initialize_beta(n, c, v)
n |
matrix of observed counts |
c |
number of score levels in table |
v |
number of levels of beta beyond c |
initialized beta vector
Compute initial values for scalar delta
McCullagh_initialize_delta(n)McCullagh_initialize_delta(n)
n |
matrix of observed counts |
value of delta
Initialize vector delta
McCullagh_initialize_delta_vec(n)McCullagh_initialize_delta_vec(n)
n |
matrix of observed counts |
vector of delta values
Initialize the symmetry matrix psi
McCullagh_initialize_psi(n, delta, alpha, c = 1)McCullagh_initialize_psi(n, delta, alpha, c = 1)
n |
matrix of observed counts |
delta |
scalar delta value |
alpha |
vector of asymmetry parameters |
c |
normalizing value of pi. Default is 1.0 |
matrix psi
This is the simplest possible implementation, that fits thresholds and a single group contrast. More complex problems will implement the matrix X themselves.
McCullagh_initialize_x(s, c, v)McCullagh_initialize_x(s, c, v)
s |
number of levels of stratification variable |
c |
number of score levels |
v |
number of predictors above thresholds |
design matrix X
Logical test of whether a specific psi will be in the constraint set.
McCullagh_is_in_constraint_set(i, j)McCullagh_is_in_constraint_set(i, j)
i |
first index of psi |
j |
second index of psi |
TRUE if it falls within the set, FALSE otherwise.
Test whether pi matrix is valid, i.e., 0 < all values.
McCullagh_is_pi_invalid(pi)McCullagh_is_pi_invalid(pi)
pi |
matrix of pi values to be tested. |
TRUE if all pi > 0, FALSE otherwise.
Computes the log(likelihood).
McCullagh_log_L(n, psi, delta, alpha, c = 1)McCullagh_log_L(n, psi, delta, alpha, c = 1)
n |
matrix of observed counts |
psi |
matrix of symmetry parameters |
delta |
scalar or vector asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
derivative
McCullah, P. (1977). A logistic model for paired comparisons with ordered categorical data. Biometrika, 64(3), 449-453.
McCullagh_logistic_model(m)McCullagh_logistic_model(m)
m |
matrix of observed counts |
a list containing w_tilde: vector of model weights for sum of normally distributed components delta_tilde: delta parameter computed using w_tilde w_star: vector of weights for Mantel-Haenszel type numerator and denominator delta_star: delta parameter computed using w_star var: variance of delta estimate
McCullagh_logistic_model(coal_g)McCullagh_logistic_model(coal_g)
Computed cumulative logits.
McCullagh_logits(cumulative, use_half = TRUE)McCullagh_logits(cumulative, use_half = TRUE)
cumulative |
vector of cumulative counts |
use_half |
logical indicting whether or not to add 0.5 to numerator and denominator counts before computing logits, Default value is TRUE, add 0.5. |
Maximize the log(likelihood) wrt parameters phi and alpha
McCullagh_maximize_q_symmetry(n, phi, alpha)McCullagh_maximize_q_symmetry(n, phi, alpha)
n |
matrix of observed counts |
phi |
matrix of symmetry parameters |
alpha |
vector of asymmetry parameters |
list with new values of phi and alpha
Using gradient and hessian, it finds the update direction. Then it tries increassingly smaller step sizes until the step*update yields a valid pi matrix.
McCullagh_newton_raphson_update( n, gradient, hessian, psi, delta, alpha, c = 1, max_iter = 50, verbose = FALSE )McCullagh_newton_raphson_update( n, gradient, hessian, psi, delta, alpha, c = 1, max_iter = 50, verbose = FALSE )
n |
matrix of observed counts |
gradient |
gradient vector |
hessian |
hessian matrix |
psi |
matrix of symmetry parameters |
delta |
scalar or vector of asymmetry parameters |
alpha |
vector of asymmetry parameters |
c |
scaling factor to ensure pi sums to 1.0. Default is 1.0 |
max_iter |
maximum number of iterations. Default is 50. |
verbose |
should cycle-by-cycle into be printed out. Default is FALSE, do not print. |
list containing new parameters psi: matrix of symmetry parameters delta; scalar or vector of asymmetry parameters alpha: vector of asymmetry parameters c: scaling coefficient to ensure pi sums to 1.0
McCullagh, P. (1978). A class of parametric models for the analysis of square contingency tables with ordered categories. Biometrika, 65(2). 413-416.
McCullagh_palindromic_symmetry(n, max_iter = 15, verbose = FALSE)McCullagh_palindromic_symmetry(n, max_iter = 15, verbose = FALSE)
n |
matrix of observed counts |
max_iter |
maximum number of iterations to maximize the log(likelihood) |
verbose |
should cycle-by-cycle info be printed out? Default is FALSE, don't print. |
a list containing delta: the value of the asymmetry parameter delta sigma_delta: SE(delta) logL: value of log(likelihood) for final estimates chisq: Pearson chi-square for solution df: degrees of freedom for solution chisq psi: matrix of symmetry parameters alpha: c: constraint, sum of pi - values condition: constraint on psi to make model identified, Lagrange multiplier SE: vector of standard errors for all parameters
McCullagh_palindromic_symmetry(vision_data)McCullagh_palindromic_symmetry(vision_data)
Computes the penalized value of a derivative by adding the derivative of the penalty to it.
McCullagh_penalized(derivative, i1, j1, n, psi, delta, alpha, c = 1)McCullagh_penalized(derivative, i1, j1, n, psi, delta, alpha, c = 1)
derivative |
the base derivative |
i1 |
first index of psi |
j1 |
second index of psi |
n |
matrix of observed counts |
psi |
matrix of symmetry parameters |
delta |
scalar asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
derivative
Compute model-based cumulative probabilities
McCullagh_pij_qij(i, j, psi, delta, alpha, c = 1)McCullagh_pij_qij(i, j, psi, delta, alpha, c = 1)
i |
row index |
j |
column index |
psi |
the symmetry matrix |
delta |
the asymmetry parameter |
alpha |
the vector of asymmetry parameters |
c |
the normalizing constant for pi. Default is 1.0 |
the model-based cumulative probability pi_ij
Computes the proportional hazards.
McCullagh_proportional_hazards(n)McCullagh_proportional_hazards(n)
n |
matrix of observed counts |
loga(-log(survival))
Initializes the asymmetry vector alpha
McCullagh_q_symmetry_initialize_alpha(M)McCullagh_q_symmetry_initialize_alpha(M)
M |
size of alpha vector to create = nrow(matrix to analyze) |
vector of asymmetry parameters alpha
Initializes the phi matrix
McCullagh_q_symmetry_initialize_phi(M)McCullagh_q_symmetry_initialize_phi(M)
M |
size of the psi matrix to create |
the symmetry matrix phi
Computes the model-based p-values
McCullagh_q_symmetry_pi(phi, alpha)McCullagh_q_symmetry_pi(phi, alpha)
phi |
the matrix of symmetry parameters |
alpha |
the vector of asymmetry parameters |
matrix pi of model-based p-values
McCullagh, P. (1978). A class of parametric models for the analysis of square contingency tables with ordered categories. Biometrika, 65(2) 413-418.
McCullagh_quasi_symmetry(n, max_iter = 15, verbose = FALSE)McCullagh_quasi_symmetry(n, max_iter = 15, verbose = FALSE)
n |
matrix of observed counts |
max_iter |
maximum number of iterations in maximizing log(likelihood), Default is 15. |
verbose |
should cycle-by-cycle information be printed out? Default is FALSE, do not print |
a list containing phi: symmetry matrix alpha: vector of asymmetry parameters chisq: Pearson chi-square value df; degrees of freedom
McCullagh_quasi_symmetry(vision_data)McCullagh_quasi_symmetry(vision_data)
Second derivative of Lagrangian wrt psi^2.
McCullagh_second_order_lagrangian_wrt_psi_2( n, i1, j1, i2, j2, psi, delta, alpha, c = 1 )McCullagh_second_order_lagrangian_wrt_psi_2( n, i1, j1, i2, j2, psi, delta, alpha, c = 1 )
n |
matrix of observed counts |
i1 |
first row index of psi |
j1 |
first column index of psi |
i2 |
second row index of psi |
j2 |
second column index of psi |
psi |
matrix of symmetry parameters |
delta |
scalar asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
derivative
Second derivative of Lagrangian wrt psi[i1, j1] and alpha[index].
McCullagh_second_order_lagrangian_wrt_psi_alpha( n, i1, j1, index, psi, delta, alpha, c = 1 )McCullagh_second_order_lagrangian_wrt_psi_alpha( n, i1, j1, index, psi, delta, alpha, c = 1 )
n |
matrix of observed counts |
i1 |
row index of psi |
j1 |
column index of psi |
index |
second row index of alpha |
psi |
matrix of symmetry parameters |
delta |
scalar asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
derivative
Second derivative of Lagrangian wrt psi[i1, j1] and delta.
McCullagh_second_order_lagrangian_wrt_psi_delta( n, i1, j1, psi, delta, alpha, c = 1 )McCullagh_second_order_lagrangian_wrt_psi_delta( n, i1, j1, psi, delta, alpha, c = 1 )
n |
matrix of observed counts |
i1 |
row index of psi |
j1 |
column index of psi |
psi |
matrix of symmetry parameters |
delta |
scalar asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
derivative
Second derivative of Lagrangian wrt psi[i1, j1] and delta_vec[k[.
McCullagh_second_order_lagrangian_wrt_psi_delta_vec( n, i1, j1, k, psi, delta_vec, alpha, c = 1 )McCullagh_second_order_lagrangian_wrt_psi_delta_vec( n, i1, j1, k, psi, delta_vec, alpha, c = 1 )
n |
matrix of observed counts |
i1 |
row index of psi |
j1 |
column index of psi |
k |
index of delta_vec |
psi |
matrix of symmetry parameters |
delta_vec |
vector asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
derivative
Second derivative of log(likelihood) wrt alpha^2.
McCullagh_second_order_log_l_wrt_alpha_2( n, index_a, index_b, psi, delta, alpha, c = 1 )McCullagh_second_order_log_l_wrt_alpha_2( n, index_a, index_b, psi, delta, alpha, c = 1 )
n |
matrix of observed counts |
index_a |
first index of alpha |
index_b |
second column index of alpha |
psi |
matrix of symmetry parameters |
delta |
scalar asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
derivative
Second derivative of log(likelihood) wrt alpha[index] and c.
McCullagh_second_order_log_l_wrt_alpha_c(n, index, psi, delta, alpha, c)McCullagh_second_order_log_l_wrt_alpha_c(n, index, psi, delta, alpha, c)
n |
matrix of observed counts |
index |
index of alpha |
psi |
matrix of symmetry parameters |
delta |
scalar asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. |
derivative
Appendix of McCullagh, P. (1980). Regression models for ordinal data. Journal of the Royal Statistical Society, Series B, 42(2), 109-142. and appendix B3 of Agresti, A. (1984). Analysis of ordinal categorical data, New York, Wiley, p. 242-244.
McCullagh_second_order_log_l_wrt_beta_2(n, x, gamma)McCullagh_second_order_log_l_wrt_beta_2(n, x, gamma)
n |
matrix of observed counts |
x |
design matrix for location model |
gamma |
current value of model-based cumulative logits. |
matrix of second order partial derivatives
Second derivative of log(likelihood) wrt c^2.
McCullagh_second_order_log_l_wrt_c_2(n, psi, delta, alpha, c)McCullagh_second_order_log_l_wrt_c_2(n, psi, delta, alpha, c)
n |
matrix of observed counts |
psi |
matrix of symmetry parameters |
delta |
scalar asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
derivative
Second derivative of log(likelihood) wrt delta^2.
McCullagh_second_order_log_l_wrt_delta_2(n, psi, delta, alpha, c = 1)McCullagh_second_order_log_l_wrt_delta_2(n, psi, delta, alpha, c = 1)
n |
matrix of observed counts |
psi |
matrix of symmetry parameters |
delta |
scalar asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
derivative
Second derivative of log(likelihood) wrt delta and alpha[index].
McCullagh_second_order_log_l_wrt_delta_alpha( n, index, psi, delta, alpha, c = 1 )McCullagh_second_order_log_l_wrt_delta_alpha( n, index, psi, delta, alpha, c = 1 )
n |
matrix of observed counts |
index |
index of alpha |
psi |
matrix of symmetry parameters |
delta |
scalar asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
derivative
Second derivative of log(likelihood) wrt scalar delta and c.
McCullagh_second_order_log_l_wrt_delta_c(n, psi, delta, alpha, c)McCullagh_second_order_log_l_wrt_delta_c(n, psi, delta, alpha, c)
n |
matrix of observed counts |
psi |
matrix of symmetry parameters |
delta |
scalar asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0.. |
derivative
Second derivative of log(likelihood) wrt delta_vec^2.
McCullagh_second_order_log_l_wrt_delta_vec_2( n, k1, k2, psi, delta_vec, alpha, c = 1 )McCullagh_second_order_log_l_wrt_delta_vec_2( n, k1, k2, psi, delta_vec, alpha, c = 1 )
n |
matrix of observed counts |
k1 |
first index of delta_vec |
k2 |
second index of delta_vec |
psi |
matrix of symmetry parameters |
delta_vec |
vector asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
derivative
Second derivative of log(likelihood) wrt delta[k] and alpha[index].
McCullagh_second_order_log_l_wrt_delta_vec_alpha( n, k, index, psi, delta_vec, alpha, c = 1 )McCullagh_second_order_log_l_wrt_delta_vec_alpha( n, k, index, psi, delta_vec, alpha, c = 1 )
n |
matrix of observed counts |
k |
index of delta_vec |
index |
index of alpha |
psi |
matrix of symmetry parameters |
delta_vec |
vector asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
derivative
Second derivative of log(likeloihood) wrt delta_vec[k] and c.
McCullagh_second_order_log_l_wrt_delta_vec_c(n, k, psi, delta_vec, alpha, c)McCullagh_second_order_log_l_wrt_delta_vec_c(n, k, psi, delta_vec, alpha, c)
n |
matrix of observed counts |
k |
index of delta_vec |
psi |
matrix of symmetry parameters |
delta_vec |
vector asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0 |
derivative
Expected second order derivatives of log(likelihood)
McCullagh_second_order_log_l_wrt_parms(n, x, beta)McCullagh_second_order_log_l_wrt_parms(n, x, beta)
n |
matrix of observed counts |
x |
design matrix for location model |
beta |
vector of regression parameters for location model |
matrix of expected second derivatives
Second derivative of log(likelihoood) wrt psi^2.
McCullagh_second_order_log_l_wrt_psi_2( n, i1, j1, i2, j2, psi, delta, alpha, c = 1 )McCullagh_second_order_log_l_wrt_psi_2( n, i1, j1, i2, j2, psi, delta, alpha, c = 1 )
n |
matrix of observed counts |
i1 |
first row index of psi |
j1 |
first column index of psi |
i2 |
second row index of psi |
j2 |
second column index of psi |
psi |
matrix of symmetry parameters |
delta |
scalar asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
derivative
Second derivative of log(likelihoood) wrt ps[i1, j1] and alpha[index].
McCullagh_second_order_log_l_wrt_psi_alpha( n, i1, j1, index, psi, delta, alpha, c = 1 )McCullagh_second_order_log_l_wrt_psi_alpha( n, i1, j1, index, psi, delta, alpha, c = 1 )
n |
matrix of observed counts |
i1 |
row index of psi |
j1 |
column index of psi |
index |
index of alpha |
psi |
matrix of symmetry parameters |
delta |
scalar asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
derivative
Second derivative of log(likelihood) wrt psi[i1, j1] and c.
McCullagh_second_order_log_l_wrt_psi_c(n, i1, j1, psi, delta, alpha, c)McCullagh_second_order_log_l_wrt_psi_c(n, i1, j1, psi, delta, alpha, c)
n |
matrix of observed counts |
i1 |
row index of psi |
j1 |
column index of psi |
psi |
matrix of symmetry parameters |
delta |
scalar asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. |
derivative
Second derivative of log(likelihood) wrt psi[i1, j1] and scalar delta..
McCullagh_second_order_log_l_wrt_psi_delta(n, i1, j1, psi, delta, alpha, c = 1)McCullagh_second_order_log_l_wrt_psi_delta(n, i1, j1, psi, delta, alpha, c = 1)
n |
matrix of observed counts |
i1 |
row index of psi |
j1 |
column index of psi |
psi |
matrix of symmetry parameters |
delta |
scalar asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
derivative
Second derivative of log(likelihood) wrt psi[i1, j1] and delta_vec[k].
McCullagh_second_order_log_l_wrt_psi_delta_vec( n, i1, j1, k, psi, delta_vec, alpha, c = 1 )McCullagh_second_order_log_l_wrt_psi_delta_vec( n, i1, j1, k, psi, delta_vec, alpha, c = 1 )
n |
matrix of observed counts |
i1 |
row index of psi |
j1 |
column index of psi |
k |
second row index of delta |
psi |
matrix of symmetry parameters |
delta_vec |
vector asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
derivative
Second derivative of Lagrange multiplier omega wrt alpha^2.
McCullagh_second_order_omega_wrt_alpha_2(n, k1, k2, psi, delta, alpha, c = 1)McCullagh_second_order_omega_wrt_alpha_2(n, k1, k2, psi, delta, alpha, c = 1)
n |
matrix of observed counts |
k1 |
first index of alpha |
k2 |
second index of alpha |
psi |
matrix of symmetry parameters |
delta |
scalar asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
derivative
Second derivative of Lagrange multiplier omega wrt alpha[index] and c.
McCullagh_second_order_omega_wrt_alpha_c(n, index, psi, delta, alpha, c)McCullagh_second_order_omega_wrt_alpha_c(n, index, psi, delta, alpha, c)
n |
matrix of observed counts |
index |
row index of psi |
psi |
matrix of symmetry parameters |
delta |
scalar asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. |
derivative
Second derivative of Lagrange multiplier omega wrt c^2.
McCullagh_second_order_omega_wrt_c_2(n, psi, delta, alpha, c)McCullagh_second_order_omega_wrt_c_2(n, psi, delta, alpha, c)
n |
matrix of observed counts |
psi |
matrix of symmetry parameters |
delta |
scalar asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. |
derivative
Second derivative of Lagrange multiplier omega wrt scalae delta^2.
McCullagh_second_order_omega_wrt_delta_2(n, psi, delta, alpha, c = 1)McCullagh_second_order_omega_wrt_delta_2(n, psi, delta, alpha, c = 1)
n |
matrix of observed counts |
psi |
matrix of symmetry parameters |
delta |
scalar asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
derivative
Second derivative of Lagrange multiplier omega wrt delta and alpha[index].
McCullagh_second_order_omega_wrt_delta_alpha( n, index, psi, delta, alpha, c = 1 )McCullagh_second_order_omega_wrt_delta_alpha( n, index, psi, delta, alpha, c = 1 )
n |
matrix of observed counts |
index |
index of alpha |
psi |
matrix of symmetry parameters |
delta |
scalar asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
derivative
Second derivative of Lagrange multiplier omega wrt scalar delta and c.
McCullagh_second_order_omega_wrt_delta_c(n, psi, delta, alpha, c)McCullagh_second_order_omega_wrt_delta_c(n, psi, delta, alpha, c)
n |
matrix of observed counts |
psi |
matrix of symmetry parameters |
delta |
scalar asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
derivative
Second derivative of Lagrange multiplier omega wrt delta_vec^2.
McCullagh_second_order_omega_wrt_delta_vec_2( n, k1, k2, psi, delta_vec, alpha, c = 1 )McCullagh_second_order_omega_wrt_delta_vec_2( n, k1, k2, psi, delta_vec, alpha, c = 1 )
n |
matrix of observed counts |
k1 |
first index of delta_vec |
k2 |
second index of delta_vec |
psi |
matrix of symmetry parameters |
delta_vec |
vector asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
derivative
Second derivative of Lagrange multiplier omega wrt delta_vec[k] and alpha[index].
McCullagh_second_order_omega_wrt_delta_vec_alpha( n, k, index, psi, delta_vec, alpha, c = 1 )McCullagh_second_order_omega_wrt_delta_vec_alpha( n, k, index, psi, delta_vec, alpha, c = 1 )
n |
matrix of observed counts |
k |
index of delta_vec |
index |
index of alpha |
psi |
matrix of symmetry parameters |
delta_vec |
vector asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
derivative
Second derivative of Lagrange multiplier omega wrt delta_vec[k] and c.
McCullagh_second_order_omega_wrt_delta_vec_c(n, k, psi, delta_vec, alpha, c)McCullagh_second_order_omega_wrt_delta_vec_c(n, k, psi, delta_vec, alpha, c)
n |
matrix of observed counts |
k |
index of delta_vec |
psi |
matrix of symmetry parameters |
delta_vec |
vector of asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. |
derivative
Second derivative of Lagrange multiplier omega wrt psi^2.
McCullagh_second_order_omega_wrt_psi_2( n, i1, j1, i2, j2, psi, delta, alpha, c = 1 )McCullagh_second_order_omega_wrt_psi_2( n, i1, j1, i2, j2, psi, delta, alpha, c = 1 )
n |
matrix of observed counts |
i1 |
first row index of psi |
j1 |
first column index of psi |
i2 |
second row index of psi |
j2 |
second column index of psi |
psi |
matrix of symmetry parameters |
delta |
scalar asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
derivative
Second derivative of Lagrange multiplier omega wrt psi[i1, j1] and alpha[index].
McCullagh_second_order_omega_wrt_psi_alpha( n, i1, j1, index, psi, delta, alpha, c = 1 )McCullagh_second_order_omega_wrt_psi_alpha( n, i1, j1, index, psi, delta, alpha, c = 1 )
n |
matrix of observed counts |
i1 |
row index of psi |
j1 |
column index of psi |
index |
index of alpha |
psi |
matrix of symmetry parameters |
delta |
scalar asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
derivative
Second derivative of Lagrange multiplier omega wrt psi[i1, j1] and c.
McCullagh_second_order_omega_wrt_psi_c(n, i1, j1, psi, delta, alpha, c)McCullagh_second_order_omega_wrt_psi_c(n, i1, j1, psi, delta, alpha, c)
n |
matrix of observed counts |
i1 |
row index of psi |
j1 |
column index of psi |
psi |
matrix of symmetry parameters |
delta |
scalar asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
derivative
Second derivative of Lagrange multiplier omega wrt psi and scalar delta.
McCullagh_second_order_omega_wrt_psi_delta(n, i1, j1, psi, delta, alpha, c = 1)McCullagh_second_order_omega_wrt_psi_delta(n, i1, j1, psi, delta, alpha, c = 1)
n |
matrix of observed counts |
i1 |
row index of psi |
j1 |
column index of psi |
psi |
matrix of symmetry parameters |
delta |
scalar asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
derivative
Second derivative of Lagrange multiplier omega wrt psi[i1, j1] and delta_vec[k].
McCullagh_second_order_omega_wrt_psi_delta_vec( n, i1, j1, k, psi, delta_vec, alpha, c = 1 )McCullagh_second_order_omega_wrt_psi_delta_vec( n, i1, j1, k, psi, delta_vec, alpha, c = 1 )
n |
matrix of observed counts |
i1 |
row index of psi |
j1 |
column index of psi |
k |
index of delta_vec |
psi |
matrix of symmetry parameters |
delta_vec |
vector asymmetry parameter |
alpha |
vector of asymmetry parameters |
c |
normalizing factor to make pi sum to 1.0. Default is 1.0. |
derivative
Second derivative of pi[i, j] wrt alpha^2.
McCullagh_second_order_pi_wrt_alpha_2( i, j, index1, index2, psi, delta, alpha, c = 1 )McCullagh_second_order_pi_wrt_alpha_2( i, j, index1, index2, psi, delta, alpha, c = 1 )
i |
row index of pi |
j |
column index of pi |
index1 |
index of first alpha |
index2 |
index of second aloha |
psi |
the matrix of symmetry parameters |
delta |
the scalar asymmetry parameter |
alpha |
the vector of asymmetry parameters |
c |
the normalizing constant for the pis to sum to 1.0 Default value is 1.0 |
derivative
Second derivaitve of pi[i, j] wrt alpha[index] and c.
McCullagh_second_order_pi_wrt_alpha_c(i, j, index, psi, delta, alpha, c)McCullagh_second_order_pi_wrt_alpha_c(i, j, index, psi, delta, alpha, c)
i |
row index of pi |
j |
column index of pi |
index |
index of alpha |
psi |
the matrix of symmetry parameters |
delta |
the scalar asymmetry parameter |
alpha |
the vector of asymmetry parameters |
c |
the normalizing constant for the pis to sum to 1.0 |
derivative
Second order derivative of pi[i, j] wrt c^2.
McCullagh_second_order_pi_wrt_c_2(i, j, psi, delta, alpha, c)McCullagh_second_order_pi_wrt_c_2(i, j, psi, delta, alpha, c)
i |
row index of pi |
j |
column index of pi |
psi |
the matrix of symmetry parameters |
delta |
the scalar asymmetry parameter |
alpha |
the vector of asymmetry parameters |
c |
the normalizing constant for the pis to sum to 1.0 Default value is 1.0 |
derivative
Second order derivative of pi[i, j] wrt scalar delta.
McCullagh_second_order_pi_wrt_delta_2(i, j, psi, delta, alpha, c = 1)McCullagh_second_order_pi_wrt_delta_2(i, j, psi, delta, alpha, c = 1)
i |
row index of pi |
j |
column index of pi |
psi |
the matrix of symmetry parameters |
delta |
the scalar asymmetry parameter |
alpha |
the vector of asymmetry parameters |
c |
the normalizing constant for the pis to sum to 1.0 Default value is 1.0 |
derivative
Second order deriviative of pi[i, j] wrt scalar delta and alpha[index]
McCullagh_second_order_pi_wrt_delta_alpha( i, j, index, psi, delta, alpha, c = 1 )McCullagh_second_order_pi_wrt_delta_alpha( i, j, index, psi, delta, alpha, c = 1 )
i |
row index of pi |
j |
column index of pi |
index |
index of alpha |
psi |
the matrix of symmetry parameters |
delta |
the scalar asymmetry parameter |
alpha |
the vector of asymmetry parameters |
c |
the normalizing constant for the pis to sum to 1.0 Default value is 1.0 |
derivative
Second order derivative of pi[i, j] wrt scalae delta and c.
McCullagh_second_order_pi_wrt_delta_c(i, j, psi, delta, alpha, c)McCullagh_second_order_pi_wrt_delta_c(i, j, psi, delta, alpha, c)
i |
row index of pi |
j |
column index of pi |
psi |
the matrix of symmetry parameters |
delta |
the scalar asymmetry parameter |
alpha |
the vector of asymmetry parameters |
c |
the normalizing constant for the pis to sum to 1.0 |
derivative
Derivative of pi[i, j] wrt delta^2.
McCullagh_second_order_pi_wrt_delta_vec_2( i, j, k1, k2, psi, delta_vec, alpha, c = 1 )McCullagh_second_order_pi_wrt_delta_vec_2( i, j, k1, k2, psi, delta_vec, alpha, c = 1 )
i |
row index of pi |
j |
column index of pi |
k1 |
first index of delta |
k2 |
second index of delta |
psi |
the matrix of symmetry parameters |
delta_vec |
the vector asymmetry parameter |
alpha |
the vector of asymmetry parameters |
c |
the normalizing constant for the pis to sum to 1.0 Default value is 1.0 |
derivative
Second order dertivative of pi[i, j] wrtt delta[k] alpha[index].
McCullagh_second_order_pi_wrt_delta_vec_alpha( i, j, k, index, psi, delta_vec, alpha, c = 1 )McCullagh_second_order_pi_wrt_delta_vec_alpha( i, j, k, index, psi, delta_vec, alpha, c = 1 )
i |
row index of pi |
j |
column index of pi |
k |
index of delta |
index |
index of alpha |
psi |
the matrix of symmetry parameters |
delta_vec |
the vector asymmetry parameter |
alpha |
the vector of asymmetry parameters |
c |
the normalizing constant for the pis to sum to 1.0 Default value is 1.0 |
derivative
Second derivative of pi[i, j] wrt delta[k] and c.
McCullagh_second_order_pi_wrt_delta_vec_c(i, j, k, psi, delta_vec, alpha, c)McCullagh_second_order_pi_wrt_delta_vec_c(i, j, k, psi, delta_vec, alpha, c)
i |
row index of pi |
j |
column index of pi |
k |
index of delta |
psi |
the matrix of symmetry parameters |
delta_vec |
the vector asymmetry parameter |
alpha |
the vector of asymmetry parameters |
c |
the normalizing constant for the pis to sum to 1.0 Default value is 1.0 |
derivative
Second order derivative wrt psi^2.
McCullagh_second_order_pi_wrt_psi_2( i, j, i1, j1, i2, j2, psi, delta, alpha, c = 1 )McCullagh_second_order_pi_wrt_psi_2( i, j, i1, j1, i2, j2, psi, delta, alpha, c = 1 )
i |
row index of pi |
j |
column index of pi |
i1 |
first row index of psi |
j1 |
first column index of psi |
i2 |
second row index of psi |
j2 |
second column index of pis |
psi |
the matrix of symmetry parameters |
delta |
the scalar asymmetry parameter |
alpha |
the vector of asymmetry parameters |
c |
the normalizing constant for the pis to sum to 1.0 Default value is 1.0 |
derivative
Second order derivative of pi[i, j] wrt psi[i1, j1] and alpha[index].
McCullagh_second_order_pi_wrt_psi_alpha( i, j, i1, j1, index, psi, delta, alpha, c = 1 )McCullagh_second_order_pi_wrt_psi_alpha( i, j, i1, j1, index, psi, delta, alpha, c = 1 )
i |
row index of pi |
j |
column index of pi |
i1 |
row index of psi |
j1 |
column index of psi |
index |
index of alpha |
psi |
the matrix of symmetry parameters |
delta |
the scalar asymmetry parameter |
alpha |
the vector of asymmetry parameters |
c |
the normalizing constant for the pis to sum to 1.0 Default value is 1.0 |
derivative
Second order derivative of pi[i, j] wrt psi[i1, j1] and c.
McCullagh_second_order_pi_wrt_psi_c(i, j, i1, j1, psi, delta, alpha, c)McCullagh_second_order_pi_wrt_psi_c(i, j, i1, j1, psi, delta, alpha, c)
i |
row index of pi |
j |
column index of pi |
i1 |
row index of psi |
j1 |
column index of psi |
psi |
the matrix of symmetry parameters |
delta |
the scalar asymmetry parameter |
alpha |
the vector of asymmetry parameters |
c |
the normalizing constant for the pis to sum to 1.0 |
derivative
Second order derivaitve of pi wrt pshi and scalar delta.
McCullagh_second_order_pi_wrt_psi_delta(i, j, i1, j1, psi, delta, alpha, c = 1)McCullagh_second_order_pi_wrt_psi_delta(i, j, i1, j1, psi, delta, alpha, c = 1)
i |
row index of pi |
j |
column index of pi |
i1 |
row index of psi |
j1 |
column index of psi |
psi |
the matrix of symmetry parameters |
delta |
the scalar asymmetry parameter |
alpha |
the vector of asymmetry parameters |
c |
the normalizing constant for the pis to sum to 1.0 Default value is 1.0 |
derivative
Second order derivaitve of pi[i, j] wrt psi[i1, j1] and kelta[k].
McCullagh_second_order_pi_wrt_psi_delta_vec( i, j, i1, j1, k, psi, delta_vec, alpha, c = 1 )McCullagh_second_order_pi_wrt_psi_delta_vec( i, j, i1, j1, k, psi, delta_vec, alpha, c = 1 )
i |
row index of pi |
j |
column index of pi |
i1 |
row index of psi |
j1 |
column index of psi |
k |
index of delta |
psi |
the matrix of symmetry parameters |
delta_vec |
the vector asymmetry parameter |
alpha |
the vector of asymmetry parameters |
c |
the normalizing constant for the pis to sum to 1.0 Default value is 1.0 |
derivative
Update the parameters based on Newton-Raphson step.
McCullagh_update_parameters(update, step, psi, delta, alpha, c = 1)McCullagh_update_parameters(update, step, psi, delta, alpha, c = 1)
update |
vector of update values |
step |
size of candidate step along direction of update |
psi |
vector of symmetry parameters |
delta |
scalar or vector of asymmetry parameters |
alpha |
vector of asymmetry parameters |
c |
normalization factor to make sum pf pi = 1.0. Default value is 1.0. |
list containing new parameters psi: matrix of symmetry parameters delta; scalar or vector of asymmetry parameters alpha: vector of asymmetry parameters c: scaling coefficient to ensure pi sums to 1.0
Compute v_inverse (from appendix).
McCullagh_v_inverse(gamma, i, j)McCullagh_v_inverse(gamma, i, j)
gamma |
matrix of cumulative logits |
i |
row index |
j |
column index |
V^(-1) : d phi / d gamma[i, j]
Rows are child's mental health (ranging from 1 = well to 4 = impaired), and columns are parents' socioeconomic status, A - F.
mental_healthmental_health
## 'mental_health' A matrix with 4 rows and 6 columns
Goodman, L. A. (1979). Simple models for the analysis of association in cross-classifications having ordered categories.
Computes the column association values theta-hat
model_i_column_theta(fHat)model_i_column_theta(fHat)
fHat |
matrix of model-based expected counts |
thetaHat vector of association parameters
Gets the overall effects for Model I.
model_i_effects(result)model_i_effects(result)
result |
a Model I result object |
a list containing theta: the overall association zeta_i_dot: row effects for association zeta_dot_j: column effects for association
Computes model-based expected cell counts for Model I
model_i_fHat(alpha, beta, gamma, delta)model_i_fHat(alpha, beta, gamma, delta)
alpha |
row effects |
beta |
column effects |
gamma |
row location weights |
delta |
column location weights |
matrix of model-based expected counts
Normalizes pi(fHat) to sum to 1.0. If exclude_diagonal is TRUE, the sum of the off-diagonal terms sums to 1.0.
model_i_normalize_fHat(fHat, exclude_diagonal = FALSE)model_i_normalize_fHat(fHat, exclude_diagonal = FALSE)
fHat |
matrix of model-based cell frequencies |
exclude_diagonal |
logical. Should the cells on the main diagonal be excluded? Default is FALSE, include all cells |
matrix of model-based proportions pi
Computes the table of adjacent odds-ratios theta-hat.
model_i_row_column_odds_ratios(fHat)model_i_row_column_odds_ratios(fHat)
fHat |
matrix of model-based expected counts |
thetaHat matrix of adjacent odds-ratios
Computes the row association values theta-hat
model_i_row_theta(fHat)model_i_row_theta(fHat)
fHat |
matrix of model-based expected counts |
thetaHat vector of association parameters
Gets the Model I* effects.
model_i_star_effects(result)model_i_star_effects(result)
result |
a Model I* effect object |
a list containing theta: the overall association zeta: the row/column effect
Computes expected frequencies for Model I*
model_i_star_fHat(alpha, beta, theta)model_i_star_fHat(alpha, beta, theta)
alpha |
row effect parameters |
beta |
column effect parameters |
theta |
row/column parameters |
matrix of model-based expected cell counts
Updates the row/column parameters for Model I*.
model_i_star_update_theta(theta, n, fHat, exclude_diagonal = FALSE)model_i_star_update_theta(theta, n, fHat, exclude_diagonal = FALSE)
theta |
vector of estimated row/column effects |
n |
matrix of observed counts |
fHat |
matrix of model-based expected frequencies |
exclude_diagonal |
should the cells of the main diagonal be excluded? Default is FALSE, include all cells |
new value of theta vector
Computes crude starting values for Model I.
model_i_starting_values(n)model_i_starting_values(n)
n |
matrix of observed counts |
a list containing alpha: vector of row parameters beta: vector of column parameters gamma: vector of row locations delta: vector of column locations
Updates the estimate of the alpha vector for Model I
model_i_update_alpha(alpha, n, fHat, exclude_diagonal = FALSE)model_i_update_alpha(alpha, n, fHat, exclude_diagonal = FALSE)
alpha |
current estimate of beta |
n |
matrix of observed counts |
fHat |
current model-based counts for each cell |
exclude_diagonal |
logical. Should the diagonal be excluded from the computation? Default is FALSE, use all cells. |
updated estimate of alpha vector
Updates the estimate of the beta vector for Model I
model_i_update_beta(beta, n, fHat, exclude_diagonal = FALSE)model_i_update_beta(beta, n, fHat, exclude_diagonal = FALSE)
beta |
current estimate of alpha |
n |
matrix of observed counts |
fHat |
current model-based counts for each cell |
exclude_diagonal |
logical. Should the diagonal be excluded from the computation? Default is FALSE, use all cells |
updated estimate of beta vector
Updates the estimate of the delta vector for Model I
model_i_update_delta(delta, n, fHat, exclude_diagonal = FALSE)model_i_update_delta(delta, n, fHat, exclude_diagonal = FALSE)
delta |
current estimate of delta |
n |
matrix of observed counts |
fHat |
current model-based counts for each cell |
exclude_diagonal |
logical. Should the diagonal be excluded from the computation? Default is FALSE, use all cells |
updated estimate of delta vector
Updates the estimate of the gamma vector for Model I
model_i_update_gamma(gamma, n, fHat, exclude_diagonal = FALSE)model_i_update_gamma(gamma, n, fHat, exclude_diagonal = FALSE)
gamma |
current estimate of gamma |
n |
matrix of observed counts |
fHat |
current model-based counts for each cell |
exclude_diagonal |
logical. Should the diagonal be excluded from the computation? Default is FALSE, use all cells |
updated estimate of gamma vector
Computes the overall association theta and the row and column effects zeta
model_i_zeta(odds)model_i_zeta(odds)
odds |
matrix of adjacent odds-ratios |
a list containing theta: the overall association zeta_i_dot: row effects for association zeta_dot_j: column effects for association
Gets the effects phi, ksi_i_dot and ksi_dot_j for Model II results.
model_ii_effects(result)model_ii_effects(result)
result |
a result object from Model II |
a list containing: phi: the overall effect ksi_i_dot: the row effects ksi_dot_j: the column effects
Computes expected counts for Model II
model_ii_fHat(alpha, beta, rho, sigma)model_ii_fHat(alpha, beta, rho, sigma)
alpha |
row effects |
beta |
column effects |
rho |
row locations |
sigma |
column locations |
matrix of model-based expected counts
Gets the effects phi, ksi_i_dot and ksi_dot_j for Model II matrix of odds-ratios.
model_ii_ksi(odds)model_ii_ksi(odds)
odds |
matrix of adjacent odds-ratios |
a list containing: phi: the overall effect in log metric ksi_i_dot: the row effects ksi_dot_j: the column effects
Gets the effects for Model II*
model_ii_star_effects(result)model_ii_star_effects(result)
result |
a Model II* result object |
a list containing phi: common effect in log metric ksi: vector of ksi parameters
Computes expected counts for Model II*
model_ii_star_fHat(alpha, beta, phi)model_ii_star_fHat(alpha, beta, phi)
alpha |
row effects |
beta |
column effects |
phi |
row/column locations |
matrix of model-based expected counts
Updates estimate of phi vector
model_ii_star_update_phi(n, fHat, mu, phi, exclude_diagonal = FALSE)model_ii_star_update_phi(n, fHat, mu, phi, exclude_diagonal = FALSE)
n |
matrix of observed counts |
fHat |
current model-based counts for each cell |
mu |
alternative row coefficients |
phi |
vector of column location parameters |
exclude_diagonal |
logical, Should the cells on the main diagonal be excluded? Default is FALSE, use all cells |
list containing: phi: updated estimate of the phi vector mu: updated estimate of vector mu
Computes crude starting values for Model II
model_ii_starting_values(n)model_ii_starting_values(n)
n |
matrix of observed counts |
a list containing alpha: vector of row parameters beta: vector of column parameters rho: row coefficients sigma: column coefficients mu: alternative row coefficients nu: alternative column coefficients
Updates the estimate of the alpha vector for Model II
model_ii_update_alpha(alpha, n, fHat, exclude_diagonal = FALSE)model_ii_update_alpha(alpha, n, fHat, exclude_diagonal = FALSE)
alpha |
current estimate of alpha |
n |
matrix of observed counts |
fHat |
current model-based counts for each cell |
exclude_diagonal |
logical, Should the cells on the main diagonal be excluded? Default is FALSE, use all cells |
updated estimate of alpha vector
Updates the estimate of the beta vector for Model II
model_ii_update_beta(beta, n, fHat, exclude_diagonal = FALSE)model_ii_update_beta(beta, n, fHat, exclude_diagonal = FALSE)
beta |
current estimate of beta |
n |
matrix of observed counts |
fHat |
current model-based counts for each cell |
exclude_diagonal |
logical, Should the cells on the main diagonal be excluded? Default is FALSE, use all cells |
updated estimate of beta vector
Updates the estimate of the rho vector for Model II
model_ii_update_rho(n, fHat, mu, sigma, exclude_diagonal = FALSE)model_ii_update_rho(n, fHat, mu, sigma, exclude_diagonal = FALSE)
n |
matrix of observed counts |
fHat |
current model-based counts for each cell |
mu |
alternative row coefficients |
sigma |
vector of column location parameters |
exclude_diagonal |
logical, Should the cells on the main diagonal be excluded? Default is FALSE, use all cells |
updated estimate of alpha vector
Updates the estimate of the sigma vector for Model II
model_ii_update_sigma(n, fHat, nu, rho, exclude_diagonal = FALSE)model_ii_update_sigma(n, fHat, nu, rho, exclude_diagonal = FALSE)
n |
matrix of observed counts |
fHat |
current model-based counts for each cell |
nu |
vector of column coefficients |
rho |
vector of row location parameters |
exclude_diagonal |
logical, Should the cells on the main diagonal be excluded? Default is FALSE, use all cells |
updated estimate of sigma vector
Movie ratings by two film critics, Siskel and Ebert.
moviesmovies
## 'movies' A matrix with 3 rows and 3 columns 1 is con 2 is mixed 3 is pro
https://online.stat.psu.edu/stat504/lesson/11/11.3
See companion winnipeg_data.
new_orleans_datanew_orleans_data
## 'new_orleans_data' A matrix with 4 rows and 4 columns Ratings range from definite presence of disease to definite absence.
???
Computes expected counts for null association model
null_association_fHat(alpha, beta)null_association_fHat(alpha, beta)
alpha |
row effects |
beta |
column effects |
matrix of model-based expected counts
Higher numbers correspond to higher status occupation
occupational_statusoccupational_status
## 'occupational_status' A matrix with 6 rows and 6 columns
???
Severity corresponds to level 1 low 3 high
paranoiaparanoia
## 'paranoia' A matrix with 3 rows and 3 columns.
von Eye, A. & Mun, E. Y. (2005, p. 70). Analyzing rater agreement: Manifest variable methods. Mahwah, NJ: Lawrence Erlbaum.
Computes the Pearson X^2 statistic.
pearson_chisq(n, pi, exclude_diagonal = FALSE)pearson_chisq(n, pi, exclude_diagonal = FALSE)
n |
Matrix of observed counts |
pi |
Matrix with same dimensions as n. Model-based matrix of predicted proportions |
exclude_diagonal |
logical. Should diagonal cells of square matrix be excluded from the computation? Default is FALSE. The effect of setting it to TRUE for non-square matrices may be unintuitive and should he avoided. |
X^2
The data contains a comparison vector of (simulated) covariate data.
radiologyradiology
## 'radiology' 'covariate' A matrix with 4 rows and 4 columns, and a vector of 16 elements.
von Eye, A. & Mun, E. Y. (2005, p. 60). Analyzing rater agreement: Manifest variable methods. Mahwah, NJ: Lawrence Erlbaum.
Computes the degrees of freedom for the model.
Schuster_compute_df(pi_margin)Schuster_compute_df(pi_margin)
pi_margin |
expected proportions for each of the categories |
the df for the model
Compute matrix of model-based proportions pi.
Schuster_compute_pi(marginal_pi, kappa, v, validate = TRUE)Schuster_compute_pi(marginal_pi, kappa, v, validate = TRUE)
marginal_pi |
expected proportions for each category |
kappa |
current estimate of the kappa coefficient |
v |
symmetry matrix |
validate |
logical. should the cells be validated within this function? Defaults to TRUE |
matrix of model-based cell proportions
Patterned after example in code in appendix to article
Schuster_compute_starting_values(n)Schuster_compute_starting_values(n)
n |
matrix of observed counts |
a list containing marginal_pi: vector of expected proportions for each category kappa: kappa coefficient of agreement v: matrix of symmetry parameters
Derivative of log(likelihood) wrt kappa.
Schuster_derivative_log_l_wrt_kappa(n, marginal_pi, kappa, v)Schuster_derivative_log_l_wrt_kappa(n, marginal_pi, kappa, v)
n |
matrix of observed counts |
marginal_pi |
expected proportions for each category |
kappa |
current value of kappa coefficient |
v |
symmetry matrix |
derivative of log(L) wrt kappa
Derivative of log(likelihood) wrt marginal_pi[k]
Schuster_derivative_log_l_wrt_marginal_pi(n, k, marginal_pi, kappa, v)Schuster_derivative_log_l_wrt_marginal_pi(n, k, marginal_pi, kappa, v)
n |
matrix of observed counts |
k |
index into marginal_pi |
marginal_pi |
expected proportions of each of the categories |
kappa |
current value of the kappa coefficient |
v |
symmetry matrix |
derivative of log(L) wrt marginal_pi[k]
Derivative of log(likelihood) wrt v[i1, j1]
Schuster_derivative_log_l_wrt_v(n, i1, j1, marginal_pi, kappa, v)Schuster_derivative_log_l_wrt_v(n, i1, j1, marginal_pi, kappa, v)
n |
matrix of observed counts |
i1 |
first index into v |
j1 |
second index into v |
marginal_pi |
expected marginal proportions |
kappa |
current value of kappa coefficient |
v |
symmetry matrix |
derivative of log(L) wrt v[i1, j1]
Derivative of pi[i, j] wrt kappa coefficient.
Schuster_derivative_pi_wrt_kappa(i, j, marginal_pi, kappa, v)Schuster_derivative_pi_wrt_kappa(i, j, marginal_pi, kappa, v)
i |
first index into pi |
j |
second index into pi |
marginal_pi |
expected proportions in each category |
kappa |
current value of kappa coefficient |
v |
symmetry matrix |
the derivative of pi[i, j] wrt kappa
Derivative of pi[i, j] wrt marginal_pi[k].
Schuster_derivative_pi_wrt_marginal_pi(i, j, k, marginal_pi, kappa, v)Schuster_derivative_pi_wrt_marginal_pi(i, j, k, marginal_pi, kappa, v)
i |
first index into pi |
j |
second index into pi |
k |
index into marginal_pi |
marginal_pi |
expected proportions for each category |
kappa |
current estimate of kappa coefficient |
v |
symmetry matrix |
derivative of pi[i, j] wrt marginal_pi[k]
Computes derivative of pi[i, j] wrt v[i1, j1]
Schuster_derivative_pi_wrt_v(i, j, i1, j1, marginal_pi, kappa, v)Schuster_derivative_pi_wrt_v(i, j, i1, j1, marginal_pi, kappa, v)
i |
first index into pi |
j |
second index into pi |
i1 |
first index into v |
j1 |
second index into v |
marginal_pi |
expected marginal proportions |
kappa |
current estimate of kappa coefficient |
v |
symmetry matrix |
value of derivative of specified pi wrt specified element of v
Needed because of computed v terms in column r
Schuster_derivative_v_wrt_v(i1, j1, i2, j2, marginal_pi, kappa, v)Schuster_derivative_v_wrt_v(i1, j1, i2, j2, marginal_pi, kappa, v)
i1 |
first index into target v |
j1 |
second index into target v |
i2 |
first index into |
j2 |
second index into |
marginal_pi |
expected marginal proportions |
kappa |
current estimate of kappa coefficient |
v |
matrix of symmetry parameters |
derivative of v[i1, j1] wrt v[i2, j2]
Compute v matrix subject to constraints on rows 1..r-1.
Schuster_enforce_constraints_on_v(marginal_pi, kappa, v)Schuster_enforce_constraints_on_v(marginal_pi, kappa, v)
marginal_pi |
expected proportions for each category |
kappa |
current estimate of kappa coefficient |
v |
symmetry matrix |
new v matrix with last row/column set to agree with constraints. Element v[r, r] is set to v-tilde
Work is delegated to functions that compute partial derivatives. This function is responsible for laying them out in correct positions in the vector.
Schuster_gradient(n, marginal_pi, kappa, v)Schuster_gradient(n, marginal_pi, kappa, v)
n |
matrix of observed counts |
marginal_pi |
expected proportions for each response category |
kappa |
current estimate of kappa coefficient |
v |
symmetry matrix |
gradient vector
Work is delegated to functions that compute second-order partial derivatives. This function is responsible for laying them out in correct positions in the matrix.
Schuster_hessian(n, marginal_pi, kappa, v)Schuster_hessian(n, marginal_pi, kappa, v)
n |
matrix of observed counts |
marginal_pi |
expected proportions for each category |
kappa |
current estimate of the kappa coefficient |
v |
symmetry matrix |
hessian matrix
All elements must lie in (0, 1)
Schuster_is_pi_valid(pi)Schuster_is_pi_valid(pi)
pi |
matrix of model-based proportions |
logical value indicating whether or not the matrix is valid.
The step size is determined to be the largest that yields valid results for all quantities marginal_pi and v. Both must be positive, and the elements of marginal_pi must be valid proportions that sum to 1.0.
Schuster_newton_raphson(n, marginal_pi, kappa, v)Schuster_newton_raphson(n, marginal_pi, kappa, v)
n |
matrix of observed counts |
marginal_pi |
expected proportions for each category |
kappa |
current estimate of the kappa coefficient |
v |
symmetry matrix |
a list containing updated versions of model quantities marginal_pi kappa v
Second order partial log(L) wrt kappa^2.
Schuster_second_deriv_log_l_wrt_kappa_2(n, marginal_pi, kappa, v)Schuster_second_deriv_log_l_wrt_kappa_2(n, marginal_pi, kappa, v)
n |
matrix of observed counts |
marginal_pi |
expected proportions for each response category |
kappa |
current estimate of kappa coefficient |
v |
symmetry matrix second derivative of log(L) wrt kappa^2 |
Second order partial log(L) wrt kappa and v.
Schuster_second_deriv_log_l_wrt_kappa_v(n, marginal_pi, kappa, v)Schuster_second_deriv_log_l_wrt_kappa_v(n, marginal_pi, kappa, v)
n |
matrix of observed counts |
marginal_pi |
expected proportions for each response category |
kappa |
current estimate of kappa coefficient |
v |
symmetry matrix second derivative of log(L) wrt kappa and v |
Second order partial log(L) wrt marginal_pi^2.
Schuster_second_deriv_log_l_wrt_marginal_pi_2(n, marginal_pi, kappa, v)Schuster_second_deriv_log_l_wrt_marginal_pi_2(n, marginal_pi, kappa, v)
n |
matrix of observed counts |
marginal_pi |
expected proportions for each response category |
kappa |
current estimate of kappa coefficient |
v |
symmetry matrix second derivative of log(L) wrt marginal_pi^2 |
Second order partial log(L) wrt marginal_pi and kappa.
Schuster_second_deriv_log_l_wrt_marginal_pi_kappa(n, marginal_pi, kappa, v)Schuster_second_deriv_log_l_wrt_marginal_pi_kappa(n, marginal_pi, kappa, v)
n |
matrix of observed counts |
marginal_pi |
expected proportions for each response category |
kappa |
current estimate of kappa coefficient |
v |
symmetry matrix second derivative of log(L) wrt marginal_pi and kappa |
Second order partial log(L) wrt marginal_pi and v.
Schuster_second_deriv_log_l_wrt_marginal_pi_v(n, marginal_pi, kappa, v)Schuster_second_deriv_log_l_wrt_marginal_pi_v(n, marginal_pi, kappa, v)
n |
matrix of observed counts |
marginal_pi |
expected proportions for each response category |
kappa |
current estimate of kappa coefficient |
v |
symmetry matrix second derivative of log(L) wrt marginal_pi and v |
Second order partial log(L) wrt v^2.
Schuster_second_deriv_log_l_wrt_v_2(n, marginal_pi, kappa, v)Schuster_second_deriv_log_l_wrt_v_2(n, marginal_pi, kappa, v)
n |
matrix of observed counts |
marginal_pi |
expected proportions for each response category |
kappa |
current estimate of kappa coefficient |
v |
symmetry matrix second derivative of log(L) wrt v^2 |
Derivative is uniformly 0
Schuster_second_deriv_pi_wrt_kappa_2(i, j, marginal_pi, kappa, v)Schuster_second_deriv_pi_wrt_kappa_2(i, j, marginal_pi, kappa, v)
i |
first index of pi |
j |
second index of pi |
marginal_pi |
expected proportions for each category |
kappa |
current estimate of the kappa coefficient |
v |
symmetry matrix |
second order partial derivative
Derivative is uniformly 0
Schuster_second_deriv_pi_wrt_kappa_v(i, j, i1, j1, marginal_pi, kappa, v)Schuster_second_deriv_pi_wrt_kappa_v(i, j, i1, j1, marginal_pi, kappa, v)
i |
first index of pi |
j |
second index of pi |
i1 |
first index of v |
j1 |
second index of v |
marginal_pi |
expected proportions for each category |
kappa |
current estimate of the kappa coefficient |
v |
symmetry matrix |
second order partial derivative
Second derivative of pi[i, j] wrt marginal_pi[k]^2
Schuster_second_deriv_pi_wrt_marginal_pi_2(i, j, k, k2, marginal_pi, kappa, v)Schuster_second_deriv_pi_wrt_marginal_pi_2(i, j, k, k2, marginal_pi, kappa, v)
i |
first index into pi |
j |
second index into pi |
k |
index into marginal_pi |
k2 |
second index into marginal_pi |
marginal_pi |
expected proportions for each category |
kappa |
current estimate of kappa coefficient |
v |
symmetry matrix |
second derivative of pi[i, j] wrt marginal_pi^2
Derivative is uniformly 0
Schuster_second_deriv_pi_wrt_marginal_pi_kappa(i, j, k, marginal_pi, kappa, v)Schuster_second_deriv_pi_wrt_marginal_pi_kappa(i, j, k, marginal_pi, kappa, v)
i |
first index of pi |
j |
second index of pi |
k |
index of marginal_pi |
marginal_pi |
expected proportions for each category |
kappa |
current estimate of the kappa coefficient |
v |
symmetry matrix |
second order partial derivative
Second order partial pi wrt marginal_pi and v
Schuster_second_deriv_pi_wrt_marginal_pi_v( i, j, k, i1, j1, marginal_pi, kappa, v )Schuster_second_deriv_pi_wrt_marginal_pi_v( i, j, k, i1, j1, marginal_pi, kappa, v )
i |
first index of pi |
j |
second index of pi |
k |
index of marginal_pi |
i1 |
first index of v |
j1 |
second index of v |
marginal_pi |
expected proportions of each of the categories |
kappa |
current value of kappa coefficient |
v |
symmetry matrix |
derivative
Derivative is uniformly 0
Schuster_second_deriv_pi_wrt_v_2(i, j, i1, j1, i2, j2, marginal_pi, kappa, v)Schuster_second_deriv_pi_wrt_v_2(i, j, i1, j1, i2, j2, marginal_pi, kappa, v)
i |
first index of pi |
j |
second index of pi |
i1 |
first index of first v |
j1 |
second index of first v |
i2 |
first index of second v |
j2 |
second index of second |
marginal_pi |
expected proportions for each category |
kappa |
current estimate of the kappa coefficient |
v |
symmetry matrix |
second order partial derivative
Solves for the last row and diagonal of symmetry matrix v (v-tilde) using constraint equations
Schuster_solve_for_v(marginal_pi, kappa, v)Schuster_solve_for_v(marginal_pi, kappa, v)
marginal_pi |
expected proportions for each category |
kappa |
current estimate of kappa coefficient |
v |
symmetry matrix |
revised version of v matrix with last row and diagonal modified
Solves for the last row and diagonal of symmetry matrix v (parameteer v-tilde) using linear algebra formulation from paper.
Schuster_solve_for_v1(marginal_pi, kappa, v)Schuster_solve_for_v1(marginal_pi, kappa, v)
marginal_pi |
expected proportions for each category |
kappa |
current estimate of kappa coefficient |
v |
symmetry matrix |
revised version of v matrix with last row and diagonal modified
Schuster, C. (2001). Kappa as a parameter of a symmetry model for rater agreement. Journal of Educational and Behavioral Statistics, 26(3), 331-342.
Schuster_symmetric_rater_agreement_model( n, verbose = FALSE, max_iter = 10000, criterion = 1e-07, min_iter = 1000 )Schuster_symmetric_rater_agreement_model( n, verbose = FALSE, max_iter = 10000, criterion = 1e-07, min_iter = 1000 )
n |
the matrix of observed counts |
verbose |
logical. should cycle-by-cycle information be printed out |
max_iter |
integer. maximum number of iterations to perform |
criterion |
number. maximum change in log(likelihood) to decide convergence |
min_iter |
integer. minimum number of iterations to perform |
a list containing marginal_pi: vector of expected proportions for each category kappa numeric: kappa coefficient v: matrix of symmetry parameters chisq: Pearson X^2 g_squared: likelihood ratio G^2 df: degrees of freedom
Computes both gradient and hessian, and then solves the system of equations
Schuster_update(n, marginal_pi, kappa, v)Schuster_update(n, marginal_pi, kappa, v)
n |
matrix of observed counts |
marginal_pi |
expected proportions for each category |
kappa |
current value of kappa coefficient |
v |
symmetry matrix |
the vector of updates
Computes the common diagonal term v-tilde.
Schuster_v_tilde(marginal_pi, kappa, validate = TRUE)Schuster_v_tilde(marginal_pi, kappa, validate = TRUE)
marginal_pi |
expected proportions for each category |
kappa |
current estimate of kappa coefficient |
validate |
logical. should the value of pi[r,r] be checked for validity? Default is TRUE |
v-tilde
Social mobility data with father's occupational social status and son's occupational social status. * categories instead of 7 in social status..
social_status2social_status2
## 'social_status2' A matrix with 8 rows and 8 columns
Goodman, L. A. (1979). Simple models for the analysis of association in cross-classifications having ordered categories. Journal of the American Statistical Association, 74(367), 537-552.
Stuart, A. (1955). A test for homogeneity of the marginal distributions in a two-way classification. Biometrika, 42(3/4), 412-416.
Stuart_marginal_homogeneity(n)Stuart_marginal_homogeneity(n)
n |
matrix of observed counts |
a list containing q: value of q test-statistic df: degrees of freedom p: upper tail p-value of q
Stuart_marginal_homogeneity(vision_data)Stuart_marginal_homogeneity(vision_data)
Taste ratings
tastetaste
## 'taste' A matrix with 5 rows and 5 columns.
McCullagh, P. (1980, p. 119). Regression models for ordinal data. Journal of the Royal Statistical Society, Series B, 42(2), 109-142.
Interrater agreement data for two teachers asked to rate the intelligence of their students.
teachersteachers
## 'teachers' A matrix with 4 rows and 4 columns. Higher scores correspond to higher estimated intelligence.
von Eye, A. & Mun, E. Y. (2005, p. 36). Analyzing rater agreement: Manifest variable methods. Mahwah, NJ: Lawrence Erlbaum.
Ratings of style of teaching by supervisors. 1 indicates Authoritarian, 2 indicates Democratic, 3 indicates Permissive.
teaching_styleteaching_style
An object of class matrix (inherits from array) with 3 rows and 3 columns.
@format ## 'teaching_style' A matrix with 3 rows and 3 columns.
@source Agresti, A. (1989). An agreement model with kappa as parameter. Statistics & Probability Letters, 7, 271-273.
Relationship between size of child's tonsils and their status as a carrier of a disease.
tonsilstonsils
## 'tonsils' A matrix with 2 rows and 3 columns. Rows are disease status and columns are ratings of tonsil size.
McCullagh, P. (1980). Regression models for ordinal data. Journal of the Royal Statistical Society, Series B, 42(2), 109-142.
Ratings go from low to high probability of the show's success.
tvtv
## 'tv' A matrix of 6 rows and 6 columns.
von Eye, A. & Mun, E. Y. (2005, p. 56). Analyzing rater agreement: Manifest variable methods. Mahwah, NJ: Lawrence Erlbaum.
Computes expected counts for uniform association model
uniform_association_fHat(alpha, beta, theta)uniform_association_fHat(alpha, beta, theta)
alpha |
row effects |
beta |
column effects |
theta |
association parameter |
matrix of model-based expected counts
Updates estimate of theta value of the uniform association model
uniform_association_update_theta(theta, n, fHat, exclude_diagonal = FALSE)uniform_association_update_theta(theta, n, fHat, exclude_diagonal = FALSE)
theta |
current estimate of theta |
n |
matrix of observed counts |
fHat |
current model-based counts for each cell |
exclude_diagonal |
logical. Should the cells of the main diagonal be excluded from the computations? Defualt is FALSE, include all cells. |
updated estimate of theta parameter
Formulas are from the paper by Fleiss,J. L., Cohen, J., & Everitt, B. S. (1969). Large sample standard errors of kappa and weighted kappa. Two results are returned in a list. var_kappa0 is the null case and would be used for testing the hypothesis that kappa = 0. The second is var_kappa and is for the non-null case, such as constructing CI for estimated kappa. Not that both are in the variance metric. Take the square root to get the standard error.
var_kappa(n)var_kappa(n)
n |
matrix of observe counts |
a list containing; var_kappa0: variance for the null case var_kappa: variance for the non-null case.
Formulas are from the paper by Fleiss,J. L., Cohen, J., & Everitt, B. S. (1969). Large sample standard errors of kappa and weighted kappa. Two results are returned in a list. var_kappa0 is the null case and would be used for testing the hypothesis that kappa = 0. The second is var_kappa and is for the non-null case, such as constructing CI for estimated kappa. Not that both are in the variance metric. Take the square root to get the standard error.
var_weighted_kappa(n, w)var_weighted_kappa(n, w)
n |
matrix of observe counts |
w |
matrix of penalty weights |
a list containing; var_kappa0: variance for the null case var_kappa: variance for the non-null case.
Measurements of unaided visual acuity for women working at the Royal Ordinance factories 1943-1946. Rows are right eye, columns are left eye. 1 indicates best vision, 4 is poorest.
vision_datavision_data
## 'visual_data' A matrix with 4 rows and 4 columns.
Stuart, A. (1953). The estimation and comparison of strengths of association in contingency tables. Biometrika, 40(1/2), 105-110.
Measurements of unaided visual acuity for men working at the Royal Ordinance factories 1943-1946. Rows are right eye, columns are left eye. 1 indicates best vision, 4 is poorest.
vision_data_menvision_data_men
## 'visual_data_men' A matrix with 4 rows and 4 columns.
Stuart, A. (1953). The estimation and comparison of strengths of association in contingency tables. Biometrika, 40(1/2), 105-110.
Fits the diagonal effects model, where each category has its own parameter delta[k].
von_Eye_diagonal(n)von_Eye_diagonal(n)
n |
the matrix of observed counts |
a list containing beta: the regression parameters. delta parameters are the final elements of beta g_squared: G^2 fit measure chisq: X^2 fit measure df: degrees of freedom expected: matrix of expected frequencies
Fits the diagonal effects model, where each category has its own parameter delta[k], while also incorporating a linear-by-linear term.
von_Eye_diagonal_linear_by_linear(n, center = TRUE)von_Eye_diagonal_linear_by_linear(n, center = TRUE)
n |
the matrix of observed counts |
center |
should the linear-by-linear components be centered to have mean 0? Default is TRUE |
a list containing beta: the regression parameters. delta parameters come after rows and columns and finally the linear-by-linear term g_squared: G^2 fit measure chisq: X^2 fit measure df: degrees of freedom expected: matrix of expected frequencies
Fits the diagonal effects model, where there is a single delta parameter for all categories, while also incorporating a linear-by-linear term.
von_Eye_equal_weight_diagonal_linear(n, center = TRUE)von_Eye_equal_weight_diagonal_linear(n, center = TRUE)
n |
the matrix of observed counts |
center |
should the linear-by-linear components be centered to have mean 0? Default is TRUE |
a list containing beta: the regression parameters. delta parameters come after rows and columns and finally the linear-by-linear term g_squared: G^2 fit measure chisq: X^2 fit measure df: degrees of freedom expected: matrix of expected frequencies
Fits the equal weighted diagonal model, where the diagonals all have an additional parameter delta, with the constraint that delta is equal across all categories.
von_Eye_equal_weighted_diagonal(n)von_Eye_equal_weighted_diagonal(n)
n |
the matrix of observed counts |
a list containing beta: the regression parameters g_squared: G^2 fit measure chisq: X^2 fit measure df: degrees of freedom expected: matrix of expected frequencies
Fits the basic independent rows and columns model incorporating a linear-by-linear term.
von_Eye_linear_by_linear(n, center = TRUE)von_Eye_linear_by_linear(n, center = TRUE)
n |
matrix of observed counts |
center |
should the linear-by-linear components be centered to have mean 0? Default is TRUE |
a list containing beta: the regression parameters. The linear-by-linear parameter is last g_squared: G^2 fit measure chisq: X^2 fit measure df: degrees of freedom expected: matrix of expected frequencies
Fits the base model with only independent row and column effects.
von_Eye_main_effect(n)von_Eye_main_effect(n)
n |
the matrix of observed counts |
a list containing beta: the regression parameters g_squared: G^2 fit measure chisq: X^2 fit measure df: degrees of freedom expected: matrix of expected frequencies
The model specifies main effects for row and column, and a parameter for the agreement (diagonal) cells. This takes a design matrix for that model and applies domain-specific weights to the agreement parameters.
von_Eye_weight_by_response_category_design(n, x, w, n_raters = 2)von_Eye_weight_by_response_category_design(n, x, w, n_raters = 2)
n |
the matrix of cell counts |
x |
the original design matrix. |
w |
the vector of weights to apply to the agreement cells. Should have same number of entries as the number of diagonal elements (number of rows & of columns) |
n_raters |
number of raters. Currently only 2 (the default) are supported. This is an extension point for future work. |
new design matrix with weights applied to the agreement cells.
Computes covariance between x and y using case weights in w
weighted_cov(x, y, w, use_df = TRUE)weighted_cov(x, y, w, use_df = TRUE)
x |
Numeric vector. First variable |
y |
Numeric vector. Second variable |
w |
Numeric vector. case weights |
use_df |
Logical. should the divisor be sum of weights - 1 (TRUE) or N - 1 (FALSE) |
the weighted covariance between x and y
Computes Cohen's 1968 weighted kappa coefficient
weighted_kappa(n, w = diag(rep(1, nrow(n))), quadratic = FALSE)weighted_kappa(n, w = diag(rep(1, nrow(n))), quadratic = FALSE)
n |
matrix of observed counts |
w |
matrix of weights. Defaults to identity matrix |
quadratic |
logical. Should quadratic weights be used? Default is FALSE. If TRUE, quadratic weights are used. These override the values in w. If FALSE, weights in w are used |
value of weighted kappa
Computes variance between x and y using case weights in w
weighted_var(x, w, use_df = TRUE)weighted_var(x, w, use_df = TRUE)
x |
Numeric vector. First variable |
w |
Numeric vector. Case weights |
use_df |
Logical. Should the divisor be sum of weights - 1 (TRUE) or N - 1 (FALSE) |
the weighted covariance between x and y
See companion new_orleans_data.
winnipeg_datawinnipeg_data
## 'winnipeg_data' A matrix with 4 rows and 4 columns Ratings range from definite presence of disease to definite absence.
???
Social mobility data with father's occupational social status and son's occupational social status.
Description
Social mobility data with father's occupational social status and son's occupational social status.
Usage
Format
## 'social_status' A matrix with 7 rows and 7 columns
Source
Goodman, L. A. (1979). Simple models for the analysis of association in cross-classifications having ordered categories. Journal of the American Statistical Association, 74(367), 537-552.