Package 'CMHNPA'

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

Help Index


ARL Test

Description

ARL returns the test statistic and p-value for the aligned RL test.

Usage

ARL(y, treatment, block1, block2)

Arguments

y

a numeric vector for the response variable.

treatment

a vector giving the treatment type for the corresponding elements of y.

block1

a vector giving the first blocking variable for the corresponding elements of y.

block2

a vector giving the second blocking variable for the corresponding elements of y.

Details

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.

Value

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.

References

Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.

See Also

CARL() PARL()

Examples

attach(peanuts)
ARL(y = yield, treatment = treatment, block1 = row, block2 = col)

Asbestos data

Description

A data set showing individuals' grade of asbestosis together with their length of expposure to asbestos.

Usage

data(asbestos)

Format

A data frame with 1117 rows and two columns.

exposure

a factor representing the number of years of exposure to asbestos

grade

a factor representing the grade of asbestosis. Grade 0 represents none present

Details

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.

Source

Selikoff IJ. Household risks with inorganic fibers. Bull N Y Acad Med. 1981 Dec;57(10):947-61.

References

Selikoff IJ. Household risks with inorganic fibers. Bull N Y Acad Med. 1981 Dec;57(10):947-61.

Examples

attach(asbestos)
KW(treatment = exposure, response = grade)

CARL Test

Description

CARL returns the test statistic and p-value for the aligned RL test with empirically fitted degrees of freedom.

Usage

CARL(
  y,
  treatment,
  block1,
  block2,
  n_components = 0,
  n_permutations = 0,
  treatment_scores = NULL,
  sig_digits = 4,
  verbose = FALSE
)

Arguments

y

a numeric vector for the response variable.

treatment

a vector giving the treatment type for the corresponding elements of y.

block1

a vector giving the first blocking variable for the corresponding elements of y.

block2

a vector giving the second blocking variable for the corresponding elements of y.

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 t-2, a remainder component is created.

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.

Details

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.

Value

The CARL test statistic adjusted for ties together with the associated p-value using a chi-squared distribution with t+1 degrees of freedom.

References

Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.

See Also

ARL() PARL()

Examples

attach(peanuts)
CARL(y = yield, treatment = treatment, block1 = row, block2 = col)

Cereal data

Description

Each of five breakfast cereals are ranked by ten judges, who each taste three cereals. Each cereal is assessed six times.

Usage

data(cereal)

Format

A data frame with 30 rows and three columns.

rank

the rank of the cereal within each judge block

judge

the judge that was used

type

the type of cereal

Details

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.

Source

Kutner et al. (2005, section 28.1)

References

Kutner, M., Nachtsheim, C., Neter, J. and Li, W. (2005). Applied linear statistical models (5th ed.). Boston: McGraw-Hill Irwin.

Examples

attach(cereal)
durbin(y = rank, groups = type, blocks = judge)

CMH Test

Description

CMH returns the test statistics and p-values for the four CMH tests.

Usage

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
)

Arguments

treatment

a factor vector representing the treatment applied.

response

a factor vector giving the response category for the corresponding elements of treatment.

strata

a factor vector giving the strata or block for the corresponding elements of treatment and 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_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.

Details

Provided the required information is used in the function, the function will return all four CMH test results.

Value

The CMH test results for the four tests assuming the required information is supplied.

References

Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.

Examples

CMH(treatment = marriage$religion, response = marriage$opinion,
strata = marriage$education, test_OPA = FALSE, test_MS = FALSE)

Corn data

Description

Corn yields when grown by four different methods.

Usage

data(corn)

Format

A data frame with 34 rows and two columns.

method

one of four different methods used to grow corn

outcome

corn yield categorised into four levels

Source

Rayner and Best (2001)

References

Rayner, J.C.W. and Best, D.J. (2001). A Contingency Table Approach to Nonparametric Testing. Chapman & Hall/CRC: Boca Raton FL.

Examples

attach(corn)
KW(treatment = method, response = outcome)

Cross-over data

Description

A success or fail response variable with three treatments repeated over 11 patients.

Usage

data(crossover)

Format

A data frame with 33 rows and three columns.

treatment

the type of treatment applied. The three treatments are placebo, aspirin and a new drug

success

whether the treatment was a success or not

patient

the patient the treatment was applied to

Details

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.

Source

StatXact (2003)

References

StatXact (2003). User Manual Volume 2. CYTEL Software.

Examples

attach(crossover)
CMH(treatment = treatment,response = success,strata = patient)

Durbin Test

Description

durbin returns the results of Durbin's Rank Sum test.

Usage

durbin(
  y,
  groups,
  blocks,
  n_components = 0,
  n_permutations = 0,
  group_scores = NULL,
  sig_digits = 4,
  verbose = FALSE
)

Arguments

y

a numeric vector for the response variable.

groups

a vector giving the group for the corresponding elements of y.

blocks

a vector giving the block for the corresponding elements of y.

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 t-2, a remainder component is created.

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.

Details

The test is a generalisation of Friedman's test that can be applied to BIBD.

Value

The Durbin test adjusted for tied results.

References

Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.

Examples

attach(icecream)
durbin(y = rank, groups = variety, blocks = judge)

Dynamite data

Description

A data set for the explosiveness of five different formulations of explosive.

Usage

data(dynamite)

Format

A data frame with 25 rows and four columns.

response

a numeric vector for the explosiveness of the formulation with corresponding treatment, batch and operator

treatment

a factor distinguishing the formulation for the explosive mixture

batch

a factor describing the batch the raw materials come from

operator

a factor describing the operator who prepares the explosive formulation

Details

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.

Source

https://www.fox.temple.edu/cms/wp-content/uploads/2016/05/Randomized-Block-Design.pdf

References

Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.

Examples

attach(dynamite)
CARL(y = response, treatment = treatment, block1 = batch, block2 = operator)

Food data

Description

Categorical responses made by 15 subjects for two different prices of the same food product. The data is from a CMH design.

Usage

data(food)

Format

A data frame with 30 rows and three columns.

price

a factor showing two price points for the product

decision

a factor indicating the decision of either buy, undecided, or not_buy the product

subject

a factor showing the individual making a decison about the product

References

Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.

Examples

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 Test

Description

friedman returns the test statistic and p-value for the Friedman test.

Usage

friedman(
  y,
  groups,
  blocks,
  n_components = 0,
  n_permutations = 0,
  group_scores = NULL,
  sig_digits = 4,
  verbose = FALSE
)

Arguments

y

a numeric vector for the response variable.

groups

a vector giving the group for the corresponding elements of y.

blocks

a vector giving the block for the corresponding elements of y.

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 t-2, a remainder component is created.

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.

Value

The Friedman test results statistic adjusted for ties together with the associated p-value.

References

Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.

Examples

attach(jam)
friedman(y = sweetness_ranks, groups = type, blocks = judge)

gen_cor Test

Description

gen_cor returns the generalised correlations and associated p-values together with tests of normality.

Usage

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
)

Arguments

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 x.

V

the maximum degree of correlation relating to the variable y.

W

the maximum degree of correlation relating to the variable z. Required when z is included.

x_scores

optional scores related to the variable x.

y_scores

optional scores related to the variable y.

z_scores

optional scores related to the variable z.

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.

Details

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.

Value

This function calculates the generalised correlations for up to three input variables.

References

Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.

Examples

attach(intelligence)
gen_cor(x = rank(score), y = age, U = 2, V = 2)

HR data

Description

Human resource ranking data.

Usage

data(hr)

Format

A data frame with 50 rows and three columns.

applicant

the applicant to which ratings are applied

applicant_ranking

the ranking from made by the committee member

committee_member

member of the selection panel that ranks five candidates

Details

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.

References

Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.

Examples

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

Description

Ice Cream data

Usage

data(icecream)

Format

A data frame with 21 rows and three columns.

rank

the rank of the ice cream within each judging block

judge

the judge that was used

variety

the type of ice cream that was tested

Details

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.

Source

Table 5.1 in Conover (1998, p. 391).

References

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.

Examples

attach(icecream)
durbin(y = rank, groups = variety, blocks = judge)

Intelligence data

Description

Intelligence scores for individuals from different age groups.

Usage

data(intelligence)

Format

A data frame with 15 rows and two columns.

age

age of the respondents

score

intelligence score achieved

Source

Rayner and Best (2001, section 8.1)

References

Rayner, J. C. W. and Best, D. J. (2001). A Contingency Table Approach to Nonparametric Testing. Boca Raton: Chapman & Hall/CRC.

Examples

attach(intelligence)
gen_cor(x = rank(score), y = age, U = 2, V = 2)

Jam data

Description

Plum jam sweetness data based on JAR judge scores.

Usage

data(jam)

Format

A data frame with 24 rows and four columns.

type

the type of jam that was tested

judge

the judge that was used for tasting

sweetness

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

sweetness_ranks

the ranks within judge

Details

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.

Source

Rayner and Best (2017, 2018)

References

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.

Examples

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

Description

Job satisfaction data based on income and gender.

Usage

data(job_satisfaction)

Format

A data frame with 104 rows and three columns.

income

income level categorised

satisfaction

the level of job satisfaction for the respondent

gender

gender of the respondent

Details

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.

Source

Agresti (2003)

References

Agresti, A. (2003). Categorical Data Analysis. Hoboken: John Wiley & Sons.

Examples

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

Description

KW returns the test statistic and p-value for the Kruskal-Wallis test adjusted for ties.

Usage

KW(
  treatment,
  response,
  n_components = 0,
  n_permutations = 0,
  treatment_scores = NULL,
  sig_digits = 4,
  verbose = FALSE
)

Arguments

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 t-2, a remainder component is created.

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.

Details

The Kruskal-Wallis test is a non-parametric equivalent to the one way ANOVA.

Value

The function returns the test result of the Kruskal Wallis test with adjustment for ties and without.

References

Rayner, J.C.W and Livingston Jr, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.

Examples

attach(whiskey)
KW(treatment = maturity, response = grade)

Lemonade data

Description

The Lemonade data set comes from a Randomised Block Design. There are four types of lemonades which are all tasted by five tasters.

Usage

data(lemonade)

Format

A data frame with 20 rows and three columns.

rank

the rank of the lemonade within each judging block

type

the type of lemonade that was tested

taster

the judge that was used for tasting

Source

Thas et al. (2012, section 4.2)

References

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.

Examples

attach(lemonade)
friedman(y = rank, groups = type, blocks = taster)

Lemonade Sugar data

Description

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.

Usage

data(lemonade_sugar)

Format

A data frame with 50 rows and three columns.

ranks

the rank each lemonade based on sugar content

sugar_content

type of lemonade ordered by sugar content

judge

the judge providing the ranking

References

Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.

Examples

attach(lemonade_sugar)
gen_cor(x = ranks, y = sugar_content, U = 3, V = 3, rounding = 3)

Lizard data

Description

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.

Usage

data(lizard)

Format

A data frame with 24 rows and three columns.

month

the month in which the measurements were taken

size

the size of the Eastern Horned Lizards

ants

the number of ants consumed

Source

Manly (2007)

References

Manly, B. F. J. (2007). Randomization, Bootstrap and Monte Carlo Methods in Biology, Third Edition. Boca Raton: Chapman & Hall/CRC.

Examples

attach(lizard)
gen_cor(x = ants, y = month, z = size, U = 3, V = 3, W = 1)

Marriage data

Description

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.

Usage

data(marriage)

Format

A data frame with 133 rows and three columns.

education

highest level of eduction for the respondent

religion

