psychotree/0000755000176200001440000000000015040607541012441 5ustar liggesuserspsychotree/tests/0000755000176200001440000000000014220024137013574 5ustar liggesuserspsychotree/tests/Examples/0000755000176200001440000000000014220024137015352 5ustar liggesuserspsychotree/tests/Examples/psychotree-Ex.Rout.save0000644000176200001440000007165014232641101021731 0ustar liggesusers R version 4.2.0 (2022-04-22) -- "Vigorous Calisthenics" Copyright (C) 2022 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) 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. Natural language support but running in an English locale 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. > pkgname <- "psychotree" > source(file.path(R.home("share"), "R", "examples-header.R")) > options(warn = 1) > library('psychotree') Loading required package: partykit Loading required package: grid Loading required package: libcoin Loading required package: mvtnorm Loading required package: psychotools > > base::assign(".oldSearch", base::search(), pos = 'CheckExEnv') > base::assign(".old_wd", base::getwd(), pos = 'CheckExEnv') > cleanEx() > nameEx("CEMSChoice") > ### * CEMSChoice > > flush(stderr()); flush(stdout()) > > ### Name: CEMSChoice > ### Title: CEMS University Choice Data > ### Aliases: CEMSChoice > ### Keywords: datasets > > ### ** Examples > > data("CEMSChoice", package = "psychotree") > summary(CEMSChoice$preference) > = < NA's London : Paris 186 26 91 0 London : Milano 221 26 56 0 Paris : Milano 121 32 59 91 London : StGallen 208 22 73 0 Paris : StGallen 165 19 119 0 Milano : StGallen 135 28 140 0 London : Barcelona 217 19 67 0 Paris : Barcelona 157 37 109 0 Milano : Barcelona 104 67 132 0 StGallen : Barcelona 144 25 134 0 London : Stockholm 250 19 34 0 Paris : Stockholm 203 30 70 0 Milano : Stockholm 157 46 100 0 StGallen : Stockholm 155 50 98 0 Barcelona : Stockholm 172 41 90 0 > covariates(CEMSChoice$preference) specialization location London economics other Paris management science latin Milano economics latin StGallen finance other Barcelona management science latin Stockholm finance other > > > > cleanEx() > nameEx("DIFSim") > ### * DIFSim > > flush(stderr()); flush(stdout()) > > ### Name: DIFSim > ### Title: Artificial Data with Differential Item Functioning > ### Aliases: DIFSim DIFSimPC > ### Keywords: datasets > > ### ** Examples > > ## data > data("DIFSim", package = "psychotree") > data("DIFSimPC", package = "psychotree") > > ## summary of covariates > summary(DIFSim[, -1]) age gender motivation Min. :16.00 male :109 1:23 1st Qu.:31.00 female: 91 2:41 Median :45.00 3:45 Mean :45.84 4:35 3rd Qu.:60.00 5:41 Max. :74.00 6:15 > summary(DIFSimPC[, -1]) age gender motivation Min. :20.00 male :239 1:125 1st Qu.:35.00 female:261 2: 88 Median :49.00 3: 96 Mean :49.69 4: 90 3rd Qu.:64.00 5:101 Max. :80.00 > > ## empirical frequencies of responses > plot(DIFSim$resp) > plot(DIFSimPC$resp) > > ## histogram of raw scores > hist(rowSums(DIFSim$resp), breaks = 0:20 - 0.5) > hist(rowSums(DIFSimPC$resp), breaks = 0:17 - 0.5) > > > > cleanEx() > nameEx("EuropeanValuesStudy") > ### * EuropeanValuesStudy > > flush(stderr()); flush(stdout()) > > ### Name: EuropeanValuesStudy > ### Title: European Values Study > ### Aliases: EuropeanValuesStudy > ### Keywords: datasets > > ### ** Examples > > ## data > data("EuropeanValuesStudy", package = "psychotree") > summary(EuropeanValuesStudy$paircomp) > < NA's order : decisions 2136 1293 155 order : prices 2178 949 457 decisions : prices 1694 1335 555 order : freedom 2358 761 465 decisions : freedom 1732 860 992 prices : freedom 1558 1066 960 > > ## Not run: > ##D ## Bradley-Terry tree resulting in similar results compared to > ##D ## the (different) tree approach of Lee and Lee (2010) > ##D evs <- na.omit(EuropeanValuesStudy) > ##D bt <- bttree(paircomp ~ gender + eduage + birthyear + marital + employment + income + country2, > ##D data = evs, alpha = 0.01) > ##D plot(bt, abbreviate = 2) > ## End(Not run) > > > > cleanEx() > nameEx("SPISA") > ### * SPISA > > flush(stderr()); flush(stdout()) > > ### Name: SPISA > ### Title: SPIEGEL Studentenpisa Data (Subsample) > ### Aliases: SPISA > ### Keywords: datasets > > ### ** Examples > > ## data > data("SPISA", package = "psychotree") > > ## summary of covariates > summary(SPISA[,-1]) gender age semester elite spon female:417 Min. :18.0 2 :173 no :836 never :303 male :658 1st Qu.:21.0 4 :123 yes:239 <1/month :127 Median :23.0 6 :116 1-3/month:107 Mean :23.1 1 :105 1/week : 79 3rd Qu.:25.0 5 : 99 2-3/week : 73 Max. :40.0 3 : 98 4-5/week : 60 (Other):361 daily :326 > > ## histogram of raw scores > hist(rowSums(SPISA$spisa), breaks = 0:45 + 0.5) > > ## Not run: > ##D ## See the following vignette for a tree-based DIF analysis > ##D vignette("raschtree", package = "psychotree") > ## End(Not run) > > > > cleanEx() > nameEx("Topmodel2007") > ### * Topmodel2007 > > flush(stderr()); flush(stdout()) > > ### Name: Topmodel2007 > ### Title: Attractiveness of Germany's Next Topmodels 2007 > ### Aliases: Topmodel2007 > ### Keywords: datasets > > ### ** Examples > > data("Topmodel2007", package = "psychotree") > summary(Topmodel2007$preference) > < Barbara : Anni 121 71 Barbara : Hana 98 94 Anni : Hana 75 117 Barbara : Fiona 101 91 Anni : Fiona 81 111 Hana : Fiona 113 79 Barbara : Mandy 130 62 Anni : Mandy 114 78 Hana : Mandy 130 62 Fiona : Mandy 131 61 Barbara : Anja 123 69 Anni : Anja 112 80 Hana : Anja 130 62 Fiona : Anja 119 73 Mandy : Anja 92 100 > xtabs(~ gender + I(age < 30), data = Topmodel2007) I(age < 30) gender FALSE TRUE male 48 48 female 48 48 > > > > cleanEx() > nameEx("bttree") > ### * bttree > > flush(stderr()); flush(stdout()) > > ### Name: bttree > ### Title: Bradley-Terry Trees > ### Aliases: bttree plot.bttree print.bttree predict.bttree itempar.bttree > ### Keywords: tree > > ### ** Examples > > o <- options(digits = 4) > > ## Germany's Next Topmodel 2007 data > data("Topmodel2007", package = "psychotree") > > ## BT tree > tm_tree <- bttree(preference ~ ., data = Topmodel2007, minsize = 5, ref = "Barbara") > plot(tm_tree, abbreviate = 1, yscale = c(0, 0.5)) > > ## parameter instability tests in root node > if(require("strucchange")) sctest(tm_tree, node = 1) Loading required package: strucchange Loading required package: zoo Attaching package: ‘zoo’ The following objects are masked from ‘package:base’: as.Date, as.Date.numeric Loading required package: sandwich gender age q1 q2 q3 statistic 17.08798 3.236e+01 12.6320 19.83922 6.7586 p.value 0.02149 7.915e-04 0.1283 0.00668 0.7452 > > ## worth/item parameters in terminal nodes > itempar(tm_tree) Barbara Anni Hana Fiona Mandy Anja 3 0.1889 0.16993 0.3851 0.1142 0.09232 0.04958 5 0.1746 0.12305 0.2625 0.2254 0.10188 0.11259 6 0.2659 0.21278 0.1609 0.1945 0.06275 0.10310 7 0.2585 0.05573 0.1531 0.1605 0.16427 0.20792 > > ## CEMS university choice data > data("CEMSChoice", package = "psychotree") > summary(CEMSChoice$preference) > = < NA's London : Paris 186 26 91 0 London : Milano 221 26 56 0 Paris : Milano 121 32 59 91 London : StGallen 208 22 73 0 Paris : StGallen 165 19 119 0 Milano : StGallen 135 28 140 0 London : Barcelona 217 19 67 0 Paris : Barcelona 157 37 109 0 Milano : Barcelona 104 67 132 0 StGallen : Barcelona 144 25 134 0 London : Stockholm 250 19 34 0 Paris : Stockholm 203 30 70 0 Milano : Stockholm 157 46 100 0 StGallen : Stockholm 155 50 98 0 Barcelona : Stockholm 172 41 90 0 > > ## BT tree > cems_tree <- bttree(preference ~ french + spanish + italian + study + work + gender + intdegree, + data = CEMSChoice, minsize = 5, ref = "London") > plot(cems_tree, abbreviate = 1, yscale = c(0, 0.5)) > itempar(cems_tree) London Paris Milano StGallen Barcelona Stockholm 3 0.2083 0.12682 0.15936 0.06905 0.42506 0.01135 4 0.4315 0.08630 0.34017 0.05205 0.06060 0.02939 7 0.3325 0.42215 0.05478 0.06144 0.09252 0.03656 8 0.3989 0.22586 0.08578 0.13480 0.09108 0.06360 9 0.4104 0.09624 0.07697 0.15767 0.16424 0.09451 > > options(digits = o$digits) > > > > cleanEx() detaching ‘package:strucchange’, ‘package:sandwich’, ‘package:zoo’ > nameEx("mpttree") > ### * mpttree > > flush(stderr()); flush(stdout()) > > ### Name: mpttree > ### Title: MPT Trees > ### Aliases: mpttree coef.mpttree plot.mpttree print.mpttree > ### predict.mpttree > ### Keywords: tree > > ### ** Examples > > o <- options(digits = 4) > > ## Source Monitoring data > data("SourceMonitoring", package = "psychotools") > > ## MPT tree > sm_tree <- mpttree(y ~ sources + gender + age, data = SourceMonitoring, + spec = mptspec("SourceMon", .restr = list(d1 = d, d2 = d))) > plot(sm_tree, index = c("D1", "D2", "d", "b", "g")) > > ## extract parameter estimates > coef(sm_tree) D1 d g b D2 3 0.6245 0.4417 0.6285 0.1178 0.7420 4 0.5373 0.2643 0.5144 0.2045 0.7179 5 0.6349 0.4456 0.4696 0.1948 0.6120 > > ## parameter instability tests in root node > if(require("strucchange")) sctest(sm_tree, node = 1) Loading required package: strucchange Loading required package: zoo Attaching package: ‘zoo’ The following objects are masked from ‘package:base’: as.Date, as.Date.numeric Loading required package: sandwich sources gender age statistic 2.848e+01 9.0034 16.9298 p.value 8.805e-05 0.2925 0.2489 > > ## storage and retrieval deficits in psychiatric patients > data("MemoryDeficits", package = "psychotools") > MemoryDeficits$trial <- ordered(MemoryDeficits$trial) > > ## MPT tree > sr_tree <- mpttree(cbind(E1, E2, E3, E4) ~ trial + group, + data = MemoryDeficits, cluster = ID, spec = mptspec("SR2"), alpha = 0.1) > > ## extract parameter estimates > coef(sr_tree) c r u 3 0.4611 0.4730 0.4239 4 0.4508 0.2438 0.3248 7 0.3738 0.2733 0.3090 8 0.4342 0.5557 0.4534 9 0.5978 0.8345 0.5842 > > options(digits = o$digits) > > > > cleanEx() detaching ‘package:strucchange’, ‘package:sandwich’, ‘package:zoo’ > nameEx("npltree") > ### * npltree > > flush(stderr()); flush(stdout()) > > ### Name: npltree > ### Title: Parametric Logisitic (n-PL) IRT Model Trees > ### Aliases: npltree print.npltree plot.npltree itempar.npltree > ### threshpar.npltree guesspar.npltree upperpar.npltree > > ### ** Examples > > o <- options(digits = 4) > > # fit a Rasch (1PL) tree on the SPISA data set > library("psychotree") > data("SPISA", package = "psychotree") > nplt <- npltree(spisa[, 1:9] ~ age + gender + semester + elite + spon, + data = SPISA, type = "Rasch") > nplt PL Tree Model formula: spisa[, 1:9] ~ age + gender + semester + elite + spon Fitted party: [1] root | [2] gender in female | | [3] age <= 21: n = 153 | | `spisa[, 1:9]`2 `spisa[, 1:9]`3 `spisa[, 1:9]`4 `spisa[, 1:9]`5 `spisa[, 1:9]`6 | | -0.5380 -0.6611 -2.2553 -1.1041 -0.3135 | | `spisa[, 1:9]`7 `spisa[, 1:9]`8 `spisa[, 1:9]`9 | | -1.7846 0.4007 0.5844 | | [4] age > 21: n = 264 | | `spisa[, 1:9]`2 `spisa[, 1:9]`3 `spisa[, 1:9]`4 `spisa[, 1:9]`5 `spisa[, 1:9]`6 | | -1.1765 -1.3674 -2.7117 -1.5377 -1.8251 | | `spisa[, 1:9]`7 `spisa[, 1:9]`8 `spisa[, 1:9]`9 | | -2.5733 -0.3057 -0.1337 | [5] gender in male: n = 658 | `spisa[, 1:9]`2 `spisa[, 1:9]`3 `spisa[, 1:9]`4 `spisa[, 1:9]`5 `spisa[, 1:9]`6 | -0.4169 -0.6400 -2.5050 -1.0763 -1.8594 | `spisa[, 1:9]`7 `spisa[, 1:9]`8 `spisa[, 1:9]`9 | -2.5169 -0.5883 -0.4991 Number of inner nodes: 2 Number of terminal nodes: 3 Number of parameters per node: 8 Objective function (negative log-likelihood): 3529 > > # visualize > plot(nplt) > > # compute summaries of the models fitted in nodes 1 and 2 > summary(nplt, 1:2) $`1` Rasch model Difficulty parameters: Estimate Std. Error z value Pr(>|z|) `spisa[, 1:9]`2 -0.6159 0.0997 -6.18 6.6e-10 *** `spisa[, 1:9]`3 -0.8202 0.0994 -8.25 < 2e-16 *** `spisa[, 1:9]`4 -2.5164 0.1099 -22.90 < 2e-16 *** `spisa[, 1:9]`5 -1.1947 0.0996 -12.00 < 2e-16 *** `spisa[, 1:9]`6 -1.5974 0.1010 -15.82 < 2e-16 *** `spisa[, 1:9]`7 -2.3956 0.1082 -22.15 < 2e-16 *** `spisa[, 1:9]`8 -0.3958 0.1005 -3.94 8.2e-05 *** `spisa[, 1:9]`9 -0.2846 0.1010 -2.82 0.0048 ** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Log-likelihood: -3580 (df = 8) Number of iterations in BFGS optimization: 13 $`2` Rasch model Difficulty parameters: Estimate Std. Error z value Pr(>|z|) `spisa[, 1:9]`2 -0.9247 0.1641 -5.63 1.8e-08 *** `spisa[, 1:9]`3 -1.0909 0.1634 -6.67 2.5e-11 *** `spisa[, 1:9]`4 -2.5234 0.1725 -14.63 < 2e-16 *** `spisa[, 1:9]`5 -1.3606 0.1631 -8.34 < 2e-16 *** `spisa[, 1:9]`6 -1.2642 0.1631 -7.75 9.1e-15 *** `spisa[, 1:9]`7 -2.2626 0.1687 -13.42 < 2e-16 *** `spisa[, 1:9]`8 -0.0309 0.1757 -0.18 0.86 `spisa[, 1:9]`9 0.1452 0.1798 0.81 0.42 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Log-likelihood: -1420 (df = 8) Number of iterations in BFGS optimization: 13 > > options(digits = o$digits) > > > > cleanEx() > nameEx("pctree") > ### * pctree > > flush(stderr()); flush(stdout()) > > ### Name: pctree > ### Title: Partial Credit Trees > ### Aliases: pctree plot.pctree print.pctree predict.pctree itempar.pctree > ### threshpar.pctree > ### Keywords: tree > > ### ** Examples > > o <- options(digits = 4) > > ## verbal aggression data from package psychotools > data("VerbalAggression", package = "psychotools") > > ## use response to the second other-to-blame situation (train) > VerbalAggression$s2 <- VerbalAggression$resp[, 7:12] > > ## exclude subjects who only scored in the highest or the lowest categories > VerbalAggression <- subset(VerbalAggression, rowSums(s2) > 0 & rowSums(s2) < 12) > > ## fit partial credit tree model > pct <- pctree(s2 ~ anger + gender, data = VerbalAggression) > > ## print tree (with and without parameters) > print(pct) Partial credit tree Model formula: s2 ~ anger + gender Fitted party: [1] root | [2] gender in female: n = 220 | s2S2WantCurse-C2 s2S2DoCurse-C1 s2S2DoCurse-C2 s2S2WantScold-C1 | 1.486 1.169 3.239 1.097 | s2S2WantScold-C2 s2S2DoScold-C1 s2S2DoScold-C2 s2S2WantShout-C1 | 2.903 2.006 4.791 1.618 | s2S2WantShout-C2 s2S2DoShout-C1 s2S2DoShout-C2 | 3.768 3.198 6.705 | [3] gender in male: n = 67 | s2S2WantCurse-C2 s2S2DoCurse-C1 s2S2DoCurse-C2 s2S2WantScold-C1 | 0.5547 -0.2179 -0.1240 0.8065 | s2S2WantScold-C2 s2S2DoScold-C1 s2S2DoScold-C2 s2S2WantShout-C1 | 1.7020 0.2919 1.7719 1.5697 | s2S2WantShout-C2 s2S2DoShout-C1 s2S2DoShout-C2 | 3.6675 2.1006 5.4388 Number of inner nodes: 1 Number of terminal nodes: 2 Number of parameters per node: 11 Objective function (negative log-likelihood): 899.9 > print(pct, FUN = function(x) " *") Partial credit tree Model formula: s2 ~ anger + gender Fitted party: [1] root | [2] gender in female * | [3] gender in male * Number of inner nodes: 1 Number of terminal nodes: 2 Number of parameters per node: 11 Objective function (negative log-likelihood): 899.9 > > ## show summary for terminal panel nodes > summary(pct) $`2` Partial credit model Item category parameters: Estimate Std. Error z value Pr(>|z|) s2S2WantCurse-C2 1.486 0.303 4.90 9.6e-07 *** s2S2DoCurse-C1 1.169 0.265 4.42 9.9e-06 *** s2S2DoCurse-C2 3.239 0.478 6.78 1.2e-11 *** s2S2WantScold-C1 1.097 0.266 4.12 3.8e-05 *** s2S2WantScold-C2 2.903 0.473 6.13 8.5e-10 *** s2S2DoScold-C1 2.006 0.270 7.44 1.0e-13 *** s2S2DoScold-C2 4.791 0.508 9.44 < 2e-16 *** s2S2WantShout-C1 1.618 0.268 6.04 1.5e-09 *** s2S2WantShout-C2 3.768 0.486 7.75 9.0e-15 *** s2S2DoShout-C1 3.198 0.296 10.80 < 2e-16 *** s2S2DoShout-C2 6.705 0.575 11.66 < 2e-16 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Log-likelihood: -689 (df = 11) Number of iterations in BFGS optimization: 17 $`3` Partial credit model Item category parameters: Estimate Std. Error z value Pr(>|z|) s2S2WantCurse-C2 0.555 0.548 1.01 0.31136 s2S2DoCurse-C1 -0.218 0.507 -0.43 0.66709 s2S2DoCurse-C2 -0.124 0.780 -0.16 0.87361 s2S2WantScold-C1 0.807 0.464 1.74 0.08195 . s2S2WantScold-C2 1.702 0.789 2.16 0.03105 * s2S2DoScold-C1 0.292 0.453 0.64 0.51902 s2S2DoScold-C2 1.772 0.800 2.21 0.02681 * s2S2WantShout-C1 1.570 0.465 3.37 0.00074 *** s2S2WantShout-C2 3.667 0.878 4.18 3.0e-05 *** s2S2DoShout-C1 2.101 0.485 4.33 1.5e-05 *** s2S2DoShout-C2 5.439 1.038 5.24 1.6e-07 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Log-likelihood: -211 (df = 11) Number of iterations in BFGS optimization: 18 > > ## visualization > plot(pct, type = "regions") > plot(pct, type = "profile") > > ## extract item and threshold parameters > coef(pct) s2S2WantCurse-C2 s2S2DoCurse-C1 s2S2DoCurse-C2 s2S2WantScold-C1 2 1.4864 1.1691 3.239 1.0970 3 0.5547 -0.2179 -0.124 0.8065 s2S2WantScold-C2 s2S2DoScold-C1 s2S2DoScold-C2 s2S2WantShout-C1 2 2.903 2.0057 4.791 1.618 3 1.702 0.2919 1.772 1.570 s2S2WantShout-C2 s2S2DoShout-C1 s2S2DoShout-C2 2 3.768 3.198 6.705 3 3.667 2.101 5.439 > itempar(pct) s2S2WantCurse s2S2DoCurse s2S2WantScold s2S2DoScold s2S2WantShout s2S2DoShout 2 -1.1646 -0.288 -0.4561 0.4877 -0.02374 1.445 3 -0.8069 -1.146 -0.2332 -0.1983 0.74950 1.635 > threshpar(pct) s2S2WantCurse-C1 s2S2WantCurse-C2 s2S2DoCurse-C1 s2S2DoCurse-C2 2 -1.908 -0.4213 -0.7386 0.1626 3 -1.084 -0.5296 -1.3022 -0.9903 s2S2WantScold-C1 s2S2WantScold-C2 s2S2DoScold-C1 s2S2DoScold-C2 2 -0.8108 -0.1013 0.09792 0.8775 3 -0.2777 -0.1887 -0.79234 0.3958 s2S2WantShout-C1 s2S2WantShout-C2 s2S2DoShout-C1 s2S2DoShout-C2 2 -0.2893 0.2418 1.290 1.599 3 0.4855 1.0135 1.016 2.254 > > ## inspect parameter stability tests in the splitting node > if(require("strucchange")) sctest(pct, node = 1) Loading required package: strucchange Loading required package: zoo Attaching package: ‘zoo’ The following objects are masked from ‘package:base’: as.Date, as.Date.numeric Loading required package: sandwich anger gender statistic 16.2334 4.354e+01 p.value 0.9578 1.746e-05 > > options(digits = o$digits) > > > > > cleanEx() detaching ‘package:strucchange’, ‘package:sandwich’, ‘package:zoo’ > nameEx("raschtree") > ### * raschtree > > flush(stderr()); flush(stdout()) > > ### Name: raschtree > ### Title: Rasch Trees > ### Aliases: raschtree print.raschtree plot.raschtree predict.raschtree > ### itempar.raschtree > ### Keywords: tree > > ### ** Examples > > o <- options(digits = 4) > > ## artificial data > data("DIFSim", package = "psychotree") > > ## fit Rasch tree model > rt <- raschtree(resp ~ age + gender + motivation, data = DIFSim) > plot(rt) > > ## extract item parameters > itempar(rt) resp1 resp2 resp3 resp4 resp5 resp6 resp7 resp8 resp9 resp10 3 0.41354 1.7416 4.053 0.2700 -0.2995 -1.237 -0.1562 0.12779 -1.831 -0.5928 4 0.05796 0.7298 1.026 0.8747 0.2539 -1.175 -1.0231 -0.07179 -1.419 0.1883 5 0.31447 0.4851 2.699 0.4851 -0.5527 -1.372 -0.7737 -0.06814 -1.504 0.5433 resp11 resp12 resp13 resp14 resp15 resp16 resp17 resp18 resp19 resp20 3 0.1278 -1.831 -1.065 -2.0719 -1.2368 1.9610 1.961 -0.15621 -0.5928 0.4135 4 -0.9493 -1.336 -1.175 0.5897 1.0258 1.3536 2.078 0.05798 -0.9493 -0.1367 5 0.6024 -1.864 -1.245 0.3145 0.9134 0.6623 1.589 -0.06814 -0.7178 -0.4442 > > ## inspect parameter stability tests in all splitting nodes > if(require("strucchange")) { + sctest(rt, node = 1) + sctest(rt, node = 2) + } Loading required package: strucchange Loading required package: zoo Attaching package: ‘zoo’ The following objects are masked from ‘package:base’: as.Date, as.Date.numeric Loading required package: sandwich age gender motivation statistic 6.126e+01 0 86.252 p.value 3.613e-04 NA 0.926 > > ## highlight items 3 and 14 with DIF > ix <- rep(1, 20) > ix[c(3, 14)] <- 2 > plot(rt, ylines = 2.5, cex = c(0.4, 0.8)[ix], + pch = c(19, 19)[ix], col = gray(c(0.5, 0))[ix]) > > options(digits = o$digits) > > > > cleanEx() detaching ‘package:strucchange’, ‘package:sandwich’, ‘package:zoo’ > nameEx("rstree") > ### * rstree > > flush(stderr()); flush(stdout()) > > ### Name: rstree > ### Title: Rating Scale Trees > ### Aliases: rstree plot.rstree print.rstree predict.rstree itempar.rstree > ### threshpar.rstree > ### Keywords: tree > > ### ** Examples > > ## IGNORE_RDIFF_BEGIN > o <- options(digits = 4) > > ## verbal aggression data from package psychotools > data("VerbalAggression", package = "psychotools") > > ## responses to the first other-to-blame situation (bus) > VerbalAggression$s1 <- VerbalAggression$resp[, 1:6] > > ## exclude subjects who only scored in the highest or the lowest categories > VerbalAggression <- subset(VerbalAggression, rowSums(s1) > 0 & rowSums(s1) < 12) > > ## fit rating scale tree model for the first other-to-blame situation > rst <- rstree(s1 ~ anger + gender, data = VerbalAggression) > > ## print tree (with and without parameters) > print(rst) Rating scale tree Model formula: s1 ~ anger + gender Fitted party: [1] root | [2] gender in female | | [3] anger <= 23: n = 173 | | s1S1DoCurse s1S1WantScold s1S1DoScold s1S1WantShout s1S1DoShout | | 0.5054 0.5054 1.0954 1.0688 1.9563 | | C2 | | 0.8887 | | [4] anger > 23: n = 41 | | s1S1DoCurse s1S1WantScold s1S1DoScold s1S1WantShout s1S1DoShout | | -0.6582 0.3610 0.2247 0.5922 0.8799 | | C2 | | -0.7253 | [5] gender in male: n = 68 | s1S1DoCurse s1S1WantScold s1S1DoScold s1S1WantShout s1S1DoShout | -0.48160 0.35253 -0.06342 1.01438 1.60990 | C2 | 0.87640 Number of inner nodes: 2 Number of terminal nodes: 3 Number of parameters per node: 6 Objective function (negative log-likelihood): 975.8 > print(rst, FUN = function(x) " *") Rating scale tree Model formula: s1 ~ anger + gender Fitted party: [1] root | [2] gender in female | | [3] anger <= 23 * | | [4] anger > 23 * | [5] gender in male * Number of inner nodes: 2 Number of terminal nodes: 3 Number of parameters per node: 6 Objective function (negative log-likelihood): 975.8 > > ## show summary for terminal panel nodes > summary(rst) $`3` Rating scale model Item location and threshold parameters: Estimate Std. Error z value Pr(>|z|) s1S1DoCurse 0.505 0.157 3.21 0.0013 ** s1S1WantScold 0.505 0.157 3.21 0.0013 ** s1S1DoScold 1.095 0.166 6.58 4.6e-11 *** s1S1WantShout 1.069 0.166 6.44 1.2e-10 *** s1S1DoShout 1.956 0.194 10.08 < 2e-16 *** C2 0.889 0.157 5.65 1.6e-08 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Log-likelihood: -612 (df = 6) Number of iterations in BFGS optimization: 11 $`4` Rating scale model Item location and threshold parameters: Estimate Std. Error z value Pr(>|z|) s1S1DoCurse -0.658 0.316 -2.08 0.0374 * s1S1WantScold 0.361 0.303 1.19 0.2331 s1S1DoScold 0.225 0.301 0.75 0.4550 s1S1WantShout 0.592 0.308 1.92 0.0545 . s1S1DoShout 0.880 0.318 2.77 0.0056 ** C2 -0.725 0.347 -2.09 0.0367 * --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Log-likelihood: -132 (df = 6) Number of iterations in BFGS optimization: 12 $`5` Rating scale model Item location and threshold parameters: Estimate Std. Error z value Pr(>|z|) s1S1DoCurse -0.4816 0.2566 -1.88 0.06058 . s1S1WantScold 0.3525 0.2548 1.38 0.16650 s1S1DoScold -0.0634 0.2519 -0.25 0.80121 s1S1WantShout 1.0144 0.2731 3.71 0.00020 *** s1S1DoShout 1.6099 0.3034 5.31 1.1e-07 *** C2 0.8764 0.2568 3.41 0.00064 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Log-likelihood: -232 (df = 6) Number of iterations in BFGS optimization: 12 > > ## visualization > plot(rst, type = "regions") > plot(rst, type = "profile") > > ## extract item and threshold parameters > coef(rst) s1S1DoCurse s1S1WantScold s1S1DoScold s1S1WantShout s1S1DoShout C2 3 0.5054 0.5054 1.09541 1.0688 1.9563 0.8887 4 -0.6582 0.3610 0.22465 0.5922 0.8799 -0.7253 5 -0.4816 0.3525 -0.06342 1.0144 1.6099 0.8764 > itempar(rst) s1S1WantCurse s1S1DoCurse s1S1WantScold s1S1DoScold s1S1WantShout s1S1DoShout 3 -0.8552 -0.3498 -0.34978 0.240193 0.2135 1.1010 4 -0.2333 -0.8915 0.12775 -0.008599 0.3589 0.6466 5 -0.4053 -0.8869 -0.05277 -0.468721 0.6091 1.2046 > threshpar(rst) s1S1WantCurse-C1 s1S1WantCurse-C2 s1S1DoCurse-C1 s1S1DoCurse-C2 3 -1.2996 -0.4108 -0.7941 0.09459 4 0.1294 -0.5959 -0.5289 -1.25411 5 -0.8435 0.0329 -1.3251 -0.44870 s1S1WantScold-C1 s1S1WantScold-C2 s1S1DoScold-C1 s1S1DoScold-C2 3 -0.7941 0.09459 -0.2042 0.68456 4 0.4904 -0.23487 0.3540 -0.37123 5 -0.4910 0.38543 -0.9069 -0.03052 s1S1WantShout-C1 s1S1WantShout-C2 s1S1DoShout-C1 s1S1DoShout-C2 3 -0.2308 0.657908 0.6567 1.545 4 0.7216 -0.003693 1.0093 0.284 5 0.1709 1.047277 0.7664 1.643 > > ## inspect parameter stability tests in all splitting nodes > if(require("strucchange")) { + sctest(rst, node = 1) + sctest(rst, node = 2) + } Loading required package: strucchange Loading required package: zoo Attaching package: ‘zoo’ The following objects are masked from ‘package:base’: as.Date, as.Date.numeric Loading required package: sandwich anger gender statistic 23.61167 0 p.value 0.01672 NA > > options(digits = o$digits) > ## IGNORE_RDIFF_END > > > > ### *