R : Copyright 2005, The R Foundation for Statistical Computing Version 2.1.1 (2005-06-20), ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for a HTML browser interface to help. Type 'q()' to quit R. > ### *
> ### > attach(NULL, name = "CheckExEnv") > assign(".CheckExEnv", as.environment(2), pos = length(search())) # base > ## add some hooks to label plot pages for base and grid graphics > setHook("plot.new", ".newplot.hook") > setHook("persp", ".newplot.hook") > setHook("grid.newpage", ".gridplot.hook") > > assign("cleanEx", + function(env = .GlobalEnv) { + rm(list = ls(envir = env, all.names = TRUE), envir = env) + RNGkind("default", "default") + set.seed(1) + options(warn = 1) + delayedAssign("T", stop("T used instead of TRUE"), + assign.env = .CheckExEnv) + delayedAssign("F", stop("F used instead of FALSE"), + assign.env = .CheckExEnv) + sch <- search() + newitems <- sch[! sch %in% .oldSearch] + for(item in rev(newitems)) + eval(substitute(detach(item), list(item=item))) + missitems <- .oldSearch[! .oldSearch %in% sch] + if(length(missitems)) + warning("items ", paste(missitems, collapse=", "), + " have been removed from the search path") + }, + env = .CheckExEnv) > assign("..nameEx", "__{must remake R-ex/*.R}__", env = .CheckExEnv) # for now > assign("ptime", proc.time(), env = .CheckExEnv) > grDevices::postscript("depmix-Examples.ps") > assign("par.postscript", graphics::par(no.readonly = TRUE), env = .CheckExEnv) > options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly")) > options(warn = 1) > library('depmix') Loading required package: MASS > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "depmix-internal" > > ### * depmix-internal > > flush(stderr()); flush(stdout()) > > ### Name: depmix-internal > ### Title: Fitting Dependent Mixture Models > ### Aliases: checkSetRecode recode fblo fbuo ppar recitt pp np pa2conr > ### paridx fresp bdiag cl2st cl2stob kmstart poststart tr2stin > ### Keywords: models > > ### ** Examples > > > > > > cleanEx(); ..nameEx <- "dmm" > > ### * dmm > > flush(stderr()); flush(stdout()) > > ### Name: dmm > ### Title: Dependent Mixture Model Specifiction > ### Aliases: dmm summary.dmm lcm lca > ### Keywords: models > > ### ** Examples > > > # create a 2 state model with one continuous and one binary response > # with start values provided in st > st <- c(1,0.9,0.1,0.2,0.8,2,1,0.7,0.3,5,2,0.2,0.8,0.5,0.5) > mod <- dmm(nsta=2,itemt=c(1,2), stval=st) > summary(mod) Model: 2 -state model Number of parameters: 15 Free parameters: 9 Number of states: 2 Number of items: 2 Item types: 1 2 Parameter values, transition matrix State1 State2 State1 0.9 0.1 State2 0.2 0.8 Parameter values, observation parameters Item1,mean Item1,stddev Item2,p 1 Item2,p 2 State1 2 1 0.7 0.3 State2 5 2 0.2 0.8 Parameter values, initial state probabilies State1 State2 val 0.5 0.5 > > # 2 class latent class model with equal conditional probabilities in each class > > stv=c(1,rep(c(0.9,0.1),5),rep(c(0.1,0.9),5),0.5,0.5) > > # here the conditional probs of the first item are set equal to those in > # the subsequent items > conpat=c(1,rep(c(2,3),5),rep(c(4,5),5),1,1) > > lc=lca(ncl=2,itemtypes=rep(2,5),conpat=conpat,stv=stv) > summary(lc) Model: 2 class model Number of parameters: 27 Free parameters: 4 Number of states: 2 Number of items: 5 Item types: 2 2 2 2 2 Parameter values, observation parameters Item1,p 1 Item1,p 2 Item2,p 1 Item2,p 2 Item3,p 1 Item3,p 2 Item4,p 1 Class1 0.9 0.1 0.9 0.1 0.9 0.1 0.9 Class2 0.1 0.9 0.1 0.9 0.1 0.9 0.1 Item4,p 2 Item5,p 1 Item5,p 2 Class1 0.1 0.9 0.1 Class2 0.9 0.1 0.9 Parameter values, unconditional (class) probabilities Class1 Class2 val 0.5 0.5 > > > > > cleanEx(); ..nameEx <- "fitdmm" > > ### * fitdmm > > flush(stderr()); flush(stdout()) > > ### Name: fitdmm > ### Title: Fitting Dependent Mixture Models > ### Aliases: depmix fitdmm loglike posterior computeSes bootstrap > ### summary.fit oneliner > ### Keywords: models > > ### ** Examples > > > # COMBINED RT AND CORRECT/INCORRECT SCORES from a 'switching' experiment > > data(speed) > mod <- dmm(nsta=2,itemt=c(1,2)) # gaussian and binary items > fit1 <- fitdmm(dat=speed,dmm=mod) Initial loglikelihood: -297.4306 iteration = 0 Step: [1] 0 0 0 0 0 0 0 0 0 Parameter: [1] 0.4074968 -0.6030893 -0.5559689 0.7830820 -0.1846599 6.4032844 0.2318094 [8] 5.5372838 0.2189520 Function Value [1] 297.4306 Gradient: [1] 17.838774 4.395048 1.009810 6.808036 9.848922 30.788829 -43.417653 [8] 32.399634 54.905265 iteration = 16 Parameter: [1] 0.3877964 -0.6050630 -0.5429171 0.7942191 -0.2057752 6.3914953 0.2396807 [8] 5.5200651 0.2019121 Function Value [1] 296.1200 Gradient: [1] -0.55687642 0.99484837 3.34099578 0.08263532 3.08080738 -0.57541695 [7] -0.09220585 -0.81976170 -0.25060547 Successive iterates within tolerance. Current iterate is probably solution. Final loglikelihood: -296.1200 Computing posteriors Computing standard errors This took 16 iterations, 5.2 seconds > summary(fit1) Model: 2 -state model fitted at Wed Jul 13 13:09:46 2005 Optimization information, method is nlm Iterations: 16 Inform: 2 (look up the respective manuals for more information.) Loglikelihood of fitted model: -296.12 AIC: 610.24 BIC: 647.001 Number of observations (used in BIC): 439 Fitted model Model: 2 -state model Number of parameters: 15 Free parameters: 9 Number of states: 2 Number of items: 2 Item types: 1 2 Parameter values, transition matrix State1 State2 State1 0.916 0.084 se 0.018 0.018 t 50.854 4.671 State2 0.104 0.896 se 0.024 0.024 t 4.263 36.678 Parameter values, observation parameters Item1,mean Item1,stddev Item2,p 1 Item2,p 2 State1 6.391 0.240 0.098 0.902 se 0.016 0.012 0.019 0.019 t 399.429 20.735 5.060 46.543 State2 5.520 0.202 0.469 0.531 se 0.017 0.014 0.037 0.037 t 324.383 14.475 12.638 14.313 Parameter values, initial state probabilies State1 State2 val 1.000 0.000 se 0.578 0.578 t 1.731 0.000 > > # add some constraints using conpat > conpat=rep(1,15) > conpat[1]=0 > conpat[14:15]=0 > conpat[8:9]=0 > # use starting values from the previous model fit, except for the guessing > # parameters which should really be 0.5 > stv=c(1,.896,.104,.084,.916,5.52,.20,.5,.5,6.39,.24,.098,.90,0,1) > mod=dmm(nstates=2,itemt=c("n",2),stval=stv,conpat=conpat) > > fit2 <- fitdmm(dat=speed,dmm=mod) Initial loglikelihood: -296.4092 iteration = 0 Step: [1] 0 0 0 0 0 0 0 Parameter: [1] 0.8120000 -0.3876615 0.4159457 5.5200000 0.2000000 6.3900000 0.2400000 Function Value [1] 296.4092 Gradient: [1] -1.6611909 0.5624142 1.9924059 2.3831597 -10.4053555 -4.8517480 [7] -0.9033751 iteration = 12 Parameter: [1] 0.8148616 -0.3892347 0.4142363 5.5203960 0.2021620 6.3916302 0.2397466 Function Value [1] 296.3901 Gradient: [1] 1.241281e-04 6.447644e-05 1.740612e-04 -3.993284e-05 -9.087583e-05 [6] 2.185769e-04 -9.794727e-05 Successive iterates within tolerance. Current iterate is probably solution. Final loglikelihood: -296.3901 Computing posteriors Computing standard errors This took 12 iterations, 2.36 seconds > summary(fit2) Model: 2 -state model fitted at Wed Jul 13 13:09:50 2005 Optimization information, method is nlm Iterations: 12 Inform: 2 (look up the respective manuals for more information.) Loglikelihood of fitted model: -296.39 AIC: 606.78 BIC: 635.372 Number of observations (used in BIC): 439 Fitted model Model: 2 -state model Number of parameters: 15 Free parameters: 7 Number of states: 2 Number of items: 2 Item types: normal 2 Parameter values, transition matrix State1 State2 State1 0.899 0.101 se 0.024 0.024 t 37.670 4.251 State2 0.084 0.916 se 0.018 0.018 t 4.667 51.076 Parameter values, observation parameters Item1,mean Item1,stddev Item2,p 1 Item2,p 2 State1 5.520 0.202 0.500 0.500 se 0.017 0.014 0.000 0.000 t 324.123 14.481 NA NA State2 6.392 0.240 0.098 0.902 se 0.016 0.012 0.019 0.019 t 399.261 20.703 5.058 46.411 Parameter values, initial state probabilies State1 State2 val 0 1 se 0 0 t NA NA > > # add covariates to the model to incorporate the fact the accuracy pay off changes per trial > # 2-state model with covariates + other constraints > conpat=rep(1,15) > conpat[1]=0 > conpat[8:9]=0 > conpat[14:15]=0 > conpat[2]=2 > conpat[5]=2 > stv=c(1,0.9,0.1,0.1,0.9,5.5,0.2,0.5,0.5,6.4,0.25,0.9,0.1,0,1) > tdfix=rep(0,15) > tdfix[2:5]=1 > stcov=rep(0,15) > stcov[2:5]=c(-0.4,0.4,0.15,-0.15) > > mod<-dmm(nstates=2,itemt=c("n",2),stval=stv,conpat=conpat,tdfix=tdfix,tdst=stcov,modname="twoboth+cov") > > fit3 <- fitdmm(dat=speed,dmm=mod,tdcov=1,der=0,ses=0,vfa=80,accu="best") Initial loglikelihood: -308.5948 iteration = 0 Step: [1] 0 0 0 0 0 0 0 0 Parameter: [1] 0.28501007 1.08501007 0.28318948 -0.01681052 5.51867043 0.19911769 [7] 6.39294268 0.23771005 Function Value [1] 308.3823 Gradient: [1] -60.1917191 -53.9865153 23.1694641 -92.0159912 1.9907909 -0.3677483 [7] 8.0979350 -16.5006371 iteration = 30 Parameter: [1] 0.448863468 0.897250757 -0.002860367 0.217008470 5.516357184 [6] 0.197571620 6.389501160 0.240874382 Function Value [1] 284.8562 Gradient: [1] 0.64226109 0.63952118 -0.65173268 1.91749987 -0.02252730 -0.01339433 [7] -0.01770095 -0.04406268 Successive iterates within tolerance. Current iterate is probably solution. Final loglikelihood: -284.8562 Computing posteriors This took 30 iterations, 4.82 seconds > summary(fit3) Model: twoboth+cov fitted at Wed Jul 13 13:09:55 2005 Optimization information, method is nlm Iterations: 30 Inform: 2 (look up the respective manuals for more information.) Loglikelihood of fitted model: -284.856 AIC: 585.712 BIC: 618.388 Number of observations (used in BIC): 439 Fitted model Model: twoboth+cov Number of parameters: 30 Free parameters: 8 Number of states: 2 Number of items: 2 Item types: normal 2 Parameter values, transition matrix State1 State2 State1 0.890 0.110 be -0.224 0.224 State2 0.110 0.890 be -0.110 0.110 Parameter values, observation parameters Item1,mean Item1,stddev Item2,p 1 Item2,p 2 State1 5.516 0.198 0.5 0.5 State2 6.390 0.241 0.1 0.9 Parameter values, initial state probabilies State1 State2 val 0 1 > > # split the data into three time series > data(speed) > r1=markovdata(dat=speed[1:168,],item=itemtypes(speed)) > r2=markovdata(dat=speed[169:302,],item=itemtypes(speed)) > r3=markovdata(dat=speed[303:439,],item=itemtypes(speed)) > > # define 2-state model with constraints > conpat=rep(1,15) > conpat[1]=0 > conpat[8:9]=0 > conpat[14:15]=0 > stv=c(1,0.9,0.1,0.1,0.9,5.5,0.2,0.5,0.5,6.4,0.25,0.9,0.1,0.5,0.5) > mod<-dmm(nstates=2,itemt=c("n",2),stval=stv,conpat=conpat) > > # define 3-group model with equal transition parameters, and no > # equalities between the obser parameters > mgr <-mgdmm(dmm=mod,ng=3,trans=TRUE,obser=FALSE) > > fitmg <- fitdmm(dat=list(r1,r2,r3),dmm=mgr) Warning in fitdmm(dat = list(r1, r2, r3), dmm = mgr) : No automatic boosting of starting values for other than single component 1-group models. Initial loglikelihood: -743.5488 iteration = 0 Step: [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Parameter: [1] 0.1532026 0.9583426 1.0209866 0.9365141 0.1365141 5.5000000 0.2000000 [8] 6.4000000 0.2500000 5.5000000 0.2000000 6.4000000 0.2500000 5.5000000 [15] 0.2000000 6.4000000 0.2500000 Function Value [1] 743.5488 Gradient: [1] 583.021983 462.223663 -72.639266 482.612681 -223.658416 -115.285567 [7] -87.991400 9.367967 -52.028775 -41.194328 105.587298 -14.198741 [13] 35.195885 68.106929 -33.575720 40.380799 98.678073 iteration = 31 Parameter: [1] -1.12753226 -0.01383641 1.12281943 -0.08249354 0.70259128 5.61586897 [7] 0.25903497 6.42474384 0.25415960 5.52577190 0.14899358 6.40779600 [13] 0.23795073 5.42239968 0.16687589 6.35547365 0.21439509 Function Value [1] 280.0264 Gradient: [1] 1.104459e-04 6.955622e-05 1.387325e-04 -8.760627e-05 1.539341e-04 [6] 8.336745e-06 -6.451362e-05 1.200573e-05 -3.745991e-04 -7.356309e-05 [11] 4.670044e-04 -1.418657e-05 1.377008e-04 -1.529984e-04 5.111825e-05 [16] 6.762901e-05 -2.060450e-04 Successive iterates within tolerance. Current iterate is probably solution. Final loglikelihood: -280.0264 Computing posteriors Computing standard errors Warning in computeSes(dat, mod) : Near-singular hessian, ses may be bad. This took 31 iterations, 5.88 seconds > summary(fitmg) Model: 3 group model fitted at Wed Jul 13 13:10:05 2005 Optimization information, method is nlm Iterations: 31 Inform: 2 (look up the respective manuals for more information.) Loglikelihood of fitted model: -280.026 AIC: 594.053 BIC: 663.489 Number of observations (used in BIC): 439 Fitted model Model: 3 group model Nr of groups: 3 Nr of parameters: 45 Free parameters: 17 Model for group: 1 Model: 2 -state model Number of parameters: 15 Free parameters: 7 Number of states: 2 Number of items: 2 Item types: normal 2 Parameter values, transition matrix State1 State2 State1 0.903 0.097 se 0.023 0.023 t 38.656 4.152 State2 0.084 0.916 se 0.018 0.018 t 4.601 50.377 Parameter values, observation parameters Item1,mean Item1,stddev Item2,p 1 Item2,p 2 State1 5.616 0.259 0.500 0.500 se 0.033 0.025 0.000 0.000 t 168.197 10.238 NA NA State2 6.425 0.254 0.058 0.942 se 0.029 0.020 0.027 0.027 t 220.433 12.544 2.123 34.539 Parameter values, initial state probabilies State1 State2 val 0.5 0.5 se 0.0 0.0 t NA NA Model for group: 2 Model: 2 -state model Number of parameters: 15 Free parameters: 7 Number of states: 2 Number of items: 2 Item types: normal 2 Parameter values, transition matrix State1 State2 State1 0.903 0.097 se 0.023 0.023 t 38.656 4.152 State2 0.084 0.916 se 0.018 0.018 t 4.601 50.377 Parameter values, observation parameters Item1,mean Item1,stddev Item2,p 1 Item2,p 2 State1 5.526 0.149 0.500 0.500 se 0.021 0.015 0.000 0.000 t 269.320 10.080 NA NA State2 6.408 0.238 0.100 0.900 se 0.027 0.019 0.034 0.034 t 238.862 12.502 2.981 26.689 Parameter values, initial state probabilies State1 State2 val 0.5 0.5 se 0.0 0.0 t NA NA Model for group: 3 Model: 2 -state model Number of parameters: 15 Free parameters: 7 Number of states: 2 Number of items: 2 Item types: normal 2 Parameter values, transition matrix State1 State2 State1 0.903 0.097 se 0.023 0.023 t 38.656 4.152 State2 0.084 0.916 se 0.018 0.018 t 4.601 50.377 Parameter values, observation parameters Item1,mean Item1,stddev Item2,p 1 Item2,p 2 State1 5.422 0.167 0.500 0.500 se 0.027 0.027 0.000 0.000 t 200.763 6.209 NA NA State2 6.355 0.214 0.107 0.893 se 0.025 0.018 0.034 0.034 t 259.249 12.221 3.164 26.282 Parameter values, initial state probabilies State1 State2 val 0.5 0.5 se 0.0 0.0 t NA NA > > # LEARNING DATA AND MODELS (with absorbing states) > > data(discrimination) > > # all or none model with error prob in the learned state > fixed = c(0,0,0,1,1,1,1,0,0,0,0) > stv = c(1,1,0,0.03,0.97,0.1,0.9,0.5,0.5,0,1) > allor <- dmm(nstates=2,itemtypes=2,fixed=fixed,stval=stv,modname="All-or-none") > > # Concept identification model: learning only after an error > st=c(1,1,0,0,0,0.5,0.5,0.5,0.25,0.25,0.05,0.95,0,1,1,0,0.25,0.375,0.375) > # fix some parameters > fx=rep(0,19) > fx[8:12]=1 > fx[17:19]=1 > # add a couple of constraints > conr1 <- rep(0,19) > conr1[9]=1 > conr1[10]=-1 > conr2 <- rep(0,19) > conr2[18]=1 > conr2[19]=-1 > conr3 <- rep(0,19) > conr3[8]=1 > conr3[17]=-2 > conr=c(conr1,conr2,conr3) > cim <- dmm(nstates=3,itemtypes=2,fixed=fx,conrows=conr,stval=st,modname="CIM") > > # define a mixture of the above models ... > mix <- mixdmm(dmm=list(allor,cim),modname="MixAllCim") > > # ... and fit it on the combined data discrimination > fitmix <- fitdmm(discrimination,mix) Warning in fitdmm(discrimination, mix) : No automatic boosting of starting values for other than single component 1-group models. Initial loglikelihood: -1678.963 iteration = 0 Step: [1] 0 0 0 0 0 Parameter: [1] -0.40215729 0.49784271 -0.67326675 -0.02781207 -0.56737159 Function Value [1] 1678.963 Gradient: [1] -221.7038 -354.8272 -588.4017 258.5217 -223.8521 iteration = 26 Parameter: [1] -0.37097952 0.56157750 -0.61673263 -0.02784283 -0.60113677 Function Value [1] 1656.162 Gradient: [1] 0.0003716630 -0.0006824727 -0.0001190787 0.0001874036 -0.0001628039 Relative gradient close to zero. Current iterate is probably solution. Final loglikelihood: -1656.162 Computing posteriors Computing standard errors This took 26 iterations, 60.34 seconds > summary(fitmix) Model: MixAllCim fitted at Wed Jul 13 13:11:29 2005 Optimization information, method is nlm Iterations: 26 Inform: 1 (look up the respective manuals for more information.) Loglikelihood of fitted model: -1656.162 AIC: 3322.324 BIC: 3352.582 Number of observations (used in BIC): 3139 Fitted model Model: MixAllCim Nr of components: 2 npars: 30 freepars: 5 Mixture proportions Comp 1 Comp 2 val 0.51063408 0.48936592 se 0.09852686 0.09852686 t 5.18268903 4.96682748 Component: 1 Model: All-or-none Number of parameters: 11 Free parameters: 2 Number of states: 2 Number of items: 1 Item types: 2 Parameter values, transition matrix State1 State2 State1 1.000 0.000 se 0.000 0.000 t NA NA State2 0.076 0.924 se 0.012 0.012 t 6.574 79.809 Parameter values, observation parameters Item1,p 1 Item1,p 2 State1 0.073 0.927 se 0.020 0.020 t 3.581 45.464 State2 0.500 0.500 se 0.000 0.000 t NA NA Parameter values, initial state probabilies State1 State2 val 0 1 se 0 0 t NA NA Component: 2 Model: CIM Number of parameters: 19 Free parameters: 2 Number of states: 3 Number of items: 1 Item types: 2 Parameter values, transition matrix State1 State2 State3 State1 1.000 0.000 0.000 se 0.000 0.000 0.000 t NA NA NA State2 0.000 0.500 0.500 se 0.000 0.000 0.000 t NA NA NA State3 0.539 0.230 0.230 se 0.098 0.049 0.049 t 5.500 4.698 4.698 Parameter values, observation parameters Item1,p 1 Item1,p 2 State1 0.034 0.966 se 0.014 0.014 t 2.474 70.882 State2 0.000 1.000 se 0.000 0.000 t NA NA State3 1.000 0.000 se 0.000 0.000 t NA NA Parameter values, initial state probabilies State1 State2 State3 val 0.270 0.365 0.365 se 0.049 0.025 0.025 t 5.500 14.896 14.896 > > > > > cleanEx(); ..nameEx <- "generate" > > ### * generate > > flush(stderr()); flush(stdout()) > > ### Name: generate > ### Title: Generate data from a dependent mixture model > ### Aliases: generate > ### Keywords: datagen > > ### ** Examples > > > # create a 2 state model with one continuous and one binary response > # with start values provided in st > st <- c(1,0.9,0.1,0.2,0.8,2,1,0.7,0.3,5,2,0.2,0.8,0.5,0.5) > mod <- dmm(nsta=2,itemt=c(1,2), stval=st) > > # generate two series of lengths 100 and 50 respectively using above model > gen<-generate(c(100,50),mod) > > summary(gen) Data set: 2 -item data nr of items: 2 item type(s): 1 2 item name(s): 1 2 length(s) of series: 100 50 nr of independent series: 2 data: 4.347533 1 ... > plot(gen) > > > > > cleanEx(); ..nameEx <- "markovdata" > > ### * markovdata > > flush(stderr()); flush(stdout()) > > ### Name: markovdata > ### Title: Specifying Markov data objects > ### Aliases: markovdata summary.md plot.md print.md plot.ts2 dname ntimes > ### itemtypes ncov inames nitems ind > ### Keywords: data > > ### ** Examples > > > x=rnorm(100,10,2) > y=ifelse(runif(100)<0.5,0,1) > z=matrix(c(x,y),100,2) > md=markovdata(z,itemtypes=c("cont","cat")) > summary(md) Data set: 2 -item data nr of items: 2 item type(s): continuous categorical item name(s): continuous categorical length(s) of series: 100 data: 8.747092 0 ... > md[1:10,] continuous categorical [1,] 8.747092 0 [2,] 10.367287 0 [3,] 8.328743 1 [4,] 13.190562 0 [5,] 10.659016 0 [6,] 8.359063 1 [7,] 10.974858 1 [8,] 11.476649 0 [9,] 11.151563 0 [10,] 9.389223 1 > > data(speed) > summary(speed) Data set: speed nr of items: 3 item type(s): continuous categorical covariate nr of covariates: 1 item name(s): rt corr Pacc length(s) of series: 168 134 137 nr of independent series: 3 data: 6.45677 1 0 ... > plot(speed,nind=2) > > # split the data into three data sets > # (to perform multi group analysis) > r1=markovdata(dat=speed[1:168,],item=itemtypes(speed)) > r2=markovdata(dat=speed[169:302,],item=itemtypes(speed)) > r3=markovdata(dat=speed[303:439,],item=itemtypes(speed)) > summary(r2) Data set: 3 -item data nr of items: 3 item type(s): continuous categorical covariate nr of covariates: 1 item name(s): rt corr Pacc length(s) of series: 134 data: 6.621406 1 0 ... > > > > > cleanEx(); ..nameEx <- "mgdmm" > > ### * mgdmm > > flush(stderr()); flush(stdout()) > > ### Name: mgdmm > ### Title: Multi group model specification > ### Aliases: mgdmm summary.mgd > ### Keywords: models > > ### ** Examples > > > # create a 2 state model with one continuous and one binary response > # with start values provided in st > st <- c(1,0.9,0.1,0.2,0.8,2,1,0.7,0.3,5,2,0.2,0.8,0.5,0.5) > mod <- dmm(nsta=2,itemt=c(1,2), stval=st) > > # define 3-group model with equal transition parameters, and no > # equalities between the obser parameters > mgr <- mgdmm(dmm=mod,ng=3,trans=TRUE,obser=FALSE) > summary(mgr) Model: 3 group model Nr of groups: 3 Nr of parameters: 45 Free parameters: 23 Model for group: 1 Model: 2 -state model Number of parameters: 15 Free parameters: 9 Number of states: 2 Number of items: 2 Item types: 1 2 Parameter values, transition matrix State1 State2 State1 0.9 0.1 State2 0.2 0.8 Parameter values, observation parameters Item1,mean Item1,stddev Item2,p 1 Item2,p 2 State1 2 1 0.7 0.3 State2 5 2 0.2 0.8 Parameter values, initial state probabilies State1 State2 val 0.5 0.5 Model for group: 2 Model: 2 -state model Number of parameters: 15 Free parameters: 9 Number of states: 2 Number of items: 2 Item types: 1 2 Parameter values, transition matrix State1 State2 State1 0.9 0.1 State2 0.2 0.8 Parameter values, observation parameters Item1,mean Item1,stddev Item2,p 1 Item2,p 2 State1 2 1 0.7 0.3 State2 5 2 0.2 0.8 Parameter values, initial state probabilies State1 State2 val 0.5 0.5 Model for group: 3 Model: 2 -state model Number of parameters: 15 Free parameters: 9 Number of states: 2 Number of items: 2 Item types: 1 2 Parameter values, transition matrix State1 State2 State1 0.9 0.1 State2 0.2 0.8 Parameter values, observation parameters Item1,mean Item1,stddev Item2,p 1 Item2,p 2 State1 2 1 0.7 0.3 State2 5 2 0.2 0.8 Parameter values, initial state probabilies State1 State2 val 0.5 0.5 > > > > > cleanEx(); ..nameEx <- "mixdmm" > > ### * mixdmm > > flush(stderr()); flush(stdout()) > > ### Name: mixdmm > ### Title: Mixture of dmm's specification > ### Aliases: mixdmm summary.mixdmm > ### Keywords: models > > ### ** Examples > > > # define component 1 > # all or none model with error prob in the learned state > fixed = c(0,0,0,1,1,1,1,0,0,0,0) > stv = c(1,1,0,0.07,0.93,0.9,0.1,0.5,0.5,0,1) > allor <- dmm(nstates=2,itemtypes=2,fixed=fixed,stval=stv,modname="All-or-none") > > # define component 2 > # Concept identification model: learning only after an error > st=c(1,1,0,0,0,0.5,0.5,0.5,0.25,0.25,0.8,0.2,1,0,0,1,0.25,0.375,0.375) > # fix some parameters > fx=rep(0,19) > fx[8:12]=1 > fx[17:19]=1 > # add a couple of constraints > conr1 <- rep(0,19) > conr1[9]=1 > conr1[10]=-1 > conr2 <- rep(0,19) > conr2[18]=1 > conr2[19]=-1 > conr3 <- rep(0,19) > conr3[8]=1 > conr3[17]=-2 > conr=c(conr1,conr2,conr3) > cim <- dmm(nstates=3,itemtypes=2,fixed=fx,conrows=conr,stval=st,modname="CIM") > > # define a mixture of the above component models > mix <- mixdmm(dmm=list(allor,cim),modname="MixAllCim") > summary(mix) Model: MixAllCim Nr of components: 2 npars: 30 freepars: 5 Mixture proportions [1] 0.5 0.5 Component: 1 Model: All-or-none Number of parameters: 11 Free parameters: 2 Number of states: 2 Number of items: 1 Item types: 2 Parameter values, transition matrix State1 State2 State1 1.00 0.00 State2 0.07 0.93 Parameter values, observation parameters Item1,p 1 Item1,p 2 State1 0.9 0.1 State2 0.5 0.5 Parameter values, initial state probabilies State1 State2 val 0 1 Component: 2 Model: CIM Number of parameters: 19 Free parameters: 2 Number of states: 3 Number of items: 1 Item types: 2 Parameter values, transition matrix State1 State2 State3 State1 1.0 0.00 0.00 State2 0.0 0.50 0.50 State3 0.5 0.25 0.25 Parameter values, observation parameters Item1,p 1 Item1,p 2 State1 0.8 0.2 State2 1.0 0.0 State3 0.0 1.0 Parameter values, initial state probabilies State1 State2 State3 val 0.25 0.375 0.375 > > > > > ### *