On 12-Jul-07 23:47:39, Masanao Yajima wrote:> Dear Professor Schaefer
>
> I am experiencing a technical difficulty with your mix package.
> I would appreciate it if you could help me with this problem.
>
> When I run the following code, R 2.5.1 and R 2.6.0 crashes.
> It's been tested on at least 2 windows machine and it is consistent.
> Execution code it's self was coped from the help file of imp.mix.
> Only thing I supplied was a fake dataset.
>
There are several things wrong with your approach to this.
1. The mix package is for imputation when the data consist
of variables of two kinds: one or more continuous variables
(which will be modelled as normally distributed); and one
or more discrete (categorical) variables. The levels of
the latter must be represented in the data as conscutive
integers starting at 1. In your data, all the variables
have been generated as normally distributed, and hence
not integers, except for x4 which has been converted to
integer from a Normal sample using floor(). However, this
generates negative integers, which are not acceptable to
the mix package as levels of categorical variables.
2. The categorical variables must be the first columns in the
data matrix. Your construction has made x4 (the only
possible candidate) the last column; in any case your
first 5 columns are continuous variables.
3. The data presented to mix must be a matrix, not a dataframe.
4. You invoke prelim.mix as prelim.mix(dat,3), which makes it
treat the first 3 columns as the categorical variables,
which they are not.
It is your "fake dataset" which is causing the trouble.
All the points above are covered in the documentation for
the functions in the mix package.
Hoping this helps,
Ted.
>################################################################
> library(mix)
> n <-100
> x1<-rnorm(n)
> x2<-rnorm(n,2,1.2)
> x3<-rnorm(n,1,2)
> x4<-floor(rnorm(n)*3)
> y <-rnorm(n,1*x1+2*x2+3*x3+4*x4,2)
> w <-rnorm(n,3,1.2)
> ymis<-y
> ymis[floor(runif(10,1,n))]<-NA
> wmis<-w
> wmis[floor(runif(10,1,n))]<-NA
> dat<-as.data.frame(cbind(wmis,ymis,x1,x2,x3,x4))
> s <- prelim.mix(dat,3) # do preliminary manipulations
> thetahat <- em.mix(s) # ML estimate for unrestricted model
> rngseed(1234567) # set random number generator seed
> newtheta <- da.mix(s,thetahat,steps=100) # data augmentation
> ximp <- imp.mix(s, newtheta, dat) # impute under newtheta
>################################################################
>
> Your mix package is important part of our ongoing research on the
> missing data project and we would like to have it working.
> If you could point out to me what I am doing wrong or
> some technical difficulty that I am not aware of it will be highly
> appreciated.
>
> Thank you for your help in advance.
>
> Sincerely
>
> Masanao Yajima
> my2167 at columbia.edu
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <ted.harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 13-Jul-07 Time: 09:50:52
------------------------------ XFMail ------------------------------
--------------------------------------------------------------------
E-Mail: (Ted Harding) <ted.harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 13-Jul-07 Time: 10:11:39
------------------------------ XFMail ------------------------------