R Under development (unstable) (2023-12-02 r85657 ucrt) -- "Unsuffered Consequences" Copyright (C) 2023 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > # test.clm.single.anova.R > > library(ordinal) > > # WRE says "using if(requireNamespace("pkgname")) is preferred, if possible." > # even in tests: > assertError <- function(expr, ...) + if(requireNamespace("tools")) tools::assertError(expr, ...) else invisible() > assertWarning <- function(expr, ...) + if(requireNamespace("tools")) tools::assertWarning(expr, ...) else invisible() > > fm <- clm(rating ~ temp * contact, scale=~contact, data=wine) > > anova(fm, type="I") Type I Analysis of Deviance Table with Wald chi-square tests Df Chisq Pr(>Chisq) temp 1 17.1046 3.538e-05 *** contact 1 9.1574 0.002477 ** temp:contact 1 0.1097 0.740512 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > anova(fm, type="II") Type II Analysis of Deviance Table with Wald chi-square tests Df Chisq Pr(>Chisq) temp 1 17.1046 3.538e-05 *** contact 1 9.1574 0.002477 ** temp:contact 1 0.1097 0.740512 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > anova(fm, type="III") Type III Analysis of Deviance Table with Wald chi-square tests Df Chisq Pr(>Chisq) temp 1 9.5681 0.00198 ** contact 1 4.1830 0.04083 * temp:contact 1 0.1097 0.74051 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > anova(fm, type=1) Type I Analysis of Deviance Table with Wald chi-square tests Df Chisq Pr(>Chisq) temp 1 17.1046 3.538e-05 *** contact 1 9.1574 0.002477 ** temp:contact 1 0.1097 0.740512 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > anova(fm, type=2) Type II Analysis of Deviance Table with Wald chi-square tests Df Chisq Pr(>Chisq) temp 1 17.1046 3.538e-05 *** contact 1 9.1574 0.002477 ** temp:contact 1 0.1097 0.740512 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > anova(fm, type=3) Type III Analysis of Deviance Table with Wald chi-square tests Df Chisq Pr(>Chisq) temp 1 9.5681 0.00198 ** contact 1 4.1830 0.04083 * temp:contact 1 0.1097 0.74051 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > anova(fm, type="1") Type I Analysis of Deviance Table with Wald chi-square tests Df Chisq Pr(>Chisq) temp 1 17.1046 3.538e-05 *** contact 1 9.1574 0.002477 ** temp:contact 1 0.1097 0.740512 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > anova(fm, type="2") Type II Analysis of Deviance Table with Wald chi-square tests Df Chisq Pr(>Chisq) temp 1 17.1046 3.538e-05 *** contact 1 9.1574 0.002477 ** temp:contact 1 0.1097 0.740512 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > anova(fm, type="3") Type III Analysis of Deviance Table with Wald chi-square tests Df Chisq Pr(>Chisq) temp 1 9.5681 0.00198 ** contact 1 4.1830 0.04083 * temp:contact 1 0.1097 0.74051 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > anova(fm, type="marginal") Marginal Analysis of Deviance Table with Wald chi-square tests Df Chisq Pr(>Chisq) temp 1 9.5681 0.00198 ** contact 1 4.1830 0.04083 * temp:contact 1 0.1097 0.74051 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > > # Nominal effects: > fm <- clm(rating ~ temp, nominal=~contact, data=wine) > anova(fm) Type I Analysis of Deviance Table with Wald chi-square tests Df Chisq Pr(>Chisq) temp 1 22.166 2.501e-06 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > > # Flexible links: > fm1 <- clm(rating ~ temp + contact, link="log-gamma", data=wine) Changing to 'nlminb' optimizer for flexible link function Warning message: (-1) Model failed to converge with max|grad| = 9.93001e-05 (tol = 1e-06) > anova(fm1, type=1) Type I Analysis of Deviance Table with Wald chi-square tests Df Chisq Pr(>Chisq) temp 1 26.150 3.16e-07 *** contact 1 10.369 0.001282 ** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > anova(fm1, type=2) Type II Analysis of Deviance Table with Wald chi-square tests Df Chisq Pr(>Chisq) temp 1 26.150 3.16e-07 *** contact 1 10.369 0.001282 ** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > anova(fm1, type=3) Type III Analysis of Deviance Table with Wald chi-square tests Df Chisq Pr(>Chisq) temp 1 26.150 3.16e-07 *** contact 1 10.369 0.001282 ** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > > # Equivalence of tests irrespective of contrasts: > fm1 <- clm(SURENESS ~ PRODID * SOUPFREQ, data=soup) > # summary(fm1) > (an1 <- anova(fm1, type=3)) Type III Analysis of Deviance Table with Wald chi-square tests Df Chisq Pr(>Chisq) PRODID 5 72.5901 2.959e-14 *** SOUPFREQ 2 1.8132 0.4039 PRODID:SOUPFREQ 10 8.5837 0.5720 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > fm2 <- clm(SURENESS ~ PRODID * SOUPFREQ, data=soup, + contrasts = list(SOUPFREQ = "contr.sum", PRODID = "contr.SAS")) > # summary(fm2) > anova(fm1, fm2) Likelihood ratio tests of cumulative link models: formula: link: threshold: fm1 SURENESS ~ PRODID * SOUPFREQ logit flexible fm2 SURENESS ~ PRODID * SOUPFREQ logit flexible no.par AIC logLik LR.stat df Pr(>Chisq) fm1 22 5388 -2672 fm2 22 5388 -2672 0 0 > (an2 <- anova(fm2, type=3)) Type III Analysis of Deviance Table with Wald chi-square tests Df Chisq Pr(>Chisq) PRODID 5 72.5901 2.959e-14 *** SOUPFREQ 2 1.8132 0.4039 PRODID:SOUPFREQ 10 8.5837 0.5720 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > stopifnot( + isTRUE(all.equal(an1, an2, check.attributes=FALSE)) + ) > > > # Aliased coefficients: > fm1 <- clm(SURENESS ~ PRODID * DAY, data=soup) > anova(fm1, type=1) Type I Analysis of Deviance Table with Wald chi-square tests Df Chisq Pr(>Chisq) PRODID 5 185.2017 < 2e-16 *** DAY 1 4.1131 0.04255 * PRODID:DAY 4 5.1186 0.27534 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > anova(fm1, type=2) Type II Analysis of Deviance Table with Wald chi-square tests Df Chisq Pr(>Chisq) PRODID 5 181.5967 < 2e-16 *** DAY 1 4.1131 0.04255 * PRODID:DAY 4 5.1186 0.27534 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > anova(fm1, type=3) Missing cells for: PRODID3:DAY2. Interpret type III hypotheses with care. Type III Analysis of Deviance Table with Wald chi-square tests Df Chisq Pr(>Chisq) PRODID 5 76.3722 4.81e-15 *** DAY 1 10.1485 0.001444 ** PRODID:DAY 4 5.1186 0.275344 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > > # Aliased term (due to nominal effects): > fm <- clm(rating ~ temp * contact, nominal=~contact, data=wine) > anova(fm, type=1) Type I Analysis of Deviance Table with Wald chi-square tests Df Chisq Pr(>Chisq) temp 1 22.066 2.634e-06 *** contact temp:contact 1 0.250 0.6171 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > anova(fm, type=2) Type II Analysis of Deviance Table with Wald chi-square tests Df Chisq Pr(>Chisq) temp 1 22.066 2.634e-06 *** contact temp:contact 1 0.250 0.6171 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > anova(fm, type=3) Type III Analysis of Deviance Table with Wald chi-square tests Df Chisq Pr(>Chisq) temp 1 9.6335 0.001911 ** contact temp:contact 1 0.2500 0.617071 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > > # model with all NA in vcov(object): > fm <- clm(rating ~ temp * contact, nominal=~contact, scale=~contact, data=wine) Warning message: (1) Hessian is numerically singular: parameters are not uniquely determined In addition: Absolute and relative convergence criteria were met > assertError(anova(fm, type=1)) # error Loading required namespace: tools > assertError(anova(fm, type=2)) # error > assertError(anova(fm, type=3)) # error > all(is.na(vcov(fm))) [1] TRUE > > proc.time() user system elapsed 1.89 0.32 2.21