Title: | Cochran-Mantel-Haenszel and Nonparametric ANOVA |
---|---|
Description: | Cochran-Mantel-Haenszel methods (Cochran (1954) <doi:10.2307/3001616>; Mantel and Haenszel (1959) <doi:10.1093/jnci/22.4.719>; Landis et al. (1978) <doi:10.2307/1402373>) are a suite of tests applicable to categorical data. A competitor to those tests is the procedure of Nonparametric ANOVA which was initially introduced in Rayner and Best (2013) <doi:10.1111/anzs.12041>. The methodology was then extended in Rayner et al. (2015) <doi:10.1111/anzs.12113>. This package employs functions related to both methodologies and serves as an accompaniment to the book: An Introduction to Cochran–Mantel–Haenszel and Non-Parametric ANOVA. The package also contains the data sets used in that text. |
Authors: | G. C. Livingston Jr [aut, cre, cph], J.C.W. Rayner [aut] |
Maintainer: | G. C. Livingston Jr <[email protected]> |
License: | GPL-3 |
Version: | 1.1.1 |
Built: | 2024-12-18 06:30:51 UTC |
Source: | CRAN |
ARL
returns the test statistic and p-value for the aligned RL test.
ARL(y, treatment, block1, block2)
ARL(y, treatment, block1, block2)
y |
a numeric vector for the response variable. |
treatment |
a vector giving the treatment type for the corresponding
elements of |
block1 |
a vector giving the first blocking variable for the
corresponding elements of |
block2 |
a vector giving the second blocking variable for the
corresponding elements of |
This test is applicable to Latin square designs. The test is not recommended though as the use of t-1 degrees of freedom in the null distribution results in unsatisfactorily large test sizes.
The CARL
test uses t+1 degrees of freedom in the null distribution which
results is appropriate test size and good power.
A list containing the ARL test statistic adjusted for ties together with the associated p-value using a chi-squared distribution with t-1 degrees of freedom.
Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.
attach(peanuts) ARL(y = yield, treatment = treatment, block1 = row, block2 = col)
attach(peanuts) ARL(y = yield, treatment = treatment, block1 = row, block2 = col)
A data set showing individuals' grade of asbestosis together with their length of expposure to asbestos.
data(asbestos)
data(asbestos)
A data frame with 1117 rows and two columns.
a factor representing the number of years of exposure to asbestos
a factor representing the grade of asbestosis. Grade 0 represents none present
Irving J. Selikoff (1915–1992) was a chest physician and researcher who had often been described as America’s foremost medical expert on asbestos related diseases between the 1960s and the early 1990s.
Through a lung clinic that he operated in New Jersey, Selikoff collected data from a sample of around 1200 insulation workers in metropolitan New York in 1963.
Selikoff IJ. Household risks with inorganic fibers. Bull N Y Acad Med. 1981 Dec;57(10):947-61.
Selikoff IJ. Household risks with inorganic fibers. Bull N Y Acad Med. 1981 Dec;57(10):947-61.
attach(asbestos) KW(treatment = exposure, response = grade)
attach(asbestos) KW(treatment = exposure, response = grade)
CARL
returns the test statistic and p-value for the aligned RL test
with empirically fitted degrees of freedom.
CARL( y, treatment, block1, block2, n_components = 0, n_permutations = 0, treatment_scores = NULL, sig_digits = 4, verbose = FALSE )
CARL( y, treatment, block1, block2, n_components = 0, n_permutations = 0, treatment_scores = NULL, sig_digits = 4, verbose = FALSE )
y |
a numeric vector for the response variable. |
treatment |
a vector giving the treatment type for the corresponding
elements of |
block1 |
a vector giving the first blocking variable for the
corresponding elements of |
block2 |
a vector giving the second blocking variable for the
corresponding elements of |
n_components |
the number of polynomial components you wish to test. The maximum number of components is the number of treatments less one. If the number of components requested is less than |
n_permutations |
the number of permutations you wish to run. |
treatment_scores |
the scores to be applied to the treatment groups. If not declared these will be set automatically and should be checked. |
sig_digits |
the number of significant digits the output should show. |
verbose |
flag for turning on the status bar for permutation tests. |
This test is applicable to Latin square designs and is recommended over the RL and ARL test. The test uses t+1 as the degrees of freedom of the chi-squared null distribution and results in appropriate test sizes as well as good power.
The CARL
test statistic adjusted for ties together with the
associated p-value using a chi-squared distribution with t+1 degrees of
freedom.
Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.
attach(peanuts) CARL(y = yield, treatment = treatment, block1 = row, block2 = col)
attach(peanuts) CARL(y = yield, treatment = treatment, block1 = row, block2 = col)
Each of five breakfast cereals are ranked by ten judges, who each taste three cereals. Each cereal is assessed six times.
data(cereal)
data(cereal)
A data frame with 30 rows and three columns.
the rank of the cereal within each judge block
the judge that was used
the type of cereal
The data comes from a Balanced Incomplete Block Design with the number of treatments t = 5, number of blocks b = 10, with k = 3 and r = 6.
Kutner et al. (2005, section 28.1)
Kutner, M., Nachtsheim, C., Neter, J. and Li, W. (2005). Applied linear statistical models (5th ed.). Boston: McGraw-Hill Irwin.
attach(cereal) durbin(y = rank, groups = type, blocks = judge)
attach(cereal) durbin(y = rank, groups = type, blocks = judge)
CMH
returns the test statistics and p-values for the four CMH tests.
CMH( treatment, response, strata = NULL, a_ij = NULL, b_hj = NULL, test_OPA = TRUE, test_GA = TRUE, test_MS = TRUE, test_C = TRUE, cor_breakdown = TRUE )
CMH( treatment, response, strata = NULL, a_ij = NULL, b_hj = NULL, test_OPA = TRUE, test_GA = TRUE, test_MS = TRUE, test_C = TRUE, cor_breakdown = TRUE )
treatment |
a factor vector representing the treatment applied. |
response |
a factor vector giving the response category for the
corresponding elements of |
strata |
a factor vector giving the strata or block for the
corresponding elements of |
a_ij |
a t x b matrix of treatment scores. The matrix allows for different scores to be used over different strata. If a t x 1 vector of scores is provided, it is assumed that the scores are the same across strata and a warning provided. |
b_hj |
a c x b matrix of response scores. The matrix allows for different scores to be used over different strata. If a c x 1 vector of scores is provided, it is assumed that the scores are the same across strata and a warning provided. |
test_OPA |
TRUE or FALSE flag to include the calculation of the OPA test values. |
test_GA |
TRUE or FALSE flag to include the calculation of the GA test values. |
test_MS |
TRUE or FALSE flag to include the calculation of the MS test values. If response scores are not included, this test will not be performed. |
test_C |
TRUE or FALSE flag to include the calculation of the C test values. If response scores and treatment scores are not included, this test will not be performed. |
cor_breakdown |
TRUE or FALSE flag to indicate if a correlation breakdown over the strata is required. |
Provided the required information is used in the function, the function will return all four CMH test results.
The CMH test results for the four tests assuming the required information is supplied.
Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.
CMH(treatment = marriage$religion, response = marriage$opinion, strata = marriage$education, test_OPA = FALSE, test_MS = FALSE)
CMH(treatment = marriage$religion, response = marriage$opinion, strata = marriage$education, test_OPA = FALSE, test_MS = FALSE)
Corn yields when grown by four different methods.
data(corn)
data(corn)
A data frame with 34 rows and two columns.
one of four different methods used to grow corn
corn yield categorised into four levels
Rayner and Best (2001)
Rayner, J.C.W. and Best, D.J. (2001). A Contingency Table Approach to Nonparametric Testing. Chapman & Hall/CRC: Boca Raton FL.
attach(corn) KW(treatment = method, response = outcome)
attach(corn) KW(treatment = method, response = outcome)
A success or fail response variable with three treatments repeated over 11 patients.
data(crossover)
data(crossover)
A data frame with 33 rows and three columns.
the type of treatment applied. The three treatments are placebo, aspirin and a new drug
whether the treatment was a success or not
the patient the treatment was applied to
In StatXact (2003), three treatment, three period cross-over clinical data for 11 patients are given. This is a CMH design with t = 3, c = 2, and b = 11.
StatXact (2003)
StatXact (2003). User Manual Volume 2. CYTEL Software.
attach(crossover) CMH(treatment = treatment,response = success,strata = patient)
attach(crossover) CMH(treatment = treatment,response = success,strata = patient)
durbin
returns the results of Durbin's Rank Sum test.
durbin( y, groups, blocks, n_components = 0, n_permutations = 0, group_scores = NULL, sig_digits = 4, verbose = FALSE )
durbin( y, groups, blocks, n_components = 0, n_permutations = 0, group_scores = NULL, sig_digits = 4, verbose = FALSE )
y |
a numeric vector for the response variable. |
groups |
a vector giving the group for the corresponding elements of
|
blocks |
a vector giving the block for the corresponding elements of
|
n_components |
the number of polynomial components you wish to test. The maximum number of components is the number of groups less one. If the number of components requested is less than |
n_permutations |
the number of permutations you wish to run. |
group_scores |
the scores to be applied to the groups. If not declared these will be set automatically and should be checked. |
sig_digits |
the number of significant digits the output should show. |
verbose |
flag for turning on the status bar for permutation tests. |
The test is a generalisation of Friedman's test that can be applied to BIBD.
The Durbin test adjusted for tied results.
Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.
attach(icecream) durbin(y = rank, groups = variety, blocks = judge)
attach(icecream) durbin(y = rank, groups = variety, blocks = judge)
A data set for the explosiveness of five different formulations of explosive.
data(dynamite)
data(dynamite)
A data frame with 25 rows and four columns.
a numeric vector for the explosiveness of the formulation with corresponding treatment
, batch
and operator
a factor distinguishing the formulation for the explosive mixture
a factor describing the batch the raw materials come from
a factor describing the operator who prepares the explosive formulation
The effect of five different formulations of an explosive mixture are assessed. A batch of raw material is large enough for only five formulations. Each formulation is prepared by five operators. The response here is the explosiveness of dynamite formulations. This is a Latin square design.
https://www.fox.temple.edu/cms/wp-content/uploads/2016/05/Randomized-Block-Design.pdf
Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.
attach(dynamite) CARL(y = response, treatment = treatment, block1 = batch, block2 = operator)
attach(dynamite) CARL(y = response, treatment = treatment, block1 = batch, block2 = operator)
Categorical responses made by 15 subjects for two different prices of the same food product. The data is from a CMH design.
data(food)
data(food)
A data frame with 30 rows and three columns.
a factor showing two price points for the product
a factor indicating the decision of either buy, undecided, or not_buy the product
a factor showing the individual making a decison about the product
Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.
attach(food) b_hj = matrix(1:3,ncol=15,nrow=3) CMH(treatment = price, response = decision, strata = subject, b_hj = b_hj, test_OPA = FALSE, test_C = FALSE)
attach(food) b_hj = matrix(1:3,ncol=15,nrow=3) CMH(treatment = price, response = decision, strata = subject, b_hj = b_hj, test_OPA = FALSE, test_C = FALSE)
friedman
returns the test statistic and p-value for the Friedman test.
friedman( y, groups, blocks, n_components = 0, n_permutations = 0, group_scores = NULL, sig_digits = 4, verbose = FALSE )
friedman( y, groups, blocks, n_components = 0, n_permutations = 0, group_scores = NULL, sig_digits = 4, verbose = FALSE )
y |
a numeric vector for the response variable. |
groups |
a vector giving the group for the corresponding elements of
|
blocks |
a vector giving the block for the corresponding elements of
|
n_components |
the number of polynomial components you wish to test. The maximum number of components is the number of groups less one. If the number of components requested is less than |
n_permutations |
the number of permutations you wish to run. |
group_scores |
the scores to be applied to the groups. If not declared these will be set automatically and should be checked. |
sig_digits |
the number of significant digits the output should show. |
verbose |
flag for turning on the status bar for permutation tests. |
The Friedman test results statistic adjusted for ties together with the associated p-value.
Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.
attach(jam) friedman(y = sweetness_ranks, groups = type, blocks = judge)
attach(jam) friedman(y = sweetness_ranks, groups = type, blocks = judge)
gen_cor
returns the generalised correlations and associated p-values
together with tests of normality.
gen_cor( x, y, z = NULL, U, V, W = NULL, x_scores = NULL, y_scores = NULL, z_scores = NULL, n_perms = 0, perms_info = FALSE, rounding = 4 )
gen_cor( x, y, z = NULL, U, V, W = NULL, x_scores = NULL, y_scores = NULL, z_scores = NULL, n_perms = 0, perms_info = FALSE, rounding = 4 )
x |
a numeric vector or factor, commonly a response variable. |
y |
a numeric vector or factor, commonly a treatment variable. |
z |
an optional numeric vector or factor, commonly a block variable. |
U |
the maximum degree of correlation relating to the variable |
V |
the maximum degree of correlation relating to the variable |
W |
the maximum degree of correlation relating to the variable |
x_scores |
optional scores related to the variable |
y_scores |
optional scores related to the variable |
z_scores |
optional scores related to the variable |
n_perms |
an optional numeric value indicating the number of permutations required. |
perms_info |
a TRUE of FALSE flag to indicate whether information regarding the progress on the number of permutations should be printed. |
rounding |
the number of decimal places the output should be rounded to. The default is 4. |
This function calculates up to three way generalised correlations. The function calculates three tests by default to test if the correlations are statistically significantly different from 0 with an option to run permuation testing.
This function calculates the generalised correlations for up to three input variables.
Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.
attach(intelligence) gen_cor(x = rank(score), y = age, U = 2, V = 2)
attach(intelligence) gen_cor(x = rank(score), y = age, U = 2, V = 2)
Human resource ranking data.
data(hr)
data(hr)
A data frame with 50 rows and three columns.
the applicant to which ratings are applied
the ranking from made by the committee member
member of the selection panel that ranks five candidates
Applications for a position are vetted and ranked by Human Resource (HR) professionals. The top five are interviewed by a selection committee of ten. Each member of the committee gives an initial ranking of the applicants and no one on the committee sees either the ranking by the HR professionals or the initial rankings of the other committee members. Ties are not permitted in any ranking. It is of interest to know if the rankings of the HR professionals and the initial rankings of the selection committee are correlated.
Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.
attach(hr) a_ij = matrix(1:5,ncol=10,nrow=5) b_hj = matrix(1:5,ncol=10,nrow=5) CMH(treatment = applicant, response = applicant_ranking, strata = committee_member, a_ij = a_ij, b_hj = b_hj, test_OPA = FALSE, test_GA = FALSE, test_MS = FALSE)
attach(hr) a_ij = matrix(1:5,ncol=10,nrow=5) b_hj = matrix(1:5,ncol=10,nrow=5) CMH(treatment = applicant, response = applicant_ranking, strata = committee_member, a_ij = a_ij, b_hj = b_hj, test_OPA = FALSE, test_GA = FALSE, test_MS = FALSE)
Ice Cream data
data(icecream)
data(icecream)
A data frame with 21 rows and three columns.
the rank of the ice cream within each judging block
the judge that was used
the type of ice cream that was tested
The icecream data set comes from a Balanced Incomplete Block Design. There are seven vanilla ice-creams that are the same except for increasing amounts of vanilla flavouring. Seven judges each taste three varieties.
Table 5.1 in Conover (1998, p. 391).
Conover, W. J. (1998). Practical nonparametric statistics (3rd ed.). New York: Wiley. Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.
attach(icecream) durbin(y = rank, groups = variety, blocks = judge)
attach(icecream) durbin(y = rank, groups = variety, blocks = judge)
Intelligence scores for individuals from different age groups.
data(intelligence)
data(intelligence)
A data frame with 15 rows and two columns.
age of the respondents
intelligence score achieved
Rayner and Best (2001, section 8.1)
Rayner, J. C. W. and Best, D. J. (2001). A Contingency Table Approach to Nonparametric Testing. Boca Raton: Chapman & Hall/CRC.
attach(intelligence) gen_cor(x = rank(score), y = age, U = 2, V = 2)
attach(intelligence) gen_cor(x = rank(score), y = age, U = 2, V = 2)
Plum jam sweetness data based on JAR judge scores.
data(jam)
data(jam)
A data frame with 24 rows and four columns.
the type of jam that was tested
the judge that was used for tasting
the judges score for sweetness: 1 denotes not sweet enough, 2 not quite sweet enough, 3 just about right, 4 a little too sweet and 5 too sweet
the ranks within judge
Three plum jams, A, B and C are given JAR sweetness codes by eight judges. Here, 1 denotes not sweet enough, 2 not quite sweet enough, 3 just about right, 4 a little too sweet and 5 too sweet.
Rayner and Best (2017, 2018)
Rayner, J.C.W. and Best, D.J. (2017). Unconditional analogues of Cochran-Mantel-Haenszel tests. Australian & NZ Journal of Statistics, 59(4), 485-494.
Rayner, J.C.W. and Best, D.J. (2018). Extensions to the Cochran-Mantel-Haenszel mean scores and correlation tests. Journal of Statistical Theory and Practice.
attach(jam) a_ij = matrix(rep(1:3,8), ncol = 8) b_hj = matrix(rep(1:5,8), ncol = 8) CMH(treatment = type, response = sweetness, strata = judge, a_ij = a_ij, b_hj = b_hj, test_OPA = FALSE, test_GA = FALSE, test_MS = FALSE)
attach(jam) a_ij = matrix(rep(1:3,8), ncol = 8) b_hj = matrix(rep(1:5,8), ncol = 8) CMH(treatment = type, response = sweetness, strata = judge, a_ij = a_ij, b_hj = b_hj, test_OPA = FALSE, test_GA = FALSE, test_MS = FALSE)
Job satisfaction data based on income and gender.
data(job_satisfaction)
data(job_satisfaction)
A data frame with 104 rows and three columns.
income level categorised
the level of job satisfaction for the respondent
gender of the respondent
The data relate job satisfaction and income in males and females. Gender induces two strata; the treatments are income with categories scored 3, 10, 20 and 35 while the response is job satisfaction with categories scored 1, 3, 4, and 5.
Agresti (2003)
Agresti, A. (2003). Categorical Data Analysis. Hoboken: John Wiley & Sons.
attach(job_satisfaction) a_ij = matrix(rep(c(3,10,20,35),2),nrow=4) b_hj = matrix(rep(c(1,3,4,5),2),nrow=4) unconditional_CMH(treatment = income, response = satisfaction, strata = gender, U = 2, V = 2, a_ij = a_ij, b_hj = b_hj)
attach(job_satisfaction) a_ij = matrix(rep(c(3,10,20,35),2),nrow=4) b_hj = matrix(rep(c(1,3,4,5),2),nrow=4) unconditional_CMH(treatment = income, response = satisfaction, strata = gender, U = 2, V = 2, a_ij = a_ij, b_hj = b_hj)
KW
returns the test statistic and p-value for the Kruskal-Wallis test
adjusted for ties.
KW( treatment, response, n_components = 0, n_permutations = 0, treatment_scores = NULL, sig_digits = 4, verbose = FALSE )
KW( treatment, response, n_components = 0, n_permutations = 0, treatment_scores = NULL, sig_digits = 4, verbose = FALSE )
treatment |
a factor that defines the group the response belongs to. |
response |
a numeric variable measuring the response outcome. |
n_components |
the number of polynomial components you wish to test. The maximum number of components is the number of treatments less one. If the number of components requested is less than |
n_permutations |
the number of permutations you wish to run. |
treatment_scores |
the scores to be applied to the treatment groups. If not declared these will be set automatically and should be checked. |
sig_digits |
the number of significant digits the output should show. |
verbose |
flag for turning on the status bar for permutation tests. |
The Kruskal-Wallis test is a non-parametric equivalent to the one way ANOVA.
The function returns the test result of the Kruskal Wallis test with adjustment for ties and without.
Rayner, J.C.W and Livingston Jr, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.
attach(whiskey) KW(treatment = maturity, response = grade)
attach(whiskey) KW(treatment = maturity, response = grade)
The Lemonade data set comes from a Randomised Block Design. There are four types of lemonades which are all tasted by five tasters.
data(lemonade)
data(lemonade)
A data frame with 20 rows and three columns.
the rank of the lemonade within each judging block
the type of lemonade that was tested
the judge that was used for tasting
Thas et al. (2012, section 4.2)
Thas, O., Best, D.J. and Rayner, J.C.W. (2012). Using orthogonal trend contrasts for testing ranked data with ordered alternatives. Statisticia Neerlandica, 66(4), 452-471.
attach(lemonade) friedman(y = rank, groups = type, blocks = taster)
attach(lemonade) friedman(y = rank, groups = type, blocks = taster)
Five lemonades with increasing sugar content are ranked by each of ten judges. They were not permitted to give tied outcomes. This is a randomised block design.
data(lemonade_sugar)
data(lemonade_sugar)
A data frame with 50 rows and three columns.
the rank each lemonade based on sugar content
type of lemonade ordered by sugar content
the judge providing the ranking
Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.
attach(lemonade_sugar) gen_cor(x = ranks, y = sugar_content, U = 3, V = 3, rounding = 3)
attach(lemonade_sugar) gen_cor(x = ranks, y = sugar_content, U = 3, V = 3, rounding = 3)
The data come from Manly (2007) and relate to the number of ants consumed by two sizes of Eastern Horned Lizards over a four month period.
data(lizard)
data(lizard)
A data frame with 24 rows and three columns.
the month in which the measurements were taken
the size of the Eastern Horned Lizards
the number of ants consumed
Manly (2007)
Manly, B. F. J. (2007). Randomization, Bootstrap and Monte Carlo Methods in Biology, Third Edition. Boca Raton: Chapman & Hall/CRC.
attach(lizard) gen_cor(x = ants, y = month, z = size, U = 3, V = 3, W = 1)
attach(lizard) gen_cor(x = ants, y = month, z = size, U = 3, V = 3, W = 1)
Scores of 1, 2 and 3 are assigned to the responses agree, neutral and disagree respectively to the proposition "Homosexuals should be able to marry" and scores of 1, 2 and 3 are assigned to the religious categories fundamentalist, moderate and liberal respectively.
data(marriage)
data(marriage)
A data frame with 133 rows and three columns.
highest level of eduction for the respondent
level of religiosity. Scores of 1, 2 and 3 are assigned to the religious categories fundamentalist, moderate and liberal respectively
the response to the proposition: "Homosexuals should be able to marry". Scores of 1, 2 and 3 are assigned to the responses agree, neutral and disagree respectively
Agresti (2002)
Agresti, A. (2002). Categorical Data Analysis, 2nd ed; Wiley: New York.
attach(marriage) lm(as.numeric(opinion)~religion+education)
attach(marriage) lm(as.numeric(opinion)~religion+education)
In each of four lactation periods each of four cows are fed a different diet. There is a washout period so previous diet does not affect future results. A 4 × 4 Latin square is used to assess how diet affects milk production.
data(milk)
data(milk)
A data frame with 16 rows and four columns.
a numerical measure of the milk production for the given diet, cow, and period
a factor showing which diet the cow was administered
a factor indicating the cow
a factor showing the relevant period
https://www.stat.purdue.edu/~yuzhu/stat514fall05/Lecnot/latinsquarefall05.pdf
attach(milk) CARL(y = production, treatment = diet, block1 = cow, block2 = period)
attach(milk) CARL(y = production, treatment = diet, block1 = cow, block2 = period)
mu_r
returns the estimated rth moment of a vector.
mu_r(x, r)
mu_r(x, r)
x |
a numeric vector. |
r |
the degree moment requiring calculation |
Returns the estimated rth moment of a vector.
Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.
x_vec = rnorm(10) mu_r(x_vec,2)
x_vec = rnorm(10) mu_r(x_vec,2)
np_anova
performs a nonparametric ANOVA.
np_anova(ordered_vars, predictor_vars, uvw)
np_anova(ordered_vars, predictor_vars, uvw)
ordered_vars |
a data frame for the ordered variables being assessed. |
predictor_vars |
a data frame for the un-ordered variables being assessed. |
uvw |
the degree being assessed. This should be a vector with length
equal the number of elements in the |
Nonparametric ANOVA is a methodology that is applicable where one as an ordered response variable as well as both ordered response and predictor variables.
Where there is only one ordered variable, the function returns a type III
ANOVA table to test for differences of order uvw
across the levels of
the predictor_vars
.
Where there is more than one ordered variable, the function returns a type
III ANOVA table to test for differences in generalised correlations of order
uvw
across the levels of the predictor_vars
.
Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.
attach(jam) np_anova(ordered_vars = sweetness, predictor_vars = data.frame(type,judge), uvw = 1)
attach(jam) np_anova(ordered_vars = sweetness, predictor_vars = data.frame(type,judge), uvw = 1)
orthogonal_scores
returns orthogonal scores weighted by prevalence in
the data.
orthogonal_scores(x, degree, n_strata = 1)
orthogonal_scores(x, degree, n_strata = 1)
x |
a vector of scores, either a factor or numeric. |
degree |
the degree of orthogonal scores required. |
n_strata |
optional argument for indicating the number of strata to apply the scores to. |
Returns a matrix of orthogonal scores.
Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.
attach(jam) orthogonal_scores(x = sweetness, degree = 2, n_strata = 8)
attach(jam) orthogonal_scores(x = sweetness, degree = 2, n_strata = 8)
PARL
returns the test statistic and p-value for the aligned RL test
performed as a permutation test.
PARL(y, treatment, block1, block2, N_perms = 1000, components = FALSE)
PARL(y, treatment, block1, block2, N_perms = 1000, components = FALSE)
y |
a numericc vector for the response variable. |
treatment |
a vector giving the treatment type for the corresponding
elements of |
block1 |
a vector giving the first blocking variable for the
corresponding elements of |
block2 |
a vector giving the second blocking variable for the
corresponding elements of |
N_perms |
The number of permutations to perform. |
components |
a TRUE or FALSE flag to indicate whether component p-values should be calculated. |
This test is applicable to Latin square designs and is recommended over the RL and ARL test. The CARL test is much faster to run.
The PARL test statistic together with the associated p-value. Component p-values may also be calculated and shown.
Rayner, J.C.W and Livingston Jr, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.
attach(peanuts) PARL(y = yield, treatment = treatment, block1 = row, block2 = col, components = TRUE)
attach(peanuts) PARL(y = yield, treatment = treatment, block1 = row, block2 = col, components = TRUE)
A plant biologist conducted an experiment to compare the yields of four varieties of peanuts, denoted as A, B, C, and D. A plot of land was divided into 16 subplots (four rows and four columns).
data(peanuts)
data(peanuts)
A data frame with 16 rows and four columns.
the peanut yield
the variety of peanut plant
the row the plants were grown in of the plot
the column the plants were grown in of the plot
http://www.math.montana.edu/jobo/st541/sec3c.pdf
Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.
attach(peanuts) CARL(y = yield, treatment = treatment, block1 = row, block2 = col)
attach(peanuts) CARL(y = yield, treatment = treatment, block1 = row, block2 = col)
Poly
returns t-1 orthonormal scores weighted by a weights parameter.
The function uses Emerson Recursion.
Poly(x, p)
Poly(x, p)
x |
a vector of numeric scores. |
p |
a vector of weights corresponding to the elements of x. |
Returns a matrix of orthomornal scores based on the weights provided.
Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley. Rayner, J.C.W., Thas, O. and De Boeck, B. (2008), A GENERALIZED EMERSON RECURRENCE RELATION. Australian & New Zealand Journal of Statistics, 50: 235-240.
x = 1:5 p = rep(0.2,5) Poly(x = x, p = p)
x = 1:5 p = rep(0.2,5) Poly(x = x, p = p)
RL
returns the test statistic and p-value for the RL test. This test
is applicable to Latin square designs. The test is not recommended though as
block effects contaminate the response variable leading to unacceptable test
size.
RL(y, treatment, block1, block2)
RL(y, treatment, block1, block2)
y |
a numericc vector for the response variable. |
treatment |
a vector giving the treatment type for the corresponding
elements of |
block1 |
a vector giving the first blocking variable for the
corresponding elements of |
block2 |
a vector giving the second blocking variable for the
corresponding elements of |
A list containing the RL test statistic adjusted for ties together with the associated p-value using a chi-squared distribution with t-1 degrees of freedom.
Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.
attach(peanuts) RL(y = yield, treatment = treatment, block1 = row, block2 = col)
attach(peanuts) RL(y = yield, treatment = treatment, block1 = row, block2 = col)
row_col_effects
returns the values of the row and column effects. This
can be used to remove these effects from the response in a process call
aligning. This is particularly applicable in LSD data.
row_col_effect(to_align, rows, cols)
row_col_effect(to_align, rows, cols)
to_align |
a numeric response vector. |
rows |
a vector giving the row effects for |
cols |
a vector giving the column effects for |
A vector of row and column effects. The response vector less this is the aligned response variable.
Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.
attach(peanuts) row_col_effect(to_align = yield, rows = row, cols = col)
attach(peanuts) row_col_effect(to_align = yield, rows = row, cols = col)
Three products, A, B and C, were tasted by 107 consumers who gave responses ‘not salty enough’, ‘just about right saltiness’ and ‘too salty’, which were then scored as 1, 2 and 3. The design is randomised blocks.
data(saltiness)
data(saltiness)
A data frame with 321 rows and three columns.
the type of product being tested
the saltiness score. Scores of 1, 2 and 3 correspond to responses ‘not salty enough’, ‘just about right saltiness’ and ‘too salty’
the participant providing the rating
Rayner, J. C. W. and Best, D. J. (2017)
Rayner, J. C. W. and Best, D. J. (2017). Unconditional analogues of Cochran-Mantel-Haenszel tests. Australian & New Zealand Journal of Statistics, 59(4):485–494.
attach(saltiness) CMH(treatment = product, response = scores, strata = participant, test_OPA = FALSE, test_MS = FALSE, test_C = FALSE)
attach(saltiness) CMH(treatment = product, response = scores, strata = participant, test_OPA = FALSE, test_MS = FALSE, test_C = FALSE)
Strawberry growth rates for different pesticides.
data(strawberry)
data(strawberry)
A data frame with 28 rows and four columns.
the experimental block
the pesticide applied to the plant. Pesticide O is a control.
a measure of the growth rate of strawberry plants with pesticide
applied.
rank of the response
Pesticides are applied to strawberry plants to inhibit the growth of weeds. The question is, do they also inhibit the growth of the strawberries? The design is a supplemented balanced design.
Pearce (1960)
Pearce, S.C. (1960). Supplemented balanced. Biometrika, 47, 263-271.
attach(strawberry) lm_strawberry = lm(rank~pesticide+block) anova(lm_strawberry)
attach(strawberry) lm_strawberry = lm(rank~pesticide+block) anova(lm_strawberry)
T_Mu
returns the test statistic for an unconditional CMH MS equivalent
test of required degree
. This function is used in the
unconditional_CMH
function.
T_Mu(treatment, response, strata = NULL, degree)
T_Mu(treatment, response, strata = NULL, degree)
treatment |
a vector of treatment values. |
response |
a vector of response values. |
strata |
a variable defining the strata. |
degree |
the degree assessment required. |
The function returns the test statistic for an unconditional CMH MS
equivalent test of required degree
.
Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.
attach(job_satisfaction) T_Mu(treatment = income, response = as.numeric(satisfaction), strata = gender, degree = 1)
attach(job_satisfaction) T_Mu(treatment = income, response = as.numeric(satisfaction), strata = gender, degree = 1)
Traffic light data for different light sequences, intersections, and times of day.
data(traffic)
data(traffic)
A data frame with 25 rows and four columns.
the amount of unused red-light time in minutes
the traffic light sequence
the intersection the treatment
was applied
the time of the day the treatment
was applied
A traffic engineer conducted a study to compare the total unused red-light time for five different traffic light signal sequences. The experiment was conducted with a Latin square design in which blocking factors were (1) five intersections and (2) five time of day periods.
Kuehl, R. (2000)
Kuehl, R. (2000). Design of Experiments: Statistical Principles of Research Design and Analysis. Belmont, California: Duxbury Press.
Best, D. J. and Rayner, J. C. W. (2011). Nonparametric tests for Latin squares. NIASRA Statistics Working Paper Series, 11-11.
attach(traffic) np_anova(ordered_vars = rank(minutes), predictor_vars = data.frame(treatment,intersection,time_of_day), uvw = 1)
attach(traffic) np_anova(ordered_vars = rank(minutes), predictor_vars = data.frame(treatment,intersection,time_of_day), uvw = 1)
unconditional_CMH
returns the test statistics and p-values for the
equivalent unconditional CMH tests.
unconditional_CMH( treatment, response, strata = NULL, U = NULL, V = NULL, a_ij = NULL, b_hj = NULL, test_OPA = TRUE, test_GA = TRUE, test_M = TRUE, test_C = TRUE )
unconditional_CMH( treatment, response, strata = NULL, U = NULL, V = NULL, a_ij = NULL, b_hj = NULL, test_OPA = TRUE, test_GA = TRUE, test_M = TRUE, test_C = TRUE )
treatment |
a factor vector representing the treatment applied. |
response |
a factor vector giving the response category for the
corresponding elements of |
strata |
a factor vector giving the strata or block for the
corresponding elements of |
U |
The degree of assessment relating to the treatment. |
V |
The degree of assessment relating to the response. |
a_ij |
a t x b matrix of treatment scores. The matrix allows for different scores to be used over different strata. If a t x 1 vector of scores is provided, it is assumed that the scores are the same across strata and a warning provided. |
b_hj |
a c x b matrix of response scores. The matrix allows for different scores to be used over different strata. If a c x 1 vector of scores is provided, it is assumed that the scores are the same across strata and a warning provided. |
test_OPA |
TRUE or FALSE flag to include the calculation of the OPA test values. |
test_GA |
TRUE or FALSE flag to include the calculation of the GA test values. |
test_M |
TRUE or FALSE flag to include the calculation of the MS test values. If response scores are not included, this test will not be performed. |
test_C |
TRUE or FALSE flag to include the calculation of the C test values. If response scores and treatment scores are not included, this test will not be performed. |
The unconditional CMH test results.
Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.
attach(job_satisfaction) a_ij = matrix(rep(c(3,10,20,35),2),nrow=4) b_hj = matrix(rep(c(1,3,4,5),2),nrow=4) unconditional_CMH(treatment = income, response = satisfaction, strata = gender, U = 2, V = 2, a_ij = a_ij, b_hj = b_hj)
attach(job_satisfaction) a_ij = matrix(rep(c(3,10,20,35),2),nrow=4) b_hj = matrix(rep(c(1,3,4,5),2),nrow=4) unconditional_CMH(treatment = income, response = satisfaction, strata = gender, U = 2, V = 2, a_ij = a_ij, b_hj = b_hj)
Ratings of different whiskeys of differing maturity.
data(whiskey)
data(whiskey)
A data frame with 8 rows and two columns.
the length of time the whiskey has matured for
grade applied to the whiskey. A lower score indicates a better whiskey
O'Mahony (1986, p.363)
Rayner, J.C.W. and Best, D.J. (2001). A Contingency Table Approach to Nonparametric Testing. Chapman & Hall/CRC: Boca Raton FL.
O'Mahony, M. (1986). Sensory Evaluation of Food - Statistical Methods and Procedures. Marcel Dekker: New York.
attach(whiskey) CMH(treatment = maturity, response = grade, a_ij = c(1,5,7), b_hj = 1:3, test_OPA = FALSE, test_GA = FALSE, test_MS = FALSE)
attach(whiskey) CMH(treatment = maturity, response = grade, a_ij = c(1,5,7), b_hj = 1:3, test_OPA = FALSE, test_GA = FALSE, test_MS = FALSE)