psychotree/0000755000175000017500000000000014235166362012601 5ustar nileshnileshpsychotree/MD50000644000175000017500000000600114235166362013106 0ustar nileshnileshf2a305ce19876a2fb86cb551fcbe9ed8 *DESCRIPTION d5006bf0cb816ce0e13e5c0ff9adc414 *NAMESPACE 2fdbba57bde164865bf0a58b16bc8a88 *NEWS 61739f5fb1b588ce34a549073b7b476e *R/bttree.R 625a3910ab510fec3866075bdbbbb677 *R/gluecodes.R 3ab5d1c82a88ff3e4ff309b8539dc802 *R/gpcmtree.R 0ce2ff52b39255a898a0513d79bbae74 *R/graphics.R 8e5a503e739f85796d0a09445bd963c4 *R/mpttree.R 4cfc79934b43dd9164aac7dd6f7fa835 *R/npltree.R 84edc0e5b494e261172250da83ab06f8 *R/pctree.R c8db68bbadcf02d205f7ab1547897be2 *R/raschtree.R d0da2a24759eeebe89f32b47cf763ba4 *R/rstree.R 1961639f6f4f7f9efffa91b624b3d060 *build/partial.rdb ab3557f5b80ddded142249b7728a66c9 *build/vignette.rds bfa8d059feb59843f681a5a73acb2fd5 *data/CEMSChoice.rda 1e662984b736edc40b53f3ca5dc3ed65 *data/DIFSim.rda 36664d97f9c5cfa484a1ec3e295a4eb7 *data/DIFSimPC.rda 815ac93b628a3f678ce5435b79fa7328 *data/EuropeanValuesStudy.rda 90d5682a15ff732dc8adcda9014f5b10 *data/SPISA.rda a48859bf37cbb9d5d1002139443f034e *data/Topmodel2007.rda 43871343ae7409f53a3afff3848b52aa *inst/CITATION c7dad7f27e2058312450b1e8aa936eef *inst/doc/raschtree.R 08180953c3198cbdc215788cc42ec70d *inst/doc/raschtree.Rnw 25b217cd9de7eb193118d9c156fa64dd *inst/doc/raschtree.pdf c253f6806bd6b997b3b6b2c17bfcf427 *inst/tinytest/fit_GPCM_dataset.rds 47d5f3f382a870978703b865d717799e *inst/tinytest/test_1PL.rds 3154b2e8604ba971cc2cc22a532462da *inst/tinytest/test_1PL_mg.rds b1eb782cd3ee895b6c49b1aacd250398 *inst/tinytest/test_1pl.R b6556872372a6ca25dab85643f5acfa2 *inst/tinytest/test_2PL.rds 18ec78153276b9b4219e511a993e0419 *inst/tinytest/test_2PL_mg.rds 0af0f162cad4bb9076ba5687bc76f912 *inst/tinytest/test_2pl.R cb20b72cc2de1fcbd58d7be4b1e94ad0 *inst/tinytest/test_GPCM.rds 855cd0b7d8c6fdbb3c02022ce43469a9 *inst/tinytest/test_GPCM_mg.rds c7a19e4e2b2afcfdf2f17d8691f910d0 *inst/tinytest/test_gpcm.R 2ece9379eec04173b5f78e03716db861 *inst/tinytest/test_rasch.R a0f287492efbb82d4f22dce11ff95828 *inst/tinytest/test_rasch.rds f003422ecb94f65242216c8ca74d080e *man/CEMSChoice.Rd ceea88b7b70e973a6abbfd2fb92d2e5e *man/DIFSim.Rd eb1a0ad5af59e52c89db61cdf66b8ef7 *man/EuropeanValuesStudy.Rd fecbacbf6e0edfe42042a3c5897c7872 *man/SPISA.Rd 78e7cab80e735737543b6d382efee244 *man/Topmodel2007.Rd f13ace06e847c9348fa2dae4af544137 *man/bttree.Rd 79c374064e18b6fac73f74e1352986af *man/gpcmtree.Rd 509c7188fa7e126bc22d90335ae096e2 *man/mpttree.Rd 34196b1543483e089a2d8d35b3204327 *man/node_btplot.Rd cb2f61339167f4a524413b7bafd188f9 *man/node_mptplot.Rd fd53068c2e7905352fe40075bd6723ec *man/node_profileplot.Rd e7fe70ad4474e39b1ea54fe0d5442bf9 *man/node_regionplot.Rd c68d2e7c52d6c389fa46a16607d6aa3f *man/npltree.Rd ee55b61596d3138a8d8e7c9dc2bd9981 *man/pctree.Rd 7f5448d2c373052fe47611c686d8bf4e *man/raschtree.Rd e6e3416002954746425ad1beb571e2d7 *man/rstree.Rd 71c9a7cc54f5756e6e6be2f3d6670e38 *tests/Examples/psychotree-Ex.Rout.save 49d6b692f7839c821b9cdfa2ecd62fb5 *tests/tinytests.R ad708a43d06e6a9af8d9f15f825fe158 *vignettes/psychotree.bib 08180953c3198cbdc215788cc42ec70d *vignettes/raschtree.Rnw 218c66efe70a363e76a4b5612cfe4f4b *vignettes/raschtree.Rout.save psychotree/DESCRIPTION0000644000175000017500000000373614235166362014320 0ustar nileshnileshPackage: psychotree Title: Recursive Partitioning Based on Psychometric Models Version: 0.16-0 Date: 2022-05-03 Authors@R: c(person(given = "Achim", family = "Zeileis", role = c("aut", "cre"), email = "Achim.Zeileis@R-project.org", comment = c(ORCID = "0000-0003-0918-3766")), person(given = "Carolin", family = "Strobl", role = "aut", email = "Carolin.Strobl@psychologie.uzh.ch"), person(given = "Florian", family = "Wickelmaier", role = "aut"), person(given = "Basil", family = "Komboz", role = "aut"), person(given = "Julia", family = "Kopf", role = "aut"), person(given = "Lennart", family = "Schneider", role = "aut", email = "Lennart.Sch@web.de", comment = c(ORCID = "0000-0003-4152-5308")), person(given = "David", family = "Dreifuss", role = "aut"), person(given = "Rudolf", family = "Debelak", role = "aut", email = "rudolf.debelak@gmail.com", comment = c(ORCID = "0000-0001-8900-2106"))) Depends: R (>= 4.0.0), partykit (>= 1.2-9), psychotools (>= 0.7-1) Suggests: stablelearner (>= 0.1-3), strucchange, tinytest, mirt Imports: graphics, grDevices, grid, stats, Formula Description: Recursive partitioning based on psychometric models, employing the general MOB algorithm (from package partykit) to obtain Bradley-Terry trees, Rasch trees, rating scale and partial credit trees, and MPT trees, trees for 1PL, 2PL, 3PL and 4PL models and generalized partial credit models. License: GPL-2 | GPL-3 NeedsCompilation: no Packaged: 2022-05-03 12:28:06 UTC; zeileis Author: Achim Zeileis [aut, cre] (), Carolin Strobl [aut], Florian Wickelmaier [aut], Basil Komboz [aut], Julia Kopf [aut], Lennart Schneider [aut] (), David Dreifuss [aut], Rudolf Debelak [aut] () Maintainer: Achim Zeileis Repository: CRAN Date/Publication: 2022-05-06 09:40:02 UTC psychotree/man/0000755000175000017500000000000014232635073013351 5ustar nileshnileshpsychotree/man/node_btplot.Rd0000644000175000017500000000355614214500744016156 0ustar nileshnilesh\name{node_btplot} \alias{node_btplot} \title{Panel-Generating Function for Visualizing Bradley-Terry Tree Models} \description{ Panel-generating function for visualizing the worth parameters from the nodes in Bradley-Terry tree models. } \usage{ node_btplot(mobobj, id = TRUE, worth = TRUE, names = TRUE, abbreviate = TRUE, index = TRUE, ref = TRUE, col = "black", refcol = "lightgray", bg = "white", cex = 0.5, pch = 19, xscale = NULL, yscale = NULL, ylines = 1.5) } \arguments{ \item{mobobj}{an object of class \code{"mob"} based on Bradley-Terry models fitted by \code{\link[psychotools]{btmodel}}.} \item{id}{logical. Should the node ID be displayed?} \item{worth}{logical. Should worth parameters (or their logs) be visualized?} \item{names}{logical. Should the names for the objects be displayed?} \item{abbreviate}{logical or numeric. Should object names be abbreviated? If numeric this controls the length of the abbreviation.} \item{index}{logical. Should different indexes for different stimuli be used?} \item{ref}{logical. Should a horizontal line for the reference level be drawn? Alternatively, \code{ref} can also be numeric or character to employ a reference level different from that stored in the model object.} \item{col, cex, pch}{graphical appearance of plotting symbols.} \item{refcol}{line color for reference line (if \code{ref}).} \item{bg}{color for background filling.} \item{xscale, yscale}{x and y axis limits.} \item{ylines}{numeric. Number of lines used for y-axis labels.} } \details{ The panel-generating function \code{node_btplot} is called by the \code{plot} method for \code{"bttree"} objects and does not have to be called by the user directly. } \value{ A panel function which can be supplied to the \code{plot} method for \code{"mob"} objects. } \seealso{\code{\link{bttree}}} \keyword{hplot} psychotree/man/EuropeanValuesStudy.Rd0000644000175000017500000000623714214500744017633 0ustar nileshnilesh\name{EuropeanValuesStudy} \alias{EuropeanValuesStudy} \title{European Values Study} \description{ A sample of the 1999 European Values Study (EVS) containing an assessment of materialism/postmaterialism in 3584 respondents from 32 countries. } \usage{data("EuropeanValuesStudy")} \format{ A data frame containing 3584 observations on 10 variables. \describe{ \item{country}{Factor coding the country of a respondent.} \item{gender}{Factor coding gender.} \item{birthyear}{Numeric. Year of birth.} \item{eduage}{Numeric. Age when full time education was or will be completed.} \item{marital}{Factor. Current legal marital status.} \item{employment}{Ordered factor. Employment and number of working hours.} \item{occupation}{Factor. What is/was your main job?} \item{income}{Ordered factor. Income of household in ten categories from 10 percent lowest to 10 percent highest income category.} \item{paircomp}{Paired comparison of class \code{\link{paircomp}}. Five pairwise choices among four important political goals derived from a double-choice task (see Details).} \item{country2}{Factor. Country group according to postmaterialism (see Details).} } } \details{ The data are part of a larger survey conducted in 1999 in 32 countries in Europe (see \url{https://europeanvaluesstudy.eu/}). Vermunt (2003) obtained a sample from 10 percent of the available cases per country, yielding 3584 valid cases. The item in the 1999 European Values Study questionnaire aiming at recording materialism/postmaterialism reads as follows: There is a lot of talk these days about what the aims of this country should be for the next ten years. On this card are listed some of the goals which different people would give top priority. If you had to choose, which of the things on this card would you say is most important? And which would be the next most important? A Maintaining order in the nation\cr B Giving people more say in important government decisions\cr C Fighting rising prices\cr D Protecting freedom of speech The double-choice task implies a partial ranking of the alternatives and (assuming transitivity) an incomplete set of paired comparisons for each respondent. The country group according to postmaterialism was derived by Vermunt (2003) using a latent class model, and applied by Lee and Lee (2010) in a tree model. } \source{ Latent GOLD Sample Data Sets Website. } \references{ Lee PH, Yu PLH (2010). Distance-Based Tree Models for Ranking Data. \emph{Computational Statistics and Data Analysis}, \bold{54}, 1672--1682. Vermunt JK (2003). Multilevel Latent Class Models. \emph{Sociological Methodology}, \bold{33}, 213--239. } \seealso{\code{\link{paircomp}}} \examples{ ## data data("EuropeanValuesStudy", package = "psychotree") summary(EuropeanValuesStudy$paircomp) \dontrun{ ## Bradley-Terry tree resulting in similar results compared to ## the (different) tree approach of Lee and Lee (2010) evs <- na.omit(EuropeanValuesStudy) bt <- bttree(paircomp ~ gender + eduage + birthyear + marital + employment + income + country2, data = evs, alpha = 0.01) plot(bt, abbreviate = 2) } } \keyword{datasets} psychotree/man/Topmodel2007.Rd0000644000175000017500000000514314214500744015733 0ustar nileshnilesh\name{Topmodel2007} \alias{Topmodel2007} \encoding{latin1} \title{Attractiveness of Germany's Next Topmodels 2007} \description{ Preferences of 192 respondents judging the attractiveness of the top six contestants of the TV show \emph{Germany's Next Topmodel 2007} (second cycle). } \usage{data("Topmodel2007")} \format{ A data frame containing 192 observations on 6 variables. \describe{ \item{preference}{Paired comparison of class \code{\link{paircomp}}. Preferences for all 15 paired comparisons from 6 contestants: Barbara, Anni, Hana, Fiona, Mandy, and Anja.} \item{gender}{Factor coding gender.} \item{age}{Integer. Age of the respondents in years.} \item{q1}{Factor. Do you recognize the women on the pictures?/Do you know the TV show Germany's Next Topmodel?} \item{q2}{Factor. Did you watch Germany's Next Topmodel regularly?} \item{q3}{Factor. Did you watch the final show of Germany's Next Topmodel?/Do you know who won Germany's Next Topmodel?} } } \details{ Germany's Next Topmodel is a German casting television show (based on a concept introduced in the United States) hosted by Heidi Klum (see Wikipedia 2009). The second season of the show aired March--May 2007. A survey was conducted at the Department of Psychology, Universitt Tbingen, in 2007 shortly after the final show. The sample was stratified by gender and age (younger versus older than 30 years) with 48 participants in each group. Digital photographs (resolution 303 times 404 pixels) of the top six contestants were available from the ProSieben web page at the time of the survey. The photos were selected to be comparable, showing the contestant's face and the upper part of the body, all women being casually dressed. Participants were presented with all 15 pairs of photographs. On each trial, their task was to judge which of the two women on the photos was the more attractive. In order to assess the participants' expertise, additional questions regarding their familiarity with the show were asked after the pairwise comparisons were completed. The actual ranking, as resulting from sequential elimination during the course of the show, was (from first to sixth place): Barbara, Anni, Hana, Fiona, Mandy, Anja. } \references{ Wikipedia (2009). Germany's Next Topmodel -- Wikipedia, The Free Encyclopedia. \url{https://en.wikipedia.org/wiki/Germany's_Next_Topmodel}, accessed 2009-02-06. } \seealso{\code{\link{paircomp}}} \examples{ data("Topmodel2007", package = "psychotree") summary(Topmodel2007$preference) xtabs(~ gender + I(age < 30), data = Topmodel2007) } \keyword{datasets} psychotree/man/raschtree.Rd0000644000175000017500000001123514214500744015616 0ustar nileshnilesh\name{raschtree} \alias{raschtree} \alias{print.raschtree} \alias{plot.raschtree} \alias{predict.raschtree} \alias{itempar.raschtree} \title{Rasch Trees} \description{ Recursive partitioning (also known as trees) based on Rasch models. } \usage{ raschtree(formula, data, na.action, reltol = 1e-10, deriv = c("sum", "diff", "numeric"), maxit = 100L, \dots) \method{predict}{raschtree}(object, newdata = NULL, type = c("probability", "cumprobability", "mode", "median", "mean", "category-information", "item-information", "test-information", "node"), personpar = 0, \dots) \method{plot}{raschtree}(x, type = c("profile", "regions"), terminal_panel = NULL, tp_args = list(...), tnex = 2L, drop_terminal = TRUE, ...) } \arguments{ \item{formula}{A symbolic description of the model to be fit. This should be of type \code{y ~ x1 + x2} where \code{y} should be a binary 0/1 item response matrix and \code{x1} and \code{x2} are used as partitioning variables.} \item{data}{a data frame containing the variables in the model.} \item{na.action}{a function which indicates what should happen when the data contain missing values (\code{NA}s).} \item{deriv}{character. Which type of derivatives should be used for computing gradient and Hessian matrix? Analytical with sum algorithm (\code{"sum"}), analytical with difference algorithm (\code{"diff"}, faster but numerically unstable), or numerical. Passed to \code{\link[psychotools]{raschmodel}}.} \item{reltol, maxit}{arguments passed via \code{\link[psychotools]{raschmodel}} to \code{\link[stats]{optim}}.} \item{\dots}{arguments passed to the underlying functions, i.e., to \code{\link[partykit]{mob_control}} for \code{raschtree}, and to the underlying \code{predict} and \code{plot} methods, respectively.} \item{object, x}{an object of class \code{"raschtree"}.} \item{newdata}{optional data frame with partitioning variables for which predictions should be computed. By default the learning data set is used.} \item{type}{character specifying the type of predictions or plot. For the \code{predict} method, either just the ID of the terminal \code{"node"} can be predicted or some property of the model at a given person parameter (specified by \code{personpar}).} \item{personpar}{numeric person parameter (of length 1) at which the predictions are evaluated.} \item{terminal_panel, tp_args, tnex, drop_terminal}{arguments passed to \code{\link[partykit]{plot.modelparty}}/\code{\link[partykit]{plot.party}}.} } \details{ Rasch trees are an application of model-based recursive partitioning (implemented in \code{\link[partykit]{mob}}) to Rasch models (implemented in \code{\link[psychotools]{raschmodel}}). Various methods are provided for \code{"raschtree"} objects, most of them inherit their behavior from \code{"modelparty"} objects (e.g., \code{print}, \code{summary}, etc.). For the Rasch models in the nodes of a tree, \code{coef} extracts all item parameters except the first one which is always restricted to be zero. \code{itempar} extracts all item parameters (including the first one) and by default restricts their sum to be zero (but other restrictions can be used as well). The \code{plot} method by default employs the \code{\link{node_profileplot}} panel-generating function and the \code{\link{node_regionplot}} panel-generating function is provided as an alternative. Rasch tree models are introduced in Strobl et al. (2015), whose analysis for the \code{\link{SPISA}} data is replicated in \code{vignette("raschtree", package = "psychotree")}. Their illustration employing artificial data is replicated below. } \references{ Strobl C, Kopf J, Zeileis A (2015). Rasch Trees: A New Method for Detecting Differential Item Functioning in the Rasch Model. \emph{Psychometrika}, \bold{80}(2), 289--316. \doi{10.1007/s11336-013-9388-3} } \value{ An object of S3 class \code{"raschtree"} inheriting from class \code{"modelparty"}. } \seealso{\code{\link[partykit]{mob}}, \code{\link[psychotools]{raschmodel}}, \code{\link{rstree}}, \code{\link{pctree}}} \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) ## inspect parameter stability tests in all splitting nodes if(require("strucchange")) { sctest(rt, node = 1) sctest(rt, node = 2) } ## 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) } \keyword{tree} psychotree/man/bttree.Rd0000644000175000017500000000774014214500744015131 0ustar nileshnilesh\name{bttree} \alias{bttree} \alias{plot.bttree} \alias{print.bttree} \alias{predict.bttree} \alias{itempar.bttree} \title{Bradley-Terry Trees} \description{ Recursive partitioning (also known as trees) based on Bradley-Terry models. } \usage{ bttree(formula, data, na.action, cluster, type = "loglin", ref = NULL, undecided = NULL, position = NULL, \dots) \method{predict}{bttree}(object, newdata = NULL, type = c("worth", "rank", "best", "node"), \dots) } \arguments{ \item{formula}{A symbolic description of the model to be fit. This should be of type \code{y ~ x1 + x2} where \code{y} should be an object of class \code{\link[psychotools]{paircomp}} and \code{x1} and \code{x2} are used as partitioning variables.} \item{data}{an optional data frame containing the variables in the model.} \item{na.action}{A function which indicates what should happen when the data contain \code{NA}s, defaulting to \code{\link[stats]{na.pass}}.} \item{cluster}{optional vector (typically numeric or factor) with a cluster ID to be employed for clustered covariances in the parameter stability tests.} \item{type}{character indicating the type of auxiliary model in \code{bttree} and the type of predictions in the \code{predict} method, respectively. For the auxiliary model see \code{\link[psychotools]{btmodel}}. For the \code{predict} method, four options are available: the fitted \code{"worth"} parameter for each alternative, the corresponding \code{"rank"}, the \code{"best"} alternative or the predicted \code{"node"} number.} \item{ref, undecided, position}{arguments for the Bradley-Terry model passed on to \code{\link[psychotools]{btmodel}}.} \item{\dots}{arguments passed to \code{\link[partykit]{mob_control}}.} \item{object}{fitted model object of class \code{"bttree"}.} \item{newdata}{optionally, a data frame in which to look for variables with which to predict. If omitted, the original observations are used.} } \details{ Bradley-Terry trees are an application of model-based recursive partitioning (implemented in \code{\link[partykit]{mob}}) to Bradley-Terry models for paired comparison data (implemented in \code{\link[psychotools]{btmodel}}). Details about the underlying theory and further explanations of the illustrations in the example section can be found in Strobl, Wickelmaier, Zeileis (2011). Various methods are provided for \code{"bttree"} objects, most of them inherit their behavior from \code{"mob"} objects (e.g., \code{print}, \code{summary}, etc.). \code{itempar} behaves analogously to \code{coef} and extracts the worth/item parameters from the BT models in the nodes of the tree. The \code{plot} method employs the \code{\link{node_btplot}} panel-generating function. } \value{ An object of S3 class \code{"bttree"} inheriting from class \code{"modelparty"}. } \references{ Strobl C, Wickelmaier F, Zeileis A (2011). Accounting for Individual Differences in Bradley-Terry Models by Means of Recursive Partitioning. \emph{Journal of Educational and Behavioral Statistics}, \bold{36}(2), 135--153. \doi{10.3102/1076998609359791} } \seealso{\code{\link[partykit]{mob}}, \code{\link[psychotools]{btmodel}}} \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) ## worth/item parameters in terminal nodes itempar(tm_tree) ## CEMS university choice data data("CEMSChoice", package = "psychotree") summary(CEMSChoice$preference) ## 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) options(digits = o$digits) } \keyword{tree} psychotree/man/node_profileplot.Rd0000644000175000017500000000471714232636642017220 0ustar nileshnilesh\name{node_profileplot} \alias{node_profileplot} \title{Panel-Generating Function for Visualizing IRT Tree Models} \description{ Panel-generating function for visualizing profiles (points and lines) of the parameters from the nodes in IRT tree models. } \usage{ node_profileplot( mobobj, what = c("items", "thresholds", "discriminations"), parg = list(type = NULL, ref = NULL, alias = TRUE), id = TRUE, names = FALSE, abbreviate = TRUE, index = TRUE, ref = TRUE, col = "black", border = col, linecol = "black", refcol = "lightgray", bg = "white", cex = 0.5, pch = 21, xscale = NULL, yscale = NULL, ylines = 2, \dots ) } \arguments{ \item{mobobj}{an object of class \code{"npltree"} or class \code{"mob"} fitted by \code{\link[psychotree]{npltree}}} \item{what}{specifying the type of parameters to be plotted} \item{parg}{supplementary arguments for \code{"what"}} \item{id}{logical. Should the node ID be displayed?} \item{names}{logical or character. If \code{TRUE}, the names of the items are displayed on the x-axis. If \code{FALSE}, numbers of items are shown. Alternatively a character vector of the same length as the number of items can be supplied.} \item{abbreviate}{logical. Should item names be abbreviated? If numeric this controls the length of the abbreviation.} \item{index}{logical. Should different indexes for different items be used?} \item{ref}{logical. Should a horizontal line for the reference level be drawn?} \item{col, border, pch, cex}{graphical appearance of plotting symbols.} \item{linecol, refcol}{character, specifying the line color to use for the profile lines and reference line, respectively.} \item{bg}{color for background filling.} \item{xscale, yscale}{x and y axis limits.} \item{ylines}{numeric. Number of lines used for y-axis labels.} \item{...}{further arguments currently not used.} } \details{ The panel-generating function \code{node_regionplot} is called by the \code{plot} method of \code{"gpcmtree"} object by default and does not have to be called by the user directly. See \code{\link[psychotools]{regionplot}} for details and references of the drawn region plots and possible values and their meaning for the argument \code{type} (taken by \code{node_regionplot}). } \value{ A panel function which can be supplied to the \code{plot} method for \code{"npltree"} objects or \code{"mob"} objects fitted by \code{\link[psychotree]{npltree}} or \code{\link[psychotree]{gpcmtree}}. } \keyword{hplot} psychotree/man/SPISA.Rd0000644000175000017500000001553714214500744014526 0ustar nileshnilesh\name{SPISA} \alias{SPISA} \encoding{latin1} \title{SPIEGEL Studentenpisa Data (Subsample)} \description{ A subsample from the general knowledge quiz \dQuote{Studentenpisa} conducted online by the German weekly news magazine SPIEGEL. The data contain the quiz results from 45 questions as well as sociodemographic data for 1075 university students from Bavaria. } \usage{data("SPISA")} \format{ A data frame containing 1075 observations on 6 variables. \describe{ \item{spisa}{matrix with \code{0}/\code{1} results from 45 questions in the quiz (indicating wrong/correct answers).} \item{gender}{factor indicating gender.} \item{age}{age in years.} \item{semester}{numeric indicating semester of university enrollment.} \item{elite}{factor indicating whether the university the student is enrolled in has been granted \dQuote{elite} status by the German \dQuote{excellence initiative}.} \item{spon}{ordered factor indicating frequency of accessing the SPIEGEL online (SPON) magazine.} } } \details{ An online quiz for testing one's general knowledge was conducted by the German weekly news magazine SPIEGEL in 2009. Overall, about 700,000 participants answered the quiz and a set of sociodemographic questions. The general knowledge quiz consisted of a total of 45 items from five different topics: politics, history, economy, culture and natural sciences. For each topic, four different sets of nine items were available, that were randomly assigned to the participants. A thorough analysis and discussion of the original data set is provided in Trepte and Verbeet (2010). Here, we provide the subsample of university students enrolled in the federal state of Bavaria, who had been assigned questionnaire number 20 (so that all subjects have answered the same set of items). Excluding all incomplete records, this subsample contains 1075 observations. The data are analyzed in Strobl et al. (2010), whose analysis is replicated in \code{vignette("raschtree", package = "psychotree")}. The full list of items in questionnaire 20 is given below. Politics:\cr Who determines the rules of action in German politics according to the constitution? -- The Bundeskanzler (federal chancellor).\cr What is the function of the second vote in the elections to the German Bundestag (federal parliament)? -- It determines the allocation of seats in the Bundestag.\cr How many people were killed by the RAF (Red Army Faction)? -- 33.\cr Where is Hessen (i.e., the German federal country Hesse) located? -- (Indicate location on a map.)\cr What is the capital of Rheinland-Pfalz (i.e., the German federal country Rhineland-Palatinate)? -- Mainz.\cr Who is this? -- (Picture of Horst Seehofer.)\cr Which EU institution is elected in 2009 by the citizens of EU member countries? -- European Parliament.\cr How many votes does China have in the UNO general assembly? -- 1.\cr Where is Somalia located? -- (Indicate location on a map.) History:\cr The Roman naval supremacy was established through... -- ... the abolition of Carthage.\cr In which century did the Thirty Years' War take place? -- The 17th century.\cr Which form of government is associated with the French King Louis XIV? -- Absolutism.\cr What island did Napoleon die on in exile? -- St. Helena.\cr How many percent of the votes did the NSDAP receive in the 1928 elections of the German Reichstag? -- About 3 percent.\cr How many Jews were killed by the Nazis during the Holocaust? -- About 6 Million.\cr Who is this? -- (Picture of Johannes Rau, former German federal president.)\cr Which of the following countries is not a member of the EU? -- Croatia.\cr How did Mao Zedong expand his power in China? -- The Long March. Economy:\cr Who is this? -- (Picture of Dieter Zetsche, CEO of Mercedes-Benz.)\cr What is the current full Hartz IV standard rate (part of the social welfare) for adults? -- 351 Euro.\cr What was the average per capita gross national product in Germany in 2007? -- About 29,400 Euro.\\ What is a CEO? -- A Chief Executive Officer.\cr What is the meaning of the hexagonal ``organic'' logo? -- Synthetic pesticides are prohibited.\cr Which company does this logo represent? -- Deutsche Bank.\cr Which German company took over the British automobile manufacturers Rolls-Royce? -- BMW.\cr Which internet company took over the media group Time Warner? -- AOL.\cr What is the historic meaning of manufacturies? -- Manufacturies were the precursors of industrial mass production.\cr Culture:\cr Which painter created this painting? -- Andy Warhol.\cr What do these four buildings have in common? -- All four were designed by the same architects.\cr Roman numbers: What is the meaning of CLVI? -- 156.\cr What was the German movie with the most viewers since 1990? -- Der Schuh des Manitu.\cr In which TV series was the US president portrayed by an African American actor for a long time? -- 24.\cr What is the name of the bestselling novel by Daniel Kehlmann? -- Die Vermessung der Welt (Measuring The World).\cr Which city is the setting for the novel \sQuote{Buddenbrooks}? -- Lbeck.\cr In which city is this building located? -- Paris.\cr Which one of the following operas is not by Mozart? -- Aida. Natural sciences:\cr Why does an ice floe not sink in the water? -- Due to the lower density of ice.\cr What is ultrasound not used for? -- Radio.\cr Which sensory cells in the human eye make color vision possible? -- Cones.\cr What is also termed Trisomy 21? -- Down syndrome.\cr Which element is the most common in the Earth's atmosphere? -- Nitrogen.\cr Which kind of tree does this leaf belong to? -- Maple.\cr Which kind of bird is this? -- Blackbird.\cr Where is the stomach located? -- (Indicate location on a map of the body.)\cr What is the sum of interior angles in a triangle? -- 180 degrees. } \references{ Strobl C, Kopf J, Zeileis A (2015). Rasch Trees: A New Method for Detecting Differential Item Functioning in the Rasch Model. \emph{Psychometrika}, \bold{80}(2), 289--316. \doi{10.1007/s11336-013-9388-3} SPIEGEL Online (2009). Studentenpisa -- Alle Fragen, alle Antworten. In German. Accessed 2010-10-26. \url{https://www.spiegel.de/lebenundlernen/uni/studentenpisa-alle-fragen-alle-antworten-a-620101.html} Trepte S, Verbeet M (2010). Allgemeinbildung in Deutschland -- Erkenntnisse aus dem SPIEGEL-Studentenpisa-Test. ISBN 978-3-531-17218-7. VS Verlag, Wiesbaden. } \seealso{\code{\link{raschtree}}} \examples{ ## data data("SPISA", package = "psychotree") ## summary of covariates summary(SPISA[,-1]) ## histogram of raw scores hist(rowSums(SPISA$spisa), breaks = 0:45 + 0.5) \dontrun{ ## See the following vignette for a tree-based DIF analysis vignette("raschtree", package = "psychotree") } } \keyword{datasets} psychotree/man/node_mptplot.Rd0000644000175000017500000000341414214500744016342 0ustar nileshnilesh\name{node_mptplot} \alias{node_mptplot} \title{Panel-Generating Function for Visualizing MPT Tree Models} \description{ Panel-generating function for visualizing the model parameters from the nodes in MPT tree models. } \usage{ node_mptplot(mobobj, id = TRUE, names = TRUE, abbreviate = TRUE, index = TRUE, ref = TRUE, col = "black", linecol = "lightgray", bg = "white", cex = 0.5, pch = 19, xscale = NULL, yscale = c(0, 1), ylines = 1.5) } \arguments{ \item{mobobj}{an object of class \code{"mob"} based on MPT models fitted by \code{\link[psychotools]{mptmodel}}.} \item{id}{logical. Should the node ID be displayed?} \item{names}{logical or character. Should the names for the parameters be displayed? If character, this sets the names.} \item{abbreviate}{logical or numeric. Should parameter names be abbreviated? If numeric this controls the length of the abbreviation.} \item{index}{logical or character. Should different indexes for different parameters be used? If character, this controls the order of labels given in \code{names}.} \item{ref}{logical. Should a horizontal line for the reference level be drawn?} \item{col, cex, pch}{graphical appearance of plotting symbols.} \item{linecol}{line color for reference line (if \code{ref}).} \item{bg}{color for background filling.} \item{xscale, yscale}{x and y axis limits.} \item{ylines}{numeric. Number of lines used for y-axis labels.} } \details{ The panel-generating function \code{node_mptplot} is called by the \code{plot} method for \code{"mpttree"} objects and does not have to be called by the user directly. } \value{ A panel function which can be supplied to the \code{plot} method for \code{"mob"} objects. } \seealso{\code{\link{mpttree}}} \keyword{hplot} psychotree/man/rstree.Rd0000644000175000017500000001243214214500744015142 0ustar nileshnilesh\name{rstree} \alias{rstree} \alias{plot.rstree} \alias{print.rstree} \alias{predict.rstree} \alias{itempar.rstree} \alias{threshpar.rstree} \title{Rating Scale Trees} \description{ Recursive partitioning (also known as trees) based on rating scale models. } \usage{ rstree(formula, data, na.action, reltol = 1e-10, deriv = c("sum", "diff"), maxit = 100L, \dots) \method{predict}{rstree}(object, newdata = NULL, type = c("probability", "cumprobability", "mode", "median", "mean", "category-information", "item-information", "test-information", "node"), personpar = 0, \dots) \method{plot}{rstree}(x, type = c("regions", "profile"), terminal_panel = NULL, tp_args = list(...), tnex = 2L, drop_terminal = TRUE, ...) } \arguments{ \item{formula}{A symbolic description of the model to be fit. This should be of type \code{y ~ x1 + x2} where \code{y} should be a matrix with items in the columns and observations in the rows and \code{x1} and \code{x2} are used as partitioning variables. Additionally each item (column) should have the same maximum value (see \code{\link{pctree}} for a way to handle variable maximum values).} \item{data}{a data frame containing the variables in the model.} \item{na.action}{a function which indicates what should happen when the data contain missing values (\code{NA}s).} \item{deriv}{character. If "sum" (the default), the first derivatives of the elementary symmetric functions are calculated with the sum algorithm. Otherwise ("diff") the difference algorithm (faster but numerically unstable) is used.} \item{reltol, maxit}{arguments passed via \code{\link[psychotools]{rsmodel}} to \code{\link[stats]{optim}}.} \item{\dots}{arguments passed to the underlying functions, i.e., to \code{\link[partykit]{mob_control}} for \code{rstree}, and to the underlying \code{predict} and \code{plot} methods, respectively.} \item{object, x}{an object of class \code{"raschtree"}.} \item{newdata}{optional data frame with partitioning variables for which predictions should be computed. By default the learning data set is used.} \item{type}{character specifying the type of predictions or plot. For the \code{predict} method, either just the ID of the terminal \code{"node"} can be predicted or some property of the model at a given person parameter (specified by \code{personpar}).} \item{personpar}{numeric person parameter (of length 1) at which the predictions are evaluated.} \item{terminal_panel, tp_args, tnex, drop_terminal}{arguments passed to \code{\link[partykit]{plot.modelparty}}/\code{\link[partykit]{plot.party}}.} } \details{ Rating scale trees are an application of model-based recursive partitioning (implemented in \code{\link[partykit]{mob}}) to rating scale models (implemented in \code{\link[psychotools]{rsmodel}}). Various methods are provided for \code{"rstree"} objects, most of them inherit their behavior from \code{"mob"} objects (e.g., \code{print}, \code{summary}, etc.). For the rating scale models in the nodes of a tree, \code{coef} extracts all item parameters. The \code{plot} method employs the \code{\link{node_regionplot}} panel-generating function by default. Various methods are provided for \code{"rstree"} objects, most of them inherit their behavior from \code{"modelparty"} objects (e.g., \code{print}, \code{summary}, etc.). For the RSMs in the nodes of a tree, \code{coef} extracts all item and threshold parameters except those restricted to be zero. \code{itempar} and \code{threshpar} extract all item and threshold parameters (including the restricted ones). The \code{plot} method by default employs the \code{\link{node_regionplot}} panel-generating function and the \code{\link{node_profileplot}} panel-generating function is provided as an alternative. } \references{ Komboz B, Zeileis A, Strobl C (2018). Tree-Based Global Model Tests for Polytomous Rasch Models. \emph{Educational and Psychological Measurement}, \bold{78}(1), 128--166. \doi{10.1177/0013164416664394} } \value{ An object of S3 class \code{"rstree"} inheriting from class \code{"modelparty"}. } \seealso{\code{\link[partykit]{mob}}, \code{\link[psychotools]{rsmodel}}, \code{\link{pctree}}, \code{\link{raschtree}}} \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) print(rst, FUN = function(x) " *") ## show summary for terminal panel nodes summary(rst) ## visualization plot(rst, type = "regions") plot(rst, type = "profile") ## extract item and threshold parameters coef(rst) itempar(rst) threshpar(rst) ## inspect parameter stability tests in all splitting nodes if(require("strucchange")) { sctest(rst, node = 1) sctest(rst, node = 2) } options(digits = o$digits) ## IGNORE_RDIFF_END } \keyword{tree} psychotree/man/mpttree.Rd0000644000175000017500000000602714214500744015321 0ustar nileshnilesh\name{mpttree} \alias{mpttree} \alias{coef.mpttree} \alias{plot.mpttree} \alias{print.mpttree} \alias{predict.mpttree} \encoding{latin1} \title{MPT Trees} \description{ Recursive partitioning (also known as trees) based on multinomial processing tree (MPT) models. } \usage{ mpttree(formula, data, na.action, cluster, spec, treeid = NULL, optimargs = list(control = list(reltol = .Machine$double.eps^(1/1.2), maxit = 1000)), \dots) } \arguments{ \item{formula}{a symbolic description of the model to be fit. This should be of type \code{y ~ x1 + x2} where \code{y} should be a matrix of response frequencies and \code{x1} and \code{x2} are used as partitioning variables.} \item{data}{an optional data frame containing the variables in the model.} \item{na.action}{a function which indicates what should happen when the data contain \code{NA}s, defaulting to \code{\link[stats]{na.pass}}.} \item{cluster}{optional vector (typically numeric or factor) with a cluster ID to be employed for clustered covariances in the parameter stability tests.} \item{spec, treeid, optimargs}{arguments for the MPT model passed on to \code{\link[psychotools]{mptmodel}}.} \item{\dots}{arguments passed to \code{\link[partykit]{mob_control}}.} } \details{ MPT trees (Wickelmaier & Zeileis, 2018) are an application of model-based recursive partitioning (implemented in \code{\link[partykit]{mob}}) to MPT models (implemented in \code{\link[psychotools]{mptmodel}}). Various methods are provided for \code{"mpttree"} objects, most of them inherit their behavior from \code{"mob"} objects (e.g., \code{print}, \code{summary}, etc.). The \code{plot} method employs the \code{\link{node_mptplot}} panel-generating function. } \value{ An object of S3 class \code{"mpttree"} inheriting from class \code{"modelparty"}. } \references{ Wickelmaier F, Zeileis A (2018). Using Recursive Partitioning to Account for Parameter Heterogeneity in Multinomial Processing Tree Models. \emph{Behavior Research Methods}, \bold{50}(3), 1217--1233. \doi{10.3758/s13428-017-0937-z} } \seealso{\code{\link[partykit]{mob}}, \code{\link[psychotools]{mptmodel}}.} \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) ## parameter instability tests in root node if(require("strucchange")) sctest(sm_tree, node = 1) ## 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) options(digits = o$digits) } \keyword{tree} psychotree/man/CEMSChoice.Rd0000644000175000017500000000707014214500744015502 0ustar nileshnilesh\name{CEMSChoice} \alias{CEMSChoice} \encoding{latin1} \title{CEMS University Choice Data} \description{ Preferences of 303 students from WU Wien for different CEMS universities. } \usage{data("CEMSChoice")} \format{ A data frame containing 303 observations on 10 variables. \describe{ \item{preference}{Paired comparison of class \code{\link{paircomp}}. Preferences for all 15 paired comparisons from 6 objects: London, Paris, Milano, St. Gallen, Barcelona, Stockholm.} \item{study}{Factor coding main discipline of study: commerce, or other (economics, business administration, business education).} \item{english}{Factor coding knowledge of English (good, poor).} \item{french}{Factor coding knowledge of French (good, poor).} \item{spanish}{Factor coding knowledge of Spanish (good, poor).} \item{italian}{Factor coding knowledge of Italian (good, poor).} \item{work}{Factor. Was the student working full-time while studying?} \item{gender}{Factor coding gender.} \item{intdegree}{Factor. Does the student intend to take an international degree?} \item{preference1998}{Paired comparison of class \code{\link{paircomp}}. This is like \code{preference} but the comparisons between Barcelona an Stockholm are (erroneously) reversed, see below.} } } \details{ Students at Wirtschaftsuniversitt Wien (\url{https://www.wu.ac.at/}) can study abroad visiting one of currently 17 CEMS universities (Community of European Management Schools and International Companies). Dittrich et al. (1998) conduct and analyze a survey of 303 students to examine the student's preferences for 6 universities: London School of Economics, HEC Paris, Universit Commerciale Luigi Bocconi (Milano), Universitt St. Gallen, ESADE (Barcelona), Handelshgskolan i Stockholm. To identify reasons for the preferences, several subject covariates (including foreign language competence, gender, etc.) have been assessed. Furthermore, several object covariates are attached to \code{preference} (and \code{preference1998}): the universities' field of \code{specialization} (economics, management science, finance) and location (Latin country, or other). The correct data are available in the online complements to Dittrich et al. (1998). However, the accompanying analysis was based on an erroneous version of the data in which the choices for the last comparison pair (Barcelona : Stockholm) were accidentally reversed. See the corrigendum in Dittrich et al. (2001) for further details. The variable \code{preference} provides the correct data and can thus be used to replicate the analysis from the corrigendum (Dittrich et al. 2001). For convenience, the erroneous version is provided in \code{preference1998} which can therefore be used to replicate the (incorrect) original analysis (Dittrich et al. 1998). } \source{ The Royal Statistical Society Datasets Website. } \references{ Dittrich R, Hatzinger R, Katzenbeisser W (1998). Modelling the Effect of Subject-Specific Covariates in Paired Comparison Studies with an Application to University Rankings, \emph{Journal of the Royal Statistical Society C}, \bold{47}, 511--525. Dittrich R, Hatzinger R, Katzenbeisser W (2001). Corrigendum: Modelling the Effect of Subject-Specific Covariates in Paired Comparison Studies with an Application to University Rankings, \emph{Journal of the Royal Statistical Society C}, \bold{50}, 247--249. } \seealso{\code{\link{paircomp}}} \examples{ data("CEMSChoice", package = "psychotree") summary(CEMSChoice$preference) covariates(CEMSChoice$preference) } \keyword{datasets} psychotree/man/gpcmtree.Rd0000644000175000017500000000750314232636717015461 0ustar nileshnilesh\name{gpcmtree} \alias{gpcmtree} \alias{print.gpcmtree} \alias{plot.gpcmtree} \alias{itempar.gpcmtree} \alias{threshpar.gpcmtree} \alias{guesspar.gpcmtree} \alias{upperpar.gpcmtree} \title{Generalized Partial Credit Model Trees} \description{ Recursive partitioning (also known as trees) based on generalized partial credit models (GPCMs) for global testing of differential item functioning (DIF). } \usage{ gpcmtree(formula, data, weights = NULL, grouppars = FALSE, vcov = TRUE, nullcats = "downcode", start = NULL, method = "BFGS", maxit = 500L, reltol = 1e-10, minsize = 500, \dots) \method{plot}{gpcmtree}(x, type = c("regions", "profile"), terminal_panel = NULL, tp_args = list(...), tnex = 2L, drop_terminal = TRUE, \dots) } \arguments{ \item{formula}{A symbolic description of the model to be fit. This should be of type \code{y ~ x1 + x2} where \code{y} should be an item response matrix and \code{x1} and \code{x2} are used as partitioning variables. Additionally, it is poosible to allow for impact of a group variable so that different ability distributions are estimated in each group. This can be specified by extending the previous \code{formula} by a group factor \code{g} as \code{y ~ g | x1 + x2}.} \item{data}{a data frame containing the variables in the model.} \item{weights}{an optional vector of weights (interpreted as case weights).} \item{grouppars}{logical. Should the estimated distributional group parameters of a multiple group model be included in the model parameters?} \item{vcov}{logical or character specifying the type of variance-covariance matrix (if any) computed for the final models (see \code{\link[psychotools]{gpcmodel}}).} \item{nullcats}{character string, specifying how items with null categories (i.e., categories not observed) should be treated. See \code{\link[psychotools]{gpcmodel}}, currently only \code{"downcode"} is available.} \item{start}{an optional vector or list of starting values (see \code{\link[psychotools]{gpcmodel}}).} \item{method}{control parameter for the optimizer employed by \code{\link[mirt]{mirt}} for the EM algorithm (see \code{\link[psychotools]{gpcmodel}}).} \item{maxit}{control parameter for the optimizer employed by \code{\link[psychotools]{gpcmodel}}.} \item{reltol}{control parameter for the optimizer employed by \code{\link[psychotools]{gpcmodel}}.} \item{minsize}{integer specification of minimum number of observations in each node, which is passed to \code{\link[partykit]{mob_control}}.} \item{...}{arguments passed to \code{\link[partykit]{mob_control}} for \code{gpcmtree}, or to the underlying \code{plot} method, respectively.} \item{x}{an object of class \code{gpcmtree}.} \item{type}{character specifying the type of plot.} \item{terminal_panel, tp_args, tnex, drop_terminal}{arguments passed to \code{\link[partykit]{mob}}.} } \details{ Generalized partial credit model (GPCM) trees are an application of model-based recursive partitioning (implemented in \code{\link[partykit]{mob}}) to GPCM models (implemented in \code{\link[psychotools]{gpcmodel}}). Various methods are provided for \code{"gpcmtree"} objects, most of them inherit their behavior from \code{"modelparty"} objects (e.g., \code{print}, \code{summary}). Additionally, dedicated extractor functions or provided for the different groups of model parameters in each node of the tree: \code{\link[psychotools]{itempar}} (item parameters), \code{\link[psychotools]{threshpar}} (threshold parameters), \code{\link[psychotools]{guesspar}} (guessing parameters), \code{\link[psychotools]{upperpar}} (upper asymptote parameters). } \value{ An object of S3 class \code{"gpcmtree"} inheriting from class \code{"modelparty"}. } \seealso{\code{\link[partykit]{mob}}, \code{\link[psychotools]{plmodel}}, \code{\link{rstree}}, \code{\link{pctree}}, \code{\link{raschtree}}, \code{\link{npltree}}} psychotree/man/pctree.Rd0000644000175000017500000001212414214500744015116 0ustar nileshnilesh\name{pctree} \alias{pctree} \alias{plot.pctree} \alias{print.pctree} \alias{predict.pctree} \alias{itempar.pctree} \alias{threshpar.pctree} \title{Partial Credit Trees} \description{ Recursive partitioning (also known as trees) based on partial credit models. } \usage{ pctree(formula, data, na.action, nullcats = c("keep", "downcode", "ignore"), reltol = 1e-10, deriv = c("sum", "diff"), maxit = 100L, \dots) \method{predict}{pctree}(object, newdata = NULL, type = c("probability", "cumprobability", "mode", "median", "mean", "category-information", "item-information", "test-information", "node"), personpar = 0, \dots) \method{plot}{pctree}(x, type = c("regions", "profile"), terminal_panel = NULL, tp_args = list(...), tnex = 2L, drop_terminal = TRUE, ...) } \arguments{ \item{formula}{A symbolic description of the model to be fit. This should be of type \code{y ~ x1 + x2} where \code{y} should be a matrix with items in the columns and observations in the rows and \code{x1} and \code{x2} are used as partitioning variables.} \item{data}{a data frame containing the variables in the model.} \item{na.action}{a function which indicates what should happen when the data contain missing values (\code{NA}s).} \item{nullcats}{character. How null categories should be treated. See \code{\link[psychotools]{pcmodel}} for details.} \item{deriv}{character. If "sum" (the default), the first derivatives of the elementary symmetric functions are calculated with the sum algorithm. Otherwise ("diff") the difference algorithm (faster but numerically unstable) is used.} \item{reltol, maxit}{arguments passed via \code{\link[psychotools]{pcmodel}} to \code{\link[stats]{optim}}.} \item{\dots}{arguments passed to the underlying functions, i.e., to \code{\link[partykit]{mob_control}} for \code{pctree}, and to the underlying \code{predict} and \code{plot} methods, respectively.} \item{object, x}{an object of class \code{"raschtree"}.} \item{newdata}{optional data frame with partitioning variables for which predictions should be computed. By default the learning data set is used.} \item{type}{character specifying the type of predictions or plot. For the \code{predict} method, either just the ID of the terminal \code{"node"} can be predicted or some property of the model at a given person parameter (specified by \code{personpar}).} \item{personpar}{numeric person parameter (of length 1) at which the predictions are evaluated.} \item{terminal_panel, tp_args, tnex, drop_terminal}{arguments passed to \code{\link[partykit]{plot.modelparty}}/\code{\link[partykit]{plot.party}}.} } \details{ Partial credit trees are an application of model-based recursive partitioning (implemented in \code{\link[partykit]{mob}}) to partial credit models (implemented in \code{\link[psychotools]{pcmodel}}). Various methods are provided for \code{"pctree"} objects, most of them inherit their behavior from \code{"modelparty"} objects (e.g., \code{print}, \code{summary}, etc.). For the PCMs in the nodes of a tree, \code{coef} extracts all item and threshold parameters except those restricted to be zero. \code{itempar} and \code{threshpar} extract all item and threshold parameters (including the restricted ones). The \code{plot} method by default employs the \code{\link{node_regionplot}} panel-generating function and the \code{\link{node_profileplot}} panel-generating function is provided as an alternative. } \references{ Komboz B, Zeileis A, Strobl C (2018). Tree-Based Global Model Tests for Polytomous Rasch Models. \emph{Educational and Psychological Measurement}, \bold{78}(1), 128--166. \doi{10.1177/0013164416664394} } \value{ An object of S3 class \code{"pctree"} inheriting from class \code{"modelparty"}. } \seealso{\code{\link[partykit]{mob}}, \code{\link[psychotools]{pcmodel}}, \code{\link{rstree}}, \code{\link{raschtree}}} \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) print(pct, FUN = function(x) " *") ## show summary for terminal panel nodes summary(pct) ## visualization plot(pct, type = "regions") plot(pct, type = "profile") ## extract item and threshold parameters coef(pct) itempar(pct) threshpar(pct) ## inspect parameter stability tests in the splitting node if(require("strucchange")) sctest(pct, node = 1) options(digits = o$digits) \donttest{ ## partial credit tree on artificial data from Komboz et al. (2018) data("DIFSimPC", package = "psychotree") pct2 <- pctree(resp ~ gender + age + motivation, data = DIFSimPC) plot(pct2, ylim = c(-4.5, 4.5), names = paste("I", 1:8)) } } \keyword{tree} psychotree/man/npltree.Rd0000644000175000017500000001311214232635506015310 0ustar nileshnilesh\name{npltree} \alias{npltree} \alias{print.npltree} \alias{plot.npltree} \alias{itempar.npltree} \alias{threshpar.npltree} \alias{guesspar.npltree} \alias{upperpar.npltree} \title{Parametric Logisitic (n-PL) IRT Model Trees} \description{ Recursive partitioning (also known as trees) based on parametric logistic (n-PL) item response theory (IRT) models for global testing of differential item functioning (DIF). } \usage{ npltree(formula, data, type = c("Rasch", "1PL", "2PL", "3PL", "3PLu", "4PL"), start = NULL, weights = NULL, grouppars = FALSE, vcov = TRUE, method = "BFGS", maxit = 500L, reltol = 1e-10, deriv = "sum", hessian = TRUE, full = TRUE, minsize = NULL, \dots) \method{plot}{npltree}(x, type = c("profile", "regions"), terminal_panel = NULL, tp_args = list(...), tnex = 2L, drop_terminal = TRUE, \dots) } \arguments{ \item{formula}{A symbolic description of the model to be fit. This should be of type \code{y ~ x1 + x2} where \code{y} should be an item response matrix and \code{x1} and \code{x2} are used as partitioning variables. For the models estimated using marginal maximum likelihood (MML), it is additionally poosible to allow for impact of a group variable so that different ability distributions are estimated in each group. This can be specified by extending the previous \code{formula} by a group factor \code{g} as \code{y ~ g | x1 + x2}.} \item{data}{a data frame containing the variables in the model.} \item{type}{character, specifying either the type of IRT model in \code{npltree} (see also \code{\link[psychotools]{nplmodel}}) or the type of visualization to be used in the \code{plot} method, respectively.} \item{start}{an optional vector or list of starting values (see \code{\link[psychotools]{raschmodel}} or \code{\link[psychotools]{nplmodel}}).} \item{weights}{an optional vector of weights (interpreted as case weights).} \item{grouppars}{logical. Should the estimated distributional group parameters of a multiple-group model be included in the model parameters? (See \code{\link[psychotools]{nplmodel}}.)} \item{vcov}{logical or character specifying the type of variance-covariance matrix (if any) computed for the final models when fitted using MML (see \code{\link[psychotools]{nplmodel}}).} \item{method}{control parameter for the optimizer used by \code{\link[mirt]{mirt}} for the EM algorithm when models are fitted using MML (see \code{\link[psychotools]{nplmodel}}).} \item{maxit}{control parameter for the optimizer used by \code{\link[psychotools]{raschmodel}} or \code{\link[psychotools]{nplmodel}} (see \code{\link[psychotools]{raschmodel}}, \code{\link[psychotools]{nplmodel}}).} \item{reltol}{control parameter for the optimizer used by \code{\link[psychotools]{raschmodel}} or \code{\link[psychotools]{nplmodel}} (see \code{\link[psychotools]{raschmodel}}, \code{\link[psychotools]{nplmodel}}).} \item{deriv}{character. Which type of derivatives should be used for computing gradient and Hessian matrix when fitting Rasch models with the conditional maximum likelihood (CML) method (see \code{\link[psychotools]{raschmodel}})?} \item{hessian}{logical. Should the Hessian be computed for Rasch models fitted with the CML method (see \code{\link[psychotools]{raschmodel}})?} \item{full}{logical. Should a full model object be returned for Rasch models fitted with the CML method (see \code{\link[psychotools]{raschmodel}})?} \item{minsize}{The minimum number of observations in each node, which is passed to \code{\link[partykit]{mob_control}}. If not set, it is 300 for 2PL models and 500 for 3PL, 3PLu, and 4PL models.} \item{...}{arguments passed to \code{\link[partykit]{mob_control}} for \code{npltree}, and to the underlying \code{plot} method.} \item{x}{an object of class \code{npltree}.} \item{terminal_panel, tp_args, tnex, drop_terminal}{arguments passed to \code{\link[partykit]{mob}}.} } \details{ Parametric logistic (n-PL) model trees are an application of model-based recursive partitioning (implemented in \code{\link[partykit]{mob}}) to item response theory (IRT) models (implemented in \code{\link[psychotools]{raschmodel}} and \code{\link[psychotools]{nplmodel}}). While the \code{"Rasch"} model is estimated by conditional maximum likelihood (CML) all other n-PL models are estimated by marginal maximum likelihood (MML) via the standard EM algorithm. The latter allow the specification of multiple-group model to capture group impact on the ability distributions. Various methods are provided for \code{"npltree"} objects, most of them inherit their behavior from \code{"modelparty"} objects (e.g., \code{print}, \code{summary}). Additionally, dedicated extractor functions or provided for the different groups of model parameters in each node of the tree: \code{\link[psychotools]{itempar}} (item parameters), \code{\link[psychotools]{threshpar}} (threshold parameters), \code{\link[psychotools]{guesspar}} (guessing parameters), \code{\link[psychotools]{upperpar}} (upper asymptote parameters). } \value{ An object of S3 class \code{"npltree"} inheriting from class \code{"modelparty"}. } \seealso{\code{\link[partykit]{mob}}, \code{\link[psychotools]{nplmodel}}, \code{\link{rstree}}, \code{\link{pctree}}, \code{\link{raschtree}}, \code{\link{gpcmtree}}} \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 # visualize plot(nplt) # compute summaries of the models fitted in nodes 1 and 2 summary(nplt, 1:2) options(digits = o$digits) } psychotree/man/node_regionplot.Rd0000644000175000017500000000507114232636701017031 0ustar nileshnilesh\name{node_regionplot} \alias{node_regionplot} \title{Panel-Generating Function for Visualizing IRT Tree Models} \description{ Panel-generating function for visualizing the regions of expected item responses across abilities (via shaded rectangles) based on the parameters from the nodes in IRT tree models. } \usage{ node_regionplot( mobobj, names = FALSE, abbreviate = TRUE, type = c("mode", "median", "mean"), ref = NULL, ylim = NULL, off = 0.1, col_fun = gray.colors, bg = "white", uo_show = TRUE, uo_col = "red", uo_lty = 2, uo_lwd = 1.25, ylines = 2 ) } \arguments{ \item{mobobj}{an object of class \code{"npltree"} or class \code{"mob"} fitted by \code{\link[psychotree]{npltree}}} \item{names}{logical or character. If \code{TRUE}, the names of the items are displayed on the x-axis. If \code{FALSE}, numbers of items are shown. Alternatively a character vector of the same length as the number of items can be supplied.} \item{abbreviate}{logical. Should item names be abbreviated? If numeric this controls the length of the abbreviation.} \item{type}{character, specifying which type of threshold parameters are to be used to mark the category regions per item in the plot (see \code{\link[psychotools]{regionplot}} for details).} \item{ref}{a vector of labels or position indices of item parameters which should be used as restriction/for normalization. If \code{NULL} (the default), all items are used (sum zero restriction). See \code{\link[psychotools]{threshpar}} for more details.} \item{ylim}{y axis limits} \item{off}{numeric, the distance (in scale units) between two item rectangles.} \item{col_fun}{function. Function to use for creating the color palettes for the rectangles. Per default \code{gray.colors} is used. Be aware that \code{col_fun} should accept as first argument an integer specifying the number of colors to create.} \item{bg}{color for background filling.} \item{uo_show}{logical. If set to \code{TRUE} (the default), disordered absolute item threshold parameters are indicated by a horizontal line (only if \code{type} is set to \code{"mode"}).} \item{uo_col}{character, color of indication lines (if \code{uo_show}).} \item{uo_lty}{numeric. Line typ of indication lines (if \code{uo_show}).} \item{uo_lwd}{numeric. Line width of indication lines (if \code{uo_show}).} \item{ylines}{numeric. Number of lines used for y-axis labels.} } \value{ A panel function which can be supplied to the \code{plot} method for \code{"npltree"} objects or \code{"mob"} objects fitted by \code{\link[psychotree]{npltree}}. } \keyword{hplot} psychotree/man/DIFSim.Rd0000644000175000017500000000340414214500744014710 0ustar nileshnilesh\name{DIFSim} \alias{DIFSim} \alias{DIFSimPC} \title{Artificial Data with Differential Item Functioning} \description{ Artificial data simulated from a Rasch model and a partial credit model, respectively, where the items exhibit differential item functioning (DIF). } \usage{ data(DIFSim) data(DIFSimPC) } \format{ Two data frames containing 200 and 500 observations, respectively, on 4 variables. \describe{ \item{resp}{an \code{\link[psychotools]{itemresp}} matrix with binary or polytomous results for 20 or 8 items, respectively.} \item{age}{age in years.} \item{gender}{factor indicating gender.} \item{motivation}{ordered factor indicating motivation level.} } } \details{ The data are employed for illustrations in Strobl et al. (2015) and Komboz et al. (2018). See the manual pages for \code{\link{raschtree}} and \code{\link{pctree}} for fitting the tree models.. } \references{ Komboz B, Zeileis A, Strobl C (2018). Tree-Based Global Model Tests for Polytomous Rasch Models. \emph{Educational and Psychological Measurement}, \bold{78}(1), 128--166. \doi{10.1177/0013164416664394} Strobl C, Kopf J, Zeileis A (2015). Rasch Trees: A New Method for Detecting Differential Item Functioning in the Rasch Model. \emph{Psychometrika}, \bold{80}(2), 289--316. \doi{10.1007/s11336-013-9388-3} } \seealso{\code{\link{raschtree}}, \code{\link{pctree}}} \examples{ ## data data("DIFSim", package = "psychotree") data("DIFSimPC", package = "psychotree") ## summary of covariates summary(DIFSim[, -1]) summary(DIFSimPC[, -1]) ## 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) } \keyword{datasets} psychotree/vignettes/0000755000175000017500000000000014234217725014610 5ustar nileshnileshpsychotree/vignettes/raschtree.Rout.save0000644000175000017500000000667214220024140020371 0ustar nileshnilesh > options(prompt = "R> ", continue = "+ ") > library("psychotree") Loading required package: partykit Loading required package: grid Loading required package: libcoin Loading required package: mvtnorm Loading required package: psychotools > data("SPISA", package = "psychotree") > if (file.exists("raschtree-spisa.rda")) load("raschtree-spisa.rda") else { + my_first_raschtree <- raschtree(spisa ~ age + gender + semester + .... [TRUNCATED] > file.remove("raschtree-spisa.rda") [1] TRUE > plot(my_first_raschtree) > plot(my_first_raschtree, col = rep(palette.colors(5), + each = 9)) > coef(my_first_raschtree, node = 4) spisa2 spisa3 spisa4 spisa5 spisa6 spisa7 spisa8 -0.9187137 -1.2874521 -2.6805353 -1.8312493 -1.9026320 -2.4951461 -0.4162699 spisa9 spisa10 spisa11 spisa12 spisa13 spisa14 spisa15 -0.2581010 -2.7296693 -1.1543021 -4.1769262 -1.0539421 0.7916895 -2.3241647 spisa16 spisa17 spisa18 spisa19 spisa20 spisa21 spisa22 -2.0495272 -0.8845425 -1.4541652 1.0321505 -0.9187137 -1.2208998 -2.2428880 spisa23 spisa24 spisa25 spisa26 spisa27 spisa28 spisa29 -1.3540086 -2.7296693 -0.7458437 -1.2208998 -2.9403761 -2.1253688 -0.7458437 spisa30 spisa31 spisa32 spisa33 spisa34 spisa35 spisa36 -0.9865644 -1.4541652 -0.4922363 -3.8232693 -2.1640318 -3.2469996 -2.9403761 spisa37 spisa38 spisa39 spisa40 spisa41 spisa42 spisa43 -2.9972355 -1.9026320 -0.8845425 -3.8232693 -1.0539421 -2.7296693 -3.2469996 spisa44 spisa45 -1.5213581 -3.6324888 > itempar(my_first_raschtree, node = 4) spisa1 spisa2 spisa3 spisa4 spisa5 spisa6 1.75417311 0.83545944 0.46672105 -0.92636220 -0.07707618 -0.14845889 spisa7 spisa8 spisa9 spisa10 spisa11 spisa12 -0.74097296 1.33790319 1.49607208 -0.97549614 0.59987100 -2.42275309 spisa13 spisa14 spisa15 spisa16 spisa17 spisa18 0.70023103 2.54586259 -0.56999156 -0.29535409 0.86963065 0.30000788 spisa19 spisa20 spisa21 spisa22 spisa23 spisa24 2.78632359 0.83545944 0.53327329 -0.48871486 0.40016448 -0.97549614 spisa25 spisa26 spisa27 spisa28 spisa29 spisa30 1.00832941 0.53327329 -1.18620295 -0.37119569 1.00832941 0.76760868 spisa31 spisa32 spisa33 spisa34 spisa35 spisa36 0.30000788 1.26193682 -2.06909621 -0.40985866 -1.49282653 -1.18620295 spisa37 spisa38 spisa39 spisa40 spisa41 spisa42 -1.24306243 -0.14845889 0.86963065 -2.06909621 0.70023103 -0.97549614 spisa43 spisa44 spisa45 -1.49282653 0.23281497 -1.87831571 > if (require("stablelearner", quietly = TRUE)) { + if (!file.exists("my_first_raschtree_st.Rdata")) { + set.seed(4321) + my_first .... [TRUNCATED] > summary(my_first_raschtree_st) Call: raschtree(formula = spisa ~ age + gender + semester + elite + spon, data = SPISA, minsize = 30) Sampler: B = 50 Method = Subsampling with 63.2% data Variable selection overview: freq * mean * gender 1.00 1 1.00 1 spon 0.60 1 0.82 2 semester 0.18 0 0.18 0 age 0.04 0 0.04 0 elite 0.02 0 0.02 0 (* = original tree) > barplot(my_first_raschtree_st) > image(my_first_raschtree_st) > plot(my_first_raschtree_st) *** Run successfully completed *** > proc.time() user system elapsed 52.343 0.263 52.605 psychotree/vignettes/raschtree.Rnw0000644000175000017500000006013214220024140017240 0ustar nileshnilesh\documentclass[nojss]{jss} \usepackage[utf8]{inputenc} %% need no \usepackage{Sweave} \SweaveOpts{concordance=FALSE, engine = R, keep.source=TRUE, eps = FALSE, echo = TRUE} %\VignetteIndexEntry{Using the raschtree Function for Detecting Differential Item Functioning in the Rasch Model} %\VignetteDepends{psychotree, stablelearner} %\VignetteKeywords{item response theory, IRT, Rasch model, differential item functioning, DIF, structural change, multidimensionality} %\VignettePackage{psychotree} <>= options(prompt = "R> ", continue = "+ ") @ \renewcommand{\rm}[0]{Rasch model} %\newcommand{\dif}[0]{differential item functioning} \newcommand{\dif}[0]{DIF} \newcommand{\ip}[0]{item parameter} \newcommand{\mob}[0]{model-based recursive partitioning} \newcommand{\rt}[0]{Rasch tree} %% math commands \newcommand{\argmin}{\operatorname{argmin}\displaylimits} \newcommand{\argmax}{\operatorname{argmax}\displaylimits} \newcommand{\indic}{I} \newcommand{\ui}{\underline{i}} \newcommand{\oi}{\overline{\imath}} \newcommand{\bs}[1]{\boldsymbol{#1}} \newcommand{\fixme}[1]{\textcolor{red}{#1}} \title{Using the \code{raschtree} function for detecting differential item functioning in the Rasch model\\ {\small Updated May 2021, including new section on stability assessment}} \Plaintitle{Using the raschtree function for detecting differential item functioning in the Rasch model} \Shorttitle{Using \texttt{raschtree} for detecting DIF in the Rasch model} \author{Carolin Strobl\\Universit\"at Z\"urich \And Lennart Schneider\\Ludwig-Maximilians-\\Universit\"at M\"unchen \And Julia Kopf\\Universit\"at Z\"urich \And Achim Zeileis\\Universit\"at Innsbruck} \Plainauthor{Carolin Strobl, Lennart Schneider, Julia Kopf, Achim Zeileis} \Abstract{ The \pkg{psychotree} package contains the function \code{raschtree}, that can be used to detect differential item functioning (\dif ) in the Rasch model. The \dif\ detection method implemented in \code{raschtree} is based on the \mob\ framework of \citet{Zeietal:2008} and employs generalized M-fluctuation tests \citep{ZeiHor:2007} for detecting differences in the item parameters between different groups of subjects. The statistical methodology behind \code{raschtree} is described in detail in \citet{Stretal:2015:raschtree}. The main advantage of this approach is that it allows to detect groups of subjects exhibiting \dif , that are not pre-specified, but are detected automatically from combinations of covariates. In this vignette, the practical usage of \code{raschtree} is illustrated. } \Keywords{Item response theory, IRT, \rm, differential item functioning, DIF, structural change, multidimensionality} \Address{ Carolin Strobl\\ Department of Psychology\\ Universit\"at Z\"urich\\ Binzm\"uhlestr.~14\\ 8050 Z\"urich, Switzerland\\ E-mail: \email{Carolin.Strobl@uzh.ch}\\ URL: \url{https://www.psychologie.uzh.ch/fachrichtungen/methoden.html}\\ Lennart Schneider\\ Department of Statistics\\ Ludwig-Maximilians-Universit\"at M\"unchen\\ Ludwigstra{\ss}e 33\\ 80539 M\"unchen, Germany\\ E-mail: \email{lennart.sch@web.de}\\ Julia Kopf\\ Department of Psychology\\ Universit\"at Z\"urich\\ Binzm\"uhlestr.~14\\ 8050 Z\"urich, Switzerland\\ E-mail: \email{Julia.Kopf@uzh.ch}\\ Achim Zeileis\\ Department of Statistics\\ Faculty of Economics and Statistics\\ Universit\"at Innsbruck\\ Universit\"atsstr.~15\\ 6020 Innsbruck, Austria\\ E-mail: \email{Achim.Zeileis@R-project.org}\\ URL: \url{https://www.zeileis.org/} } \begin{document} \section{Differential item functioning in the Rasch model} A key assumption of the \rm\ is that the item parameter estimates should not depend on the person sample (and vice versa). This assumption may be violated if certain items are easier or harder to solve for certain groups of subjects -- regardless of their true ability -- in which case we speak of differential item functioning (\dif ). In order to detect \dif\ with the \code{raschtree} function, the item responses and all covariates that should be tested for \dif\ need to be handed over to the method, as described below. Then the following steps are conducted: % \begin{enumerate} \item At first, one joint \rm\ is fit for all subjects. \item Then it is tested statistically whether the item parameters differ along any of the covariates. \item In that case the sample is split along that covariate and two separate \rm s are estimated. \item This process is repeated as long as there is further \dif\ (and the subsample is still large enough). \end{enumerate} For details on the underlying statistical framework implemented in \code{raschtree} see \citet{Stretal:2015:raschtree}. The main advantage of the \rt\ approach is that \dif\ can be detected between groups of subjects created by more than one covariate. For example, certain items may be easier for male subjects over the age of 40 as opposed to all other subjects. In this case \dif\ is associated with an interaction of the variables gender and age, rather than any one variable alone. Moreover, with this approach it is not necessary to pre-define cutpoints in continuous variables, as would be the standard approach when using, e.g., a likelihood ratio or Wald test: Usually, age groups are pre-specified, for example by means of splitting at the median. However, the median may not be where the actual parameter change occurs -- it could be that only very young or very old subjects find certain items particularly easy or hard. By splitting at the median this effect may be disguised. Therefore, the Rasch tree method searches for the value corresponding to the strongest parameter change and splits the sample at that value. Certain statistical techniques are necessary for doing this in a statistically sound way, as described in detail in \citet{Stretal:2015:raschtree}. Now the practical application of \code{raschtree} is outlined, starting with the data preparation. \section{Data preparation} When using \code{raschtree} for the first time, the \pkg{psychotree} package needs to be installed first: % <>= install.packages("psychotree") @ % After this, the package is permanently installed on the computer, but needs to be made available at the start of every new \proglang{R} session: % <>= library("psychotree") @ % The package contains a data example for illustrating the \rt s, that can be loaded with: % <>= data("SPISA", package = "psychotree") @ % The data set \code{SPISA} consists of the item responses and covariate values of \Sexpr{nrow(SPISA)} subjects. It is a subsample of a larger data set from an online quiz, that was carried out by the German weekly news magazine SPIEGEL in 2009 via the online version of the magazine SPIEGEL Online (SPON). The quiz was designed for testing one's general knowledge and consisted of a total of 45~items from five different topics: politics, history, economy, culture and natural sciences. A thorough analysis and discussion of the original data set is provided in \citet{SPISA:book}. The data are structured in the following way: The variable \code{spisa} contains the 0/1-responses of all subjects to all test items (i.e., \code{spisa} is only a single variable but contains a matrix of responses). In addition to that, covariates like age and gender are available for each subject: \begin{center} \begin{tabular}{|ccccccccccc|ccccc|} \hline \multicolumn{11}{|c|}{Item reponses} & \multicolumn{5}{c|}{Covariates}\\ \multicolumn{11}{|c|}{\code{\Sexpr{names(SPISA)[1]}}} & \code{\Sexpr{names(SPISA)[2]}} & \code{\Sexpr{names(SPISA)[3]}} & \code{\Sexpr{names(SPISA)[4]}} & \code{\Sexpr{names(SPISA)[5]}} & \code{\Sexpr{names(SPISA)[6]}}\\ \hline 1 & 0 & 0 & 1 & 1 & $\cdots$ & 0 & 1 & 1 & 1 & 1 & female & 21 & 3 & no & 1--3/month\\ 0 & 1 & 0 & 1 & 1 & $\cdots$ & 1 & 1 & 1 & 1 & 1 & male & 20 & 1 & no & 4--5/week\\ 0 & 0 & 0 & 1 & 0 & $\cdots$ & 0 & 1 & 1 & 1 & 1 & female & 25 & 9 & no & 1--3/month\\ 0 & 0 & 1 & 1 & 1 & $\cdots$ & 1 & 1 & 0 & 1 & 1 & male & 27 & 10 & no & never\\ 1 & 1 & 1 & 1 & 1 & $\cdots$ & 0 & 0 & 1 & 1 & 1 & male & 24 & 8 & no & 1/week\\ 1 & 0 & 0 & 1 & 0 & $\cdots$ & 1 & 1 & 0 & 1 & 1 & male & 20 & 1 & yes & 1--3/month\\ & & & & & $\vdots$ & & & & & & $\vdots$ & $\vdots$ & $\vdots$ & $\vdots$ & $\vdots$ \\ \hline \end{tabular} \end{center} \medskip If your own data set, termed for example \code{mydata}, is in a different format, it is easy to change it into the right format for \code{raschtree}. For example, if the item responses are coded as individual variables like this: \begin{center} \begin{tabular}{|ccccc|ccc|} \hline \multicolumn{5}{|c|}{Item reponses} & \multicolumn{3}{c|}{Covariates}\\ \code{item1} & \code{item2} & \code{item3} & \code{item4} & \code{item5} & \code{gender} & \code{age} & \code{semester} \\ \hline 1 & 0 & 0 & 1 & 1 & female & 21 & 3 \\ 0 & 1 & 0 & 1 & 1 & male & 20 & 1 \\ 0 & 0 & 0 & 1 & 0 & female & 25 & 9 \\ 0 & 0 & 1 & 1 & 1 & male & 27 & 10 \\ 1 & 1 & 1 & 1 & 1 & male & 24 & 8 \\ \hline \end{tabular} \end{center} \medskip You can bring them into a more convenient format by first defining a new variable \code{resp} that contains the matrix of item responses (i.e., the first five columns of \code{mydata}): % <>= mydata$resp <- as.matrix(mydata[ , 1:5]) @ % Then you can omit the original separate item response variables from the data set % <>= mydata <- mydata[ , -(1:5)] @ % The data set then contains both the complete matrix of item responses -- termed \code{resp} -- and the covariates as individual columns, so that later it is easier to address the complete matrix of item responses in the function call. Now the data preparation is done and we can fit a \rt . \section{Model fitting, plotting and extraction of parameter values} \label{raschtree} The idea of \rt s is to model differences in the \rm\ for the item responses by means of the covariates. This idea translates intuitively into the formula interface that is commonly used in \proglang{R} functions, such as \code{lm} for linear models: In a linear model, where the response variable \code{y} is modeled by the covariates \code{x1} and \code{x2}, the formula in \proglang{R} looks like this: % \begin{center} \code{y ~ x1 + x2} \end{center} % Very similarly, in the \rt\ for our \code{SPISA} data, where the item responses \code{spisa} are modeled by the covariates \code{age}, \code{gender}, \code{semester}, \code{elite} and \code{spon}, the formula used in \code{raschtree} looks like this: % \begin{center} \code{spisa ~ age + gender + semester + elite + spon} \end{center} % The complete call is % <>= my_first_raschtree <- raschtree(spisa ~ age + gender + semester + elite + spon, data = SPISA) @ % Note that the model is not only fitted, but also saved under the name \code{my_first_raschtree}, so that we can later extract information from the fitted model object and plot the \rt . As a shortcut, when all other variables in the data set are to be used as covariates, as in our example, the covariates do not have to be listed explicitly in the formula but can replaced by a dot, as in \code{raschtree(spisa ~ ., data = SPISA)} (leading to equivalent output as the call above). Moreover, if you want to see the process of the \rt\ fitting, including the computation of the $p$-values and corresponding split decisions in each step, you can use the \code{verbose} option, as in \code{raschtree(spisa ~ ., data = SPISA, verbose = TRUE)}. The \code{verbose} option also has the advantage that you can see something happening on your screen when \code{raschtree} takes a while to complete -- which may be the case if there are many variables with \dif\ and if these variables offer many possible cutpoints, like continuous variables and factors with many categories. In case you receive an error message, one possible cause is that certain nodes in the \rt\ contain too few observations to actually fit a Rasch model. In this case it might be necessary to restrict the minimum number of observations per node to a higher value by means of the \code{minsize} argument: % <>= my_first_raschtree <- raschtree(spisa ~ age + gender + semester + elite + spon, data = SPISA, minsize = 30) @ <>= if(file.exists("raschtree-spisa.rda")) load("raschtree-spisa.rda") else { <> save(my_first_raschtree, file = "raschtree-spisa.rda") } file.remove("raschtree-spisa.rda") @ % Note that while the minimum number of observations per node, \code{minsize}, should be chosen large enough to fit the model, it should not be chosen unnecessarily large, because otherwise splits at the margins of the feature space cannot be selected. The resulting \rt\ can then be plotted with the generic \code{plot} call: % \setkeys{Gin}{width=\textwidth} \begin{center} <>= plot(my_first_raschtree) @ \end{center} The plot function also accepts many options for standard plot functions, including coloring. Here, a qualitative color palette is employed to indicate the blocks of nine items from each of the five different topics covered in the quiz: politics, history, economy, culture and natural sciences: % \begin{center} <>= plot(my_first_raschtree, col = rep(palette.colors(5), each = 9)) @ \label{raschtree:fig} \end{center} For extracting the estimated item parameters for each group, there are two different calls corresponding to the two different ways to scale the item parameters: The parameters of a \rm\ are unique only up to linear transformations. In particular, the origin of the scale is not fixed but chosen arbitrarily. There are two common ways to choose the origin: setting one item parameter to zero or setting the sum of all item parameters to zero. Accordingly, there are two calls to extract the item parameters from \code{raschtree} one way or the other: % <>= coef(my_first_raschtree, node = 4) @ % where the parameter for the first item is set to zero and therefore not displayed (the call is termed \code{coef}, because that is the name of the call extracting the estimated parameters, or coefficients, from standard regression models generated, e.g., with the \code{lm} function) and % <>= itempar(my_first_raschtree, node = 4) @ % where the item parameters by default sum to zero (other restrictions can be specified as well). Here the item parameters have been displayed only for the subjects in node number 4 (representing female students who access the online magazine more than once per week) to save space. The item parameters for all groups can be displayed by omitting the \code{node} argument. \section{Interpretation} Ideally, if none of the items showed \dif , we would find a tree with only one single node. In this case, one joint \rm\ would be appropriate to describe the entire data set. (But note that -- like all statistical methods based on significance tests -- \rt s have power to detect \dif\ only if the sample size is large enough.) If, however, the \rt\ shows at least one split, this indicates that \dif\ is present and that it is not appropriate to compare the different groups of subjects with the test without accounting for it. \dif\ may be caused by certain characteristics of the items, such as their wording. In practice, items showing \dif\ are often excluded from the test. Sometimes it may also be possible to rephrase the items to resolve the \dif . If several items show the same \dif\ pattern, this may also indicate that they measure a secondary dimension in addition to the primary dimension. An example could be word problems in a math test, that also measure reading ability. If multiple dimensions are of interest, a multidimensional model can be used \citep[see packages \texttt{mirt} and \texttt{TAM},][]{mirt:pkg,mirt:paper,TAM:pkg}. Note, however, that whether multidimensionality can be detected always depends not only on the items, but also on whether the persons in the sample used for validating the test actually show variation on the different dimensions. Finally note that when one joint, unidimensional \rm\ is not appropriate to describe the entire test, this also means that a ranking of the subjects based on the raw scores (i.e., the number of items that each subject answered correctly) is not appropriate either, because this would also assume that the test is unidimensional. \section{Stability assessment} \label{stability} A tree based on a single sample does not provide any assessment of the confidence we should have in its interpretation -- e.g., as we would be used to in parametric models by inspecting the confidence intervals for parameter estimates. However, a toolkit for assessing the stability of trees based on resampling is now provided by the \pkg{stablelearner} package \citep{PhiZeiStr:2016}. Starting from version 0.1-2, \pkg{stablelearner} offers descriptive and graphical analyses of the variable and cutpoint selection of trees for psychometric models, including \rt s, fitted via the \pkg{psychotree} package (note that this requires at least version 0.6-0 of the \pkg{psychotools} package, which is used internally for fitting the models). This descriptive and graphical analysis of the variable and cutpoint selection can be performed by using the \code{stabletree} function, which repeatedly draws random samples from the training data, refits the tree, and displays a summary of the variable and cutpoint selection over the samples. This can give us an intuition of how similar or dissimilar the results would have been for different random samples. The package has to be installed (once), e.g., via <>= install.packages("stablelearner") @ and then activated (each time) for the current session using <>= library("stablelearner") @ Then, we can easily assess the stability of the Rasch tree \code{my_first_raschtree} by using the \code{stabletree} function. We set a seed for the random number generator to make the analysis based on random draws from the training data reproducible. By default, \code{stabletree} performs subsampling with a fraction of \code{v = 0.632} of the original training data and refits 500 trees. Here, we only refit \code{B = 50} trees to save time, but still this computation can take a while. % <>= set.seed(4321) my_first_raschtree_st <- stabletree(my_first_raschtree, B = 50) @ % In case you receive an error message, again this may be due to a too small sample size for fitting the model in certain nodes. Even if in the original tree all nodes were big enough to estimate the model, due to the random sampling in \code{stabletree}, smaller nodes can result in some random samples. In order to prevent this, the minimum node size \code{minsize} needs to be increased already in the \code{raschtree} command (cf.~Section \ref{raschtree}), before applying \code{stabletree}, because the settings of the original \rt\ are passed on to \code{stabletree}. <>= if(require("stablelearner", quietly = TRUE)) { if(!file.exists("my_first_raschtree_st.Rdata")){ set.seed(4321) my_first_raschtree_st <- stabletree(my_first_raschtree, B = 50) save(my_first_raschtree_st, file = "my_first_raschtree_st.Rdata") } else{ load("my_first_raschtree_st.Rdata") } spon1 <- summary(my_first_raschtree_st)$vstab["spon", 1] spon3 <- summary(my_first_raschtree_st)$vstab["spon", 3] } else { my_first_raschtree_st <- matrix(1) spon1 <- spon3 <- 0 } @ % The function \code{stabletree} returns an object of class \code{stabletree}, for which a \code{summary} method and several \code{plot} methods exist: % <>= summary(my_first_raschtree_st) @ % The summary prints the relative variable selection frequencies (\code{freq}) as well as the average number of splits in each variable (\code{mean}) over all 50 trees. A relative variable selection frequency of one means that a variable was selected in each of the 50 trees. The average number of splits can show values greater than 1 if the same variable is used more than once in the same tree. The asterisk columns indicate whether this variable was selected in the original tree, and how often. For example, the variable \code{gender} was selected as a splitting variable once in every tree, including the original tree. The variable \code{spon}, on the other had, was selected in \Sexpr{100 * spon1}\% of the trees, also in the orignal tree, on average \Sexpr{spon3} times, but twice in the original tree. By using \code{barplot}, we can also visualize the variable selection frequencies: % \setkeys{Gin}{width=.5\textwidth} \begin{center} <>= barplot(my_first_raschtree_st) @ \end{center} % Here the variables that were included in the original tree are marked by darker shading and underlined variable names. We see again that most trees agreed on the two most relevant splitting variables, \code{gender} and \code{spon}. The additional function \code{image} allows for a more detailed visualization of the variable selection patterns, that are displayed as one row on the y-axis for each of the 50 trees: % \setkeys{Gin}{width=.5\textwidth} \begin{center} <>= image(my_first_raschtree_st) @ \end{center} We observe again that about half of the 50 trees have selected the same combination of variables, \code{gender} and \code{spon}, that was also selected in the original tree. This combination of variables selected by the original tree is framed in red. Other combinations that were selected by larger groups of trees were, e.g., \code{gender} alone, \code{gender} and \code{semester}, \code{gender}, \code{spon} and \code{age} as well as \code{gender}, \code{spon} and \code{semester}. Finally, the \code{plot} function allows us to inspect the cutpoints and resulting partitions for each variable over all 50 trees, with the variables included in the original tree again marked by underlined variable names and the cutpoints from the original trees indicated in red: % \setkeys{Gin}{width=\textwidth} \begin{center} <>= plot(my_first_raschtree_st) @ \end{center} % Regarding the variable \code{gender}, that is coded binarily here, there is only one possible cutpoint, which is used whenever the variable is used for splitting (including the first split in the original tree, as indicated in red). Looking at the ordered factor \code{spon}, we observe that a cutpoint between \code{2-3/week} and \code{4-5/week} occurred most frequently, followed by the neighboring cutpoint between \code{1/week} and \code{2-3/week}. These two cutpoints were also chosen in the original tree (as indicated by the red vertical lines; the number two indicates that this variable was used for the second split in each branch of the tree, cf.~the illustration of the original tree on p.~\pageref{raschtree:fig}). Other cutpoints only occurred very rarely. Finally, regarding the other variables \code{semester}, \code{age}, and \code{elite} (which were not selected in the original tree), we observe cutpoints between \code{5} and \code{8} for the variable \code{semester}, quite heterogenous cutpoints for the variable \code{age}, and the only possible cutpoint for the binary variable \code{elite}, that is used only in very few trees, as we saw above. To conclude, the summary table and plots can help us gain some insight into the stability of our original \rt\ by means of a resampling approach. Here, the \dif\ effects of \code{gender} and \code{spon} appear to be quite stable. \section*{Acknowledgments} The work of Carolin Strobl was supported by grant STR1142/1-1 (``Methods to Account for Subject-Co\-vari\-ates in IRT-Models'') from the German Research Foundation (DFG). The work of Lennart Schneider was supported in part by grant 100019\_152548 (``Detecting Heterogeneity in Complex IRT Models for Measuring Latent Traits'') from the Swiss National Science Foundation (SNF). The authors would like to thank the late Reinhold Hatzinger for important insights stimulated by conversations and the \proglang{R}~package \pkg{eRm} \citep{MaiHat:2007,eRm:pkg}. \bibliography{psychotree} \end{document} psychotree/vignettes/psychotree.bib0000644000175000017500000001201114214500743017437 0ustar nileshnilesh@InProceedings{PhiZeiStr:2016, author = {Michel Philipp and Achim Zeileis and Carolin Strobl}, title = {A Toolkit for Stability Assessment of Tree-Based Learners}, year = {2016}, booktitle = {Proceedings of {COMPSTAT} 2016 -- 22nd International Conference on Computational Statistics}, pages = {315--325}, editor = {Ana Colubi and Angela Blanco and Cristian Gatu}, isbn = {978-90-73592-36-0}, publisher = {The International Statistical Institute/International Association for Statistical Computing}, url = {https://www.zeileis.org/papers/Philipp+Zeileis+Strobl-2016.pdf} } @Article{mirt:paper, title = {{mirt}: {A} Multidimensional {Item Response Theory} Package for the {R} Environment}, author = {R. Philip Chalmers}, journal = {Journal of Statistical Software}, year = {2012}, volume = {48}, number = {6}, pages = {1--29}, url = {http://www.jstatsoft.org/v48/i06}, } @Manual{mirt:pkg, title = {{mirt}: Multidimensional {Item Response Theory}}, author = {R. Philip Chalmers}, year = {2020}, note = {R package version 1.32.1}, url = {https://CRAN.R-project.org/package=mirt}, } @Manual{TAM:pkg, title = {{TAM}: {T}est Analysis Modules}, author = {Alexander Robitzsch and Thomas Kiefer and Margaret Wu}, year = {2020}, note = {R package version 3.5-19}, url = {https://CRAN.R-project.org/package=TAM}, } @Manual{eRm:pkg, title = {\pkg{eRm}: {E}xtended {R}asch Modeling}, author = {Patrick Mair and Reinhold Hatzinger and Marco Maier}, year = {2020}, note = {\proglang{R}~package version~1.0-1}, url = {http://CRAN.R-project.org/package=eRm} } @Article{, title = {{Extended Rasch modeling: The eRm package for the application of IRT models in R}}, author = {Patrick Mair and Reinhold Hatzinger}, year = {2007}, pages = {1--20}, journal = {{Journal of Statistical Software}}, volume = {20}, issue = {9}, url = {http://www.jstatsoft.org/v20/i09}, } @Article{MaiHat:2007, author = {Patrick Mair and Reinhold Hatzinger}, title = {Extended {R}asch Modeling: The \pkg{eRm} Package for the Application of {IRT} Models in \proglang{R}}, journal = {Journal of Statistical Software}, volume = {20}, number = {9}, pages = {1--20}, year = {2007}, url = {http://www.jstatsoft.org/v20/i09/} } @Book{SPISA:book, year = {2010}, title = {{Allgemeinbildung in Deutschland -- Erkenntnisse aus dem SPIEGEL Studentenpisa-Test}}, editor = {S. Trepte and M. Verbeet}, publisher = {VS Verlag}, address = {Wiesbaden} } @Article{Stretal:2010:btl2mob, author = {Carolin Strobl and Florian Wickelmaier and Achim Zeileis}, title = {Accounting for Individual Differences in {Bradley-Terry} Models by Means of Recursive Partitioning}, year = {2010}, journal = {Journal of Educational and Behavioral Statistics}, pages = {}, volume = {}, number = {}, note = {To appear} } @InCollection{Stretal:2010:spisa, author = {Carolin Strobl and Julia Kopf and Achim Zeileis}, title = {Wissen {F}rauen weniger oder nur das {F}alsche? -- {E}in statistisches {M}odell f{\"u}r unterschiedliche {A}ufgaben-{S}chwierigkeiten in {T}eilstichproben}, year = {2010}, booktitle = {{Allgemeinbildung in Deutschland -- Erkenntnisse aus dem SPIEGEL Studentenpisa-Test}}, editor = {Sabine Trepte and Markus Verbeet}, publisher = {VS Verlag}, address = {Wiesbaden}, pages = {255--272} } @TechReport{Stretal:2010:raschtree:techreport, author = {Carolin Strobl and Julia Kopf and Achim Zeileis}, title = {A New Method for Detecting Differential Item Functioning in the {R}asch Model}, institution = {Department of Statistics, Ludwig-Maximilians-Universit\"at M\"unchen}, year = {2010}, type = {Technical Report}, number = {92}, url = {http://epub.ub.uni-muenchen.de/11915/} } @article{Stretal:2015:raschtree, author = {C. Strobl and J. Kopf and A. Zeileis}, title = {{R}asch Trees: {A} New Method for Detecting Differential Item Functioning in the {R}asch Model}, journal = {Psychometrika}, volume = {80}, number = {2}, pages = {289--316}, year = {2015} } @Article{Zeietal:2008, author = {Achim Zeileis and Torsten Hothorn and Kurt Hornik}, title = {Model-Based Recursive Partitioning}, journal = {Journal of Computational and Graphical Statistics}, year = {2008}, volume = {17}, number = {2}, pages = {492--514} } @Article{ZeiHor:2007, author = {Achim Zeileis and Kurt Hornik}, title = {Generalized {M}-Fluctuation Tests for Parameter Instability}, journal = {Statistica Neerlandica}, year = {2007}, volume = {61}, number = {4}, pages = {488--508} } @Article{Zeietal:2009, author = {Achim Zeileis and Kurt Hornik and Paul Murrell}, title = {Escaping {RGB}land: Selecting Colors for Statistical Graphics}, journal = {Computational Statistics \& Data Analysis}, year = {2009}, volume = {53}, number = {9}, pages = {3259--3270} } psychotree/build/0000755000175000017500000000000014234217725013677 5ustar nileshnileshpsychotree/build/vignette.rds0000644000175000017500000000052714234217725016242 0ustar nileshnileshuQj0<@Kz- &J =:Ȓdo+r zh3"Lt1m03"SuJ<wFf+I ih3A\v,c*u^"Q̦KYզJ0X%@4|gU`o sw| O)`j% 8MJC.ާ_p/WAMgHahn2hDg%GkS5W >f۶WAw/О03qgnCZ4tݥVwx#lC& ۰ʙeB{W/E #-psychotree/build/partial.rdb0000644000175000017500000000007314234217627016025 0ustar nileshnileshb```b`a 0X84k^bnj1!d7psychotree/tests/0000755000175000017500000000000014220024137013726 5ustar nileshnileshpsychotree/tests/Examples/0000755000175000017500000000000014220024137015504 5ustar nileshnileshpsychotree/tests/Examples/psychotree-Ex.Rout.save0000644000175000017500000007165014232641101022063 0ustar nileshnilesh 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 > > > > ### *