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. > library(ordinal) > data(wine) > > ## clm.fit with nominal and scale effects: > > ## get simple model: > fm1 <- clm(rating ~ temp, scale=~temp, nominal=~ contact, + data=wine, method="design") > str(fm1, give.attr=FALSE) List of 23 $ y : Ord.factor w/ 5 levels "1"<"2"<"3"<"4"<..: 2 3 3 4 4 4 5 5 1 2 ... $ y.levels : chr [1:5] "1" "2" "3" "4" ... $ X : num [1:72, 1:2] 1 1 1 1 1 1 1 1 1 1 ... $ offset : num [1:72] 0 0 0 0 0 0 0 0 0 0 ... $ terms :Classes 'terms', 'formula' language rating ~ temp $ contrasts :List of 1 ..$ temp: chr "contr.treatment" $ xlevels :List of 1 ..$ temp: chr [1:2] "cold" "warm" $ weights : num [1:72] 1 1 1 1 1 1 1 1 1 1 ... $ S : num [1:72, 1:2] 1 1 1 1 1 1 1 1 1 1 ... $ S.terms :Classes 'terms', 'formula' language ~temp $ S.off : num [1:72] 0 0 0 0 0 0 0 0 0 0 ... $ S.contrasts :List of 1 ..$ temp: chr "contr.treatment" $ S.xlevels :List of 1 ..$ temp: chr [1:2] "cold" "warm" $ NOM : num [1:72, 1:2] 1 1 1 1 1 1 1 1 1 1 ... $ nom.terms :Classes 'terms', 'formula' language ~contact $ nom.contrasts:List of 1 ..$ contact: chr "contr.treatment" $ nom.xlevels :List of 1 ..$ contact: chr [1:2] "no" "yes" $ doFit : logi TRUE $ control :List of 11 ..$ method : chr "design" ..$ sign.location: chr "negative" ..$ sign.nominal : chr "positive" ..$ convergence : chr "warn" ..$ trace : int 0 ..$ maxIter : int 100 ..$ gradTol : num 1e-06 ..$ relTol : num 1e-06 ..$ tol : num 1.49e-08 ..$ maxLineIter : int 15 ..$ maxModIter : int 5 $ link : chr "logit" $ threshold : chr "flexible" $ start : NULL $ formulas :List of 4 ..$ formula :Class 'formula' language rating ~ temp ..$ scale :Class 'formula' language ~temp ..$ nominal :Class 'formula' language ~contact ..$ fullForm:Class 'formula' language rating ~ temp + temp + contact > fm1$control$method <- "Newton" > res <- clm.fit(fm1) > names(res) [1] "Hessian" "Theta" "aliased" "alpha" [5] "alpha.mat" "beta" "coefficients" "cond.H" [9] "convergence" "df.residual" "edf" "fitted.values" [13] "gradient" "logLik" "maxGradient" "message" [17] "n" "niter" "nobs" "tJac" [21] "vcov" "zeta" > res$Theta contact 1|2 2|3 3|4 4|5 1 no -1.357136 1.2482871 3.839568 5.114111 2 yes -2.969353 -0.2819631 1.959306 3.923477 > > ## construct some weights and offsets: > set.seed(1) > off1 <- runif(length(fm1$y)) > set.seed(1) > off2 <- rnorm(length(fm1$y)) > set.seed(1) > wet <- runif(length(fm1$y)) > > ## Fit various models: > fit <- clm.fit(fm1$y, fm1$X, fm1$S, fm1$NOM, weights=wet) Warning message: Cannot assess if all thresholds are increasing > Coef <- + c(-0.905224120279548, 1.31043498891987, 3.34235590523008, + 4.52389661722693, -3.03954652971192, -1.56922389038976, + -1.75662549320839, -1.16845464236365, 2.52988580848393, + -0.0261457032829033) > stopifnot(all.equal(coef(fit), Coef, check.attributes=FALSE, tol=1e-6)) > str(fit) List of 20 $ Hessian : num [1:10, 1:10] 2.488 -1.01 0 0 0.207 ... ..- attr(*, "dimnames")=List of 2 .. ..$ : chr [1:10] "1|2.(Intercept)" "2|3.(Intercept)" "3|4.(Intercept)" "4|5.(Intercept)" ... .. ..$ : chr [1:10] "1|2.(Intercept)" "2|3.(Intercept)" "3|4.(Intercept)" "4|5.(Intercept)" ... $ aliased :List of 3 ..$ alpha: Named logi [1:8] FALSE FALSE FALSE FALSE FALSE FALSE ... .. ..- attr(*, "names")= chr [1:8] "1|2.(Intercept)" "2|3.(Intercept)" "3|4.(Intercept)" "4|5.(Intercept)" ... ..$ beta : Named logi FALSE .. ..- attr(*, "names")= chr "tempwarm" ..$ zeta : Named logi FALSE .. ..- attr(*, "names")= chr "tempwarm" $ alpha : Named num [1:8] -0.905 1.31 3.342 4.524 -3.04 ... ..- attr(*, "names")= chr [1:8] "1|2.(Intercept)" "2|3.(Intercept)" "3|4.(Intercept)" "4|5.(Intercept)" ... $ beta : Named num 2.53 ..- attr(*, "names")= chr "tempwarm" $ coefficients : Named num [1:10] -0.905 1.31 3.342 4.524 -3.04 ... ..- attr(*, "names")= chr [1:10] "1|2.(Intercept)" "2|3.(Intercept)" "3|4.(Intercept)" "4|5.(Intercept)" ... $ cond.H : num 161 $ convergence :List of 3 ..$ code : int 0 ..$ messages : chr "successful convergence" ..$ alg.message: chr "Absolute and relative convergence criteria were met" $ df.residual : num 27 $ edf : int 10 $ fitted.values: num [1:72] 0.5 0.178 0.394 0.136 0.188 ... $ gradient : Named num [1:10] 7.85e-15 2.69e-13 2.68e-13 -5.17e-13 3.75e-16 ... ..- attr(*, "names")= chr [1:10] "1|2.(Intercept)" "2|3.(Intercept)" "3|4.(Intercept)" "4|5.(Intercept)" ... $ logLik : num -44.9 $ maxGradient : num 8.91e-13 $ message : chr "Absolute and relative convergence criteria were met" $ n : int 72 $ niter : Named num [1:2] 9 0 ..- attr(*, "names")= chr [1:2] "outer" "inner" $ nobs : num 37 $ tJac : num [1:4, 1:4] 1 0 0 0 0 1 0 0 0 0 ... ..- attr(*, "dimnames")=List of 2 .. ..$ : chr [1:4] "1|2" "2|3" "3|4" "4|5" .. ..$ : chr [1:4] "1|2" "2|3" "3|4" "4|5" $ vcov : num [1:10, 1:10] 0.5338 0.1835 0.0254 -0.0626 -0.511 ... ..- attr(*, "dimnames")=List of 2 .. ..$ : chr [1:10] "1|2.(Intercept)" "2|3.(Intercept)" "3|4.(Intercept)" "4|5.(Intercept)" ... .. ..$ : chr [1:10] "1|2.(Intercept)" "2|3.(Intercept)" "3|4.(Intercept)" "4|5.(Intercept)" ... $ zeta : Named num -0.0261 ..- attr(*, "names")= chr "tempwarm" - attr(*, "class")= chr "clm.fit" > > fit <- clm.fit(fm1$y, fm1$X, fm1$S, fm1$NOM, offset=off1) Warning message: Cannot assess if all thresholds are increasing > str(fit) List of 20 $ Hessian : num [1:10, 1:10] 4.48 -1.89 0 0 1.02 ... ..- attr(*, "dimnames")=List of 2 .. ..$ : chr [1:10] "1|2.(Intercept)" "2|3.(Intercept)" "3|4.(Intercept)" "4|5.(Intercept)" ... .. ..$ : chr [1:10] "1|2.(Intercept)" "2|3.(Intercept)" "3|4.(Intercept)" "4|5.(Intercept)" ... $ aliased :List of 3 ..$ alpha: Named logi [1:8] FALSE FALSE FALSE FALSE FALSE FALSE ... .. ..- attr(*, "names")= chr [1:8] "1|2.(Intercept)" "2|3.(Intercept)" "3|4.(Intercept)" "4|5.(Intercept)" ... ..$ beta : Named logi FALSE .. ..- attr(*, "names")= chr "tempwarm" ..$ zeta : Named logi FALSE .. ..- attr(*, "names")= chr "tempwarm" $ alpha : Named num [1:8] -0.864 1.746 4.342 5.615 -1.567 ... ..- attr(*, "names")= chr [1:8] "1|2.(Intercept)" "2|3.(Intercept)" "3|4.(Intercept)" "4|5.(Intercept)" ... $ beta : Named num 2.7 ..- attr(*, "names")= chr "tempwarm" $ coefficients : Named num [1:10] -0.864 1.746 4.342 5.615 -1.567 ... ..- attr(*, "names")= chr [1:10] "1|2.(Intercept)" "2|3.(Intercept)" "3|4.(Intercept)" "4|5.(Intercept)" ... $ cond.H : num 196 $ convergence :List of 3 ..$ code : int 0 ..$ messages : chr "successful convergence" ..$ alg.message: chr "Absolute and relative convergence criteria were met" $ df.residual : num 62 $ edf : int 10 $ fitted.values: num [1:72] 0.57 0.183 0.452 0.145 0.135 ... $ gradient : Named num [1:10] 2.19e-09 6.14e-08 5.92e-08 -1.23e-07 4.69e-10 ... ..- attr(*, "names")= chr [1:10] "1|2.(Intercept)" "2|3.(Intercept)" "3|4.(Intercept)" "4|5.(Intercept)" ... $ logLik : num -86.1 $ maxGradient : num 2.17e-07 $ message : chr "Absolute and relative convergence criteria were met" $ n : int 72 $ niter : Named num [1:2] 8 0 ..- attr(*, "names")= chr [1:2] "outer" "inner" $ nobs : num 72 $ tJac : num [1:4, 1:4] 1 0 0 0 0 1 0 0 0 0 ... ..- attr(*, "dimnames")=List of 2 .. ..$ : chr [1:4] "1|2" "2|3" "3|4" "4|5" .. ..$ : chr [1:4] "1|2" "2|3" "3|4" "4|5" $ vcov : num [1:10, 1:10] 0.33117 0.09074 0.00108 -0.04015 -0.31468 ... ..- attr(*, "dimnames")=List of 2 .. ..$ : chr [1:10] "1|2.(Intercept)" "2|3.(Intercept)" "3|4.(Intercept)" "4|5.(Intercept)" ... .. ..$ : chr [1:10] "1|2.(Intercept)" "2|3.(Intercept)" "3|4.(Intercept)" "4|5.(Intercept)" ... $ zeta : Named num 0.114 ..- attr(*, "names")= chr "tempwarm" - attr(*, "class")= chr "clm.fit" > > fit <- clm.fit(fm1$y, fm1$X, fm1$S, fm1$NOM, offset=off1, + S.offset=off2) Warning message: Cannot assess if all thresholds are increasing > str(fit) List of 20 $ Hessian : num [1:10, 1:10] 4.126 -1.006 0 0 0.079 ... ..- attr(*, "dimnames")=List of 2 .. ..$ : chr [1:10] "1|2.(Intercept)" "2|3.(Intercept)" "3|4.(Intercept)" "4|5.(Intercept)" ... .. ..$ : chr [1:10] "1|2.(Intercept)" "2|3.(Intercept)" "3|4.(Intercept)" "4|5.(Intercept)" ... $ aliased :List of 3 ..$ alpha: Named logi [1:8] FALSE FALSE FALSE FALSE FALSE FALSE ... .. ..- attr(*, "names")= chr [1:8] "1|2.(Intercept)" "2|3.(Intercept)" "3|4.(Intercept)" "4|5.(Intercept)" ... ..$ beta : Named logi FALSE .. ..- attr(*, "names")= chr "tempwarm" ..$ zeta : Named logi FALSE .. ..- attr(*, "names")= chr "tempwarm" $ alpha : Named num [1:8] -0.585 1.951 3.24 4.18 -6.481 ... ..- attr(*, "names")= chr [1:8] "1|2.(Intercept)" "2|3.(Intercept)" "3|4.(Intercept)" "4|5.(Intercept)" ... $ beta : Named num 2.12 ..- attr(*, "names")= chr "tempwarm" $ coefficients : Named num [1:10] -0.585 1.951 3.24 4.18 -6.481 ... ..- attr(*, "names")= chr [1:10] "1|2.(Intercept)" "2|3.(Intercept)" "3|4.(Intercept)" "4|5.(Intercept)" ... $ cond.H : num 634 $ convergence :List of 3 ..$ code : int 0 ..$ messages : chr "successful convergence" ..$ alg.message: chr "Absolute and relative convergence criteria were met" $ df.residual : num 62 $ edf : int 10 $ fitted.values: num [1:72] 0.7899 0.1277 0.7 0.0888 0.1521 ... $ gradient : Named num [1:10] 6.72e-12 8.06e-10 7.28e-10 -7.85e-10 1.15e-12 ... ..- attr(*, "names")= chr [1:10] "1|2.(Intercept)" "2|3.(Intercept)" "3|4.(Intercept)" "4|5.(Intercept)" ... $ logLik : num -87.6 $ maxGradient : num 9.74e-10 $ message : chr "Absolute and relative convergence criteria were met" $ n : int 72 $ niter : Named num [1:2] 13 0 ..- attr(*, "names")= chr [1:2] "outer" "inner" $ nobs : num 72 $ tJac : num [1:4, 1:4] 1 0 0 0 0 1 0 0 0 0 ... ..- attr(*, "dimnames")=List of 2 .. ..$ : chr [1:4] "1|2" "2|3" "3|4" "4|5" .. ..$ : chr [1:4] "1|2" "2|3" "3|4" "4|5" $ vcov : num [1:10, 1:10] 0.2616 0.0523 0.0345 0.0236 -0.2449 ... ..- attr(*, "dimnames")=List of 2 .. ..$ : chr [1:10] "1|2.(Intercept)" "2|3.(Intercept)" "3|4.(Intercept)" "4|5.(Intercept)" ... .. ..$ : chr [1:10] "1|2.(Intercept)" "2|3.(Intercept)" "3|4.(Intercept)" "4|5.(Intercept)" ... $ zeta : Named num -0.502 ..- attr(*, "names")= chr "tempwarm" - attr(*, "class")= chr "clm.fit" > > fit <- clm.fit(fm1$y, fm1$X, fm1$S) > str(fit) List of 21 $ Hessian : num [1:6, 1:6] 4.8066 -2.4889 0 0 -0.0926 ... ..- attr(*, "dimnames")=List of 2 .. ..$ : chr [1:6] "1|2" "2|3" "3|4" "4|5" ... .. ..$ : chr [1:6] "1|2" "2|3" "3|4" "4|5" ... $ Theta : num [1, 1:4] -1.988 0.418 2.648 4.306 ..- attr(*, "dimnames")=List of 2 .. ..$ : NULL .. ..$ : chr [1:4] "1|2" "2|3" "3|4" "4|5" $ aliased :List of 3 ..$ alpha: Named logi [1:4] FALSE FALSE FALSE FALSE .. ..- attr(*, "names")= chr [1:4] "1|2" "2|3" "3|4" "4|5" ..$ beta : Named logi FALSE .. ..- attr(*, "names")= chr "tempwarm" ..$ zeta : Named logi FALSE .. ..- attr(*, "names")= chr "tempwarm" $ alpha : Named num [1:4] -1.988 0.418 2.648 4.306 ..- attr(*, "names")= chr [1:4] "1|2" "2|3" "3|4" "4|5" $ beta : Named num 2.51 ..- attr(*, "names")= chr "tempwarm" $ coefficients : Named num [1:6] -1.988 0.418 2.648 4.306 2.512 ... ..- attr(*, "names")= chr [1:6] "1|2" "2|3" "3|4" "4|5" ... $ cond.H : num 80.6 $ convergence :List of 3 ..$ code : int 0 ..$ messages : chr "successful convergence" ..$ alg.message: chr "Absolute and relative convergence criteria were met" $ df.residual : num 66 $ edf : int 6 $ fitted.values: num [1:72] 0.4826 0.3308 0.3308 0.0528 0.2897 ... $ gradient : Named num [1:6] 7.03e-09 6.91e-08 5.99e-07 -7.42e-07 2.76e-08 ... ..- attr(*, "names")= chr [1:6] "1|2" "2|3" "3|4" "4|5" ... $ logLik : num -91.8 $ maxGradient : num 8.53e-07 $ message : chr "Absolute and relative convergence criteria were met" $ n : int 72 $ niter : Named num [1:2] 8 0 ..- attr(*, "names")= chr [1:2] "outer" "inner" $ nobs : num 72 $ tJac : num [1:4, 1:4] 1 0 0 0 0 1 0 0 0 0 ... ..- attr(*, "dimnames")=List of 2 .. ..$ : chr [1:4] "1|2" "2|3" "3|4" "4|5" .. ..$ : chr [1:4] "1|2" "2|3" "3|4" "4|5" $ vcov : num [1:6, 1:6] 0.2481 0.0622 0.0179 -0.0253 0.0197 ... ..- attr(*, "dimnames")=List of 2 .. ..$ : chr [1:6] "1|2" "2|3" "3|4" "4|5" ... .. ..$ : chr [1:6] "1|2" "2|3" "3|4" "4|5" ... $ zeta : Named num 0.176 ..- attr(*, "names")= chr "tempwarm" - attr(*, "class")= chr "clm.fit" > > fit <- clm.fit(fm1$y, fm1$X) > str(fit) List of 20 $ Hessian : num [1:5, 1:5] 4.8983 -2.499 0 0 -0.0854 ... ..- attr(*, "dimnames")=List of 2 .. ..$ : chr [1:5] "1|2" "2|3" "3|4" "4|5" ... .. ..$ : chr [1:5] "1|2" "2|3" "3|4" "4|5" ... $ Theta : num [1, 1:4] -1.936 0.435 2.432 3.827 ..- attr(*, "dimnames")=List of 2 .. ..$ : NULL .. ..$ : chr [1:4] "1|2" "2|3" "3|4" "4|5" $ aliased :List of 2 ..$ alpha: Named logi [1:4] FALSE FALSE FALSE FALSE .. ..- attr(*, "names")= chr [1:4] "1|2" "2|3" "3|4" "4|5" ..$ beta : Named logi FALSE .. ..- attr(*, "names")= chr "tempwarm" $ alpha : Named num [1:4] -1.936 0.435 2.432 3.827 ..- attr(*, "names")= chr [1:4] "1|2" "2|3" "3|4" "4|5" $ beta : Named num 2.29 ..- attr(*, "names")= chr "tempwarm" $ coefficients : Named num [1:5] -1.936 0.435 2.432 3.827 2.287 ..- attr(*, "names")= chr [1:5] "1|2" "2|3" "3|4" "4|5" ... $ cond.H : num 16.8 $ convergence :List of 3 ..$ code : int 0 ..$ messages : chr "successful convergence" ..$ alg.message: chr "Absolute and relative convergence criteria were met" $ df.residual : num 67 $ edf : int 5 $ fitted.values: num [1:72] 0.481 0.3122 0.3122 0.0594 0.2871 ... $ gradient : Named num [1:5] 4.07e-14 8.24e-14 -9.90e-14 6.66e-16 -2.22e-14 ..- attr(*, "names")= chr [1:5] "1|2" "2|3" "3|4" "4|5" ... $ logLik : num -92 $ maxGradient : num 9.9e-14 $ message : chr "Absolute and relative convergence criteria were met" $ n : int 72 $ niter : Named num [1:2] 6 0 ..- attr(*, "names")= chr [1:2] "outer" "inner" $ nobs : num 72 $ tJac : num [1:4, 1:4] 1 0 0 0 0 1 0 0 0 0 ... ..- attr(*, "dimnames")=List of 2 .. ..$ : chr [1:4] "1|2" "2|3" "3|4" "4|5" .. ..$ : chr [1:4] "1|2" "2|3" "3|4" "4|5" $ vcov : num [1:5, 1:5] 0.2345 0.0577 0.0505 0.0512 0.0537 ... ..- attr(*, "dimnames")=List of 2 .. ..$ : chr [1:5] "1|2" "2|3" "3|4" "4|5" ... .. ..$ : chr [1:5] "1|2" "2|3" "3|4" "4|5" ... - attr(*, "class")= chr "clm.fit" > > fit <- clm.fit(fm1$y) > coef(fit) 1|2 2|3 3|4 4|5 -2.5952547 -0.5108256 1.0258529 2.2284771 > str(fit) List of 19 $ Hessian : num [1:4, 1:4] 5.31 -3.57 0 0 -3.57 ... ..- attr(*, "dimnames")=List of 2 .. ..$ : chr [1:4] "1|2" "2|3" "3|4" "4|5" .. ..$ : chr [1:4] "1|2" "2|3" "3|4" "4|5" $ Theta : num [1, 1:4] -2.595 -0.511 1.026 2.228 ..- attr(*, "dimnames")=List of 2 .. ..$ : NULL .. ..$ : chr [1:4] "1|2" "2|3" "3|4" "4|5" $ aliased :List of 2 ..$ alpha: Named logi [1:4] FALSE FALSE FALSE FALSE .. ..- attr(*, "names")= chr [1:4] "1|2" "2|3" "3|4" "4|5" ..$ beta : Named logi(0) .. ..- attr(*, "names")= chr(0) $ alpha : Named num [1:4] -2.595 -0.511 1.026 2.228 ..- attr(*, "names")= chr [1:4] "1|2" "2|3" "3|4" "4|5" $ coefficients : Named num [1:4] -2.595 -0.511 1.026 2.228 ..- attr(*, "names")= chr [1:4] "1|2" "2|3" "3|4" "4|5" $ cond.H : num 8.38 $ convergence :List of 3 ..$ code : int 0 ..$ messages : chr "successful convergence" ..$ alg.message: chr "Absolute and relative convergence criteria were met" $ df.residual : num 68 $ edf : int 4 $ fitted.values: num [1:72] 0.306 0.361 0.361 0.167 0.167 ... $ gradient : Named num [1:4] 7.23e-08 -5.51e-08 -1.72e-11 -4.86e-12 ..- attr(*, "names")= chr [1:4] "1|2" "2|3" "3|4" "4|5" $ logLik : num -104 $ maxGradient : num 7.23e-08 $ message : chr "Absolute and relative convergence criteria were met" $ n : int 72 $ niter : Named num [1:2] 5 0 ..- attr(*, "names")= chr [1:2] "outer" "inner" $ nobs : num 72 $ tJac : num [1:4, 1:4] 1 0 0 0 0 1 0 0 0 0 ... ..- attr(*, "dimnames")=List of 2 .. ..$ : chr [1:4] "1|2" "2|3" "3|4" "4|5" .. ..$ : chr [1:4] "1|2" "2|3" "3|4" "4|5" $ vcov : num [1:4, 1:4] 0.2149 0.0398 0.0203 0.0165 0.0398 ... ..- attr(*, "dimnames")=List of 2 .. ..$ : chr [1:4] "1|2" "2|3" "3|4" "4|5" .. ..$ : chr [1:4] "1|2" "2|3" "3|4" "4|5" - attr(*, "class")= chr "clm.fit" > > ## Remember: compare with corresponding .Rout file > > proc.time() user system elapsed 1.60 0.20 1.81