level of religiosity. Scores of 1, 2 and 3 are assigned to the religious categories fundamentalist, moderate and liberal respectively

opinion

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

Source

Agresti (2002)

References

Agresti, A. (2002). Categorical Data Analysis, 2nd ed; Wiley: New York.

Examples

attach(marriage)
lm(as.numeric(opinion)~religion+education)

Milk data

Description

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.

Usage

data(milk)

Format

A data frame with 16 rows and four columns.

production

a numerical measure of the milk production for the given diet, cow, and period

diet

a factor showing which diet the cow was administered

cow

a factor indicating the cow

period

a factor showing the relevant period

Source

https://www.stat.purdue.edu/~yuzhu/stat514fall05/Lecnot/latinsquarefall05.pdf

Examples

attach(milk)
CARL(y = production, treatment = diet, block1 = cow, block2 = period)

mu_r

Description

mu_r returns the estimated rth moment of a vector.

Usage

mu_r(x, r)

Arguments

x

a numeric vector.

r

the degree moment requiring calculation

Value

Returns the estimated rth moment of a vector.

References

Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.

Examples

x_vec = rnorm(10)
mu_r(x_vec,2)

np_anova function

Description

np_anova performs a nonparametric ANOVA.

Usage

np_anova(ordered_vars, predictor_vars, uvw)

Arguments

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 ordered_vars data frame.

Details

Nonparametric ANOVA is a methodology that is applicable where one as an ordered response variable as well as both ordered response and predictor variables.

Value

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.

References

Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.

Examples

attach(jam)
np_anova(ordered_vars = sweetness, predictor_vars = data.frame(type,judge), uvw = 1)

orthogonal_scores

Description

orthogonal_scores returns orthogonal scores weighted by prevalence in the data.

Usage

orthogonal_scores(x, degree, n_strata = 1)

Arguments

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.

Value

Returns a matrix of orthogonal scores.

References

Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.

Examples

attach(jam)
orthogonal_scores(x = sweetness, degree = 2, n_strata = 8)

PARL Test

Description

PARL returns the test statistic and p-value for the aligned RL test performed as a permutation test.

Usage

PARL(y, treatment, block1, block2, N_perms = 1000, components = FALSE)

Arguments

y

a numericc vector for the response variable.

treatment

a vector giving the treatment type for the corresponding elements of y.

block1

a vector giving the first blocking variable for the corresponding elements of y.

block2

a vector giving the second blocking variable for the corresponding elements of y.

N_perms

The number of permutations to perform.

components

a TRUE or FALSE flag to indicate whether component p-values should be calculated.

Details

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.

Value

The PARL test statistic together with the associated p-value. Component p-values may also be calculated and shown.

References

Rayner, J.C.W and Livingston Jr, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.

See Also

ARL() CARL()

Examples

attach(peanuts)
PARL(y = yield, treatment = treatment, block1 = row, block2 = col,
components = TRUE)

Peanuts data

Description

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

Usage

data(peanuts)

Format

A data frame with 16 rows and four columns.

yield

the peanut yield

treatment

the variety of peanut plant

row

the row the plants were grown in of the plot

col

the column the plants were grown in of the plot

Source

http://www.math.montana.edu/jobo/st541/sec3c.pdf

References

Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.

Examples

attach(peanuts)
CARL(y = yield, treatment = treatment, block1 = row, block2 = col)

Poly

Description

Poly returns t-1 orthonormal scores weighted by a weights parameter. The function uses Emerson Recursion.

Usage

Poly(x, p)

Arguments

x

a vector of numeric scores.

p

a vector of weights corresponding to the elements of x.

Value

Returns a matrix of orthomornal scores based on the weights provided.

References

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.

Examples

x = 1:5
p = rep(0.2,5)
Poly(x = x, p = p)

RL Test

Description

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.

Usage

RL(y, treatment, block1, block2)

Arguments

y

a numericc vector for the response variable.

treatment

