SCM

SCM Repository

[depmix] Diff of /trunk/depmixNew-test3.R
ViewVC logotype

Diff of /trunk/depmixNew-test3.R

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 98, Fri Mar 21 23:45:47 2008 UTC revision 99, Sun Mar 23 14:11:15 2008 UTC
# Line 14  Line 14 
14  library(depmixS4)  library(depmixS4)
15    
16  data(balance)  data(balance)
17    # four binary items on the balance scale task
18    
19  # now fit some latent class models  # now fit some latent class models
20  trstart=c(1,0,0,1)  trstart=c(1,0,0,1) # as this is a latent class model, the transition are not optimized
21  instart=c(0.5,0.5)  instart=c(0.5,0.5)
   
 # ntimes is added as an argument  
   
22  respstart=runif(16)  respstart=runif(16)
23    # note that ntimes argument is used to make this a mixture model
24  mod <- depmix(list(d1~1,d2~1,d3~1,d4~1), data=balance, nstates=2,  mod <- depmix(list(d1~1,d2~1,d3~1,d4~1), data=balance, nstates=2,
25          family=list(multinomial(),multinomial(),multinomial(),multinomial()),          family=list(multinomial(),multinomial(),multinomial(),multinomial()),
26          respstart=respstart,trstart=trstart,instart=instart,          respstart=respstart,trstart=trstart,instart=instart,
27          ntimes=rep(1,nrow(balance)))          ntimes=rep(1,nrow(balance)))
28    
29  pars <- getpars(mod)  mod1 <- fit(mod)
30  fixed <- c(1,0,1,1,1,1,rep(c(1,0),8))  
31    # add age as covariate on class membership by using the prior argument
32    trstart=c(1,0,0,1) # as this is a latent class model, the transition are not optimized
33    instart=c(0.5,0.5,0,0) # we need the initial probs and the coefficients of age
34    respstart=c(rep(c(0.1,0.9),4),rep(c(0.9,0.1),4))
35    trstart=c(1,0,0,1)
36    mod2 <- depmix(list(d1~1,d2~1,d3~1,d4~1), data=balance, nstates=2,
37            family=list(multinomial(),multinomial(),multinomial(),multinomial()),
38            trstart=trstart, instart=instart, respstart=respstart,
39            ntimes=rep(1,nrow(balance)), prior=~age, initdata=balance)
40    
41    mod3 <- fit(mod2)
42    
43    llratio(mod3,mod1)
44    
45    
46    
47    # donlp optimzation instead
48    
49    # mod4 <- fit(mod2,fixed=fixed,method="donlp")
50    
51    # profiling code
52    
53    
54    
55    
56  gc()  gc()
57  Rprof()  Rprof()
# Line 46  Line 69 
69  summaryRprof()  summaryRprof()
70    
71    
 mod1  
   
 setwd("/Users/ivisser/Documents/projects/depmixProject/depmixNew/rforge/depmix/trunk/")  
   
 source("R/depmix.fitted.R")  
 source("R/viterbi.R")  
   
   
 # 'log Lik.' -1083.036 (df=9)  
   
 #  
 # Add age as covariate on class membership  
 #  
   
 instart=c(0.5,0.5,0,0)  
 respstart=c(rep(c(0.1,0.9),4),rep(c(0.9,0.1),4))  
 trstart=c(1,0,0,1)  
 mod2 <- depmix(list(d1~1,d2~1,d3~1,d4~1), data=balance, nstates=2,  
         family=list(multinomial(),multinomial(),multinomial(),multinomial()),  
         trstart=trstart, instart=instart, respstart=respstart,  
         ntimes=rep(1,nrow(balance)), prior=~age, initdata=balance)  
   
 fixed <- c(1,0,1,0,1,1,1,1,rep(c(1,0),8))  
 mod3 <- fit(mod2,fixed=fixed)  
   
 llratio(mod3,mod1)  
   
   
 mod4 <- fit(mod2,fixed=fixed,method="donlp")  
   
   
72    
73    

Legend:
Removed from v.98  
changed lines
  Added in v.99

root@r-forge.r-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business Powered By FusionForge