a vector giving the treatment type for the corresponding elements of y.

block1

a vector giving the first blocking variable for the corresponding elements of y.

block2

a vector giving the second blocking variable for the corresponding elements of y.

Value

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.

References

Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.

See Also

ARL() CARL()

Examples

attach(peanuts)
RL(y = yield, treatment = treatment, block1 = row, block2 = col)

Row and column effects

Description

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.

Usage

row_col_effect(to_align, rows, cols)

Arguments

to_align

a numeric response vector.

rows

a vector giving the row effects for y.

cols

a vector giving the column effects for y.

Value

A vector of row and column effects. The response vector less this is the aligned response variable.

References

Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.

Examples

attach(peanuts)
row_col_effect(to_align = yield, rows = row, cols = col)

Saltiness data

Description

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.

Usage

data(saltiness)

Format

A data frame with 321 rows and three columns.

product

the type of product being tested

scores

the saltiness score. Scores of 1, 2 and 3 correspond to responses ‘not salty enough’, ‘just about right saltiness’ and ‘too salty’

participant

the participant providing the rating

Source

Rayner, J. C. W. and Best, D. J. (2017)

References

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.

Examples

attach(saltiness)
CMH(treatment = product, response = scores, strata = participant,
test_OPA = FALSE, test_MS = FALSE, test_C = FALSE)

Strawberry data

Description

Strawberry growth rates for different pesticides.

Usage

data(strawberry)

Format

A data frame with 28 rows and four columns.

block

the experimental block

pesticide

the pesticide applied to the plant. Pesticide O is a control.

response

a measure of the growth rate of strawberry plants with pesticide applied.

rank

rank of the response

Details

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.

Source

Pearce (1960)

References

Pearce, S.C. (1960). Supplemented balanced. Biometrika, 47, 263-271.

Examples

attach(strawberry)
lm_strawberry = lm(rank~pesticide+block)
anova(lm_strawberry)

T_Mu statistic

Description

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.

Usage

T_Mu(treatment, response, strata = NULL, degree)

Arguments

treatment

a vector of treatment values.

response

a vector of response values.

strata

a variable defining the strata.

degree

the degree assessment required.

Value

The function returns the test statistic for an unconditional CMH MS equivalent test of required degree.

References

Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.

See Also

unconditional_CMH()

Examples

attach(job_satisfaction)
T_Mu(treatment = income, response = as.numeric(satisfaction),
strata = gender, degree = 1)

Traffic data

Description

Traffic light data for different light sequences, intersections, and times of day.

Usage

data(traffic)

Format

A data frame with 25 rows and four columns.

minutes

the amount of unused red-light time in minutes

treatment

the traffic light sequence

intersection

the intersection the treatment was applied

time_of_day

the time of the day the treatment was applied

Details

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.

Source

Kuehl, R. (2000)

References

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.

Examples

attach(traffic)
np_anova(ordered_vars = rank(minutes),
predictor_vars = data.frame(treatment,intersection,time_of_day), uvw = 1)

Unconditional CMH Test

Description

unconditional_CMH returns the test statistics and p-values for the equivalent unconditional CMH tests.

Usage

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
)

Arguments

treatment

a factor vector representing the treatment applied.

response

a factor vector giving the response category for the corresponding elements of treatment.

strata

a factor vector giving the strata or block for the corresponding elements of treatment and response.

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.

Value

The unconditional CMH test results.

References

Rayner, J.C.W and Livingston, G. C. (2022). An Introduction to Cochran-Mantel-Haenszel Testing and Nonparametric ANOVA. Wiley.

Examples

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)

Whiskey data

Description

Ratings of different whiskeys of differing maturity.

Usage

data(whiskey)

Format

A data frame with 8 rows and two columns.

maturity

the length of time the whiskey has matured for

grade

grade applied to the whiskey. A lower score indicates a better whiskey

Source

O'Mahony (1986, p.363)

References

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.

Examples

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)