mxFactor command

Dear all
I am trying to run a saturated model but there is something wrong in the way I have have ordered the variables, as I received this error message:
# Error: In model 'Sat' column 'dm1' is not an ordered factor. Use mxFactor() on this column.
So, I did the following after the reshape command:
TwDEP_DM <- reshape(DEP_DM, idvar = c("PAIRID", "ZYG"), timevar = "TVAB", direction = "wide")
colnames(TwDEP_DM) <- c('PAIRID', 'ZYG', 'dm1', 'dep1', 'age1','dm2', 'dep2', 'age2')
TwDEP_DM$dm1 <- mxFactor(TwDEP_DM$dm1, levels=c(0:2), ordered = TRUE)
TwDEP_DM$dep1 <- mxFactor(TwDEP_DM$dep1, levels=c(0:2), ordered = TRUE)
TwDEP_DM$dm2 <- mxFactor(TwDEP_DM$dm2, levels=c(0:2), ordered = TRUE)
TwDEP_DM$dep2 <- mxFactor(TwDEP_DM$dep2, levels=c(0:2), ordered = TRUE)
But:
> SatFit <- mxRun(SatModel, intervals=F)
Running Sat
# Error: In model 'Sat' I was expecting 1 thresholds in column 'dm1' of matrix/algebra 'MZ.expThresMZ' but I hit NA values after only 0 thresholds. You need to increase the number of free thresholds for 'dm1' and give them values other than NA
Is there anything I can do differently?
I think there is something in the mxFactor () as all of the "0" has been replaced as "1"; "1" with "2" ...
I have tried:
TwDEP_DM$dm1 <- mxFactor(TwDEP_DM$dm1, levels=c(0:2), exclude NA, ordered = TRUE)
TwDEP_DM$dm1 <- mxFactor(TwDEP_DM$dm1, levels=c(0:2), labels (2, NA), ordered = TRUE)
Any help will be much appreciated.
Kind regards
Carol
I think it's a problem with your model-expected thresholds
After
mxFactor()
, try enteringTwDEP_DM$dm1[1:10]
into the R console. Do you see zeroes andNA
s, or ones andNA
s?I don't think it's a problem with
mxFactor()
, though. The more important question is, what are the initial values of your model's expected thresholds? The second error message you included in your post suggests that they are somehow started atNA
, and if that's the case, OpenMx won't be able to do anything with them. Another possibility is that the number of thresholds is too small for the number of levels in the ordinal variables.BTW, the reason you got the second error after using
mxFactor()
isn't becausemxFactor()
caused the second error. Instead,mxFactor()
enabled your variables to pass the check of being ordinal variables where necessary, but your model then fails a subsequent check because of the problem with the thresholds. At least, this is what I think is happening; without seeing your syntax, I can't be completely sure.Log in or register to post comments
In reply to I think it's a problem with your model-expected thresholds by RobK
Thank you. This is what I got
Thank you.
This is what I got from TwDEP_DM$dm1[1:10] 0 0 0 0
[1] 0 0
Levels: 0 < 1
The data looks like this. It is a twin dataset, so there are a lot of missing twin with all missing variables.
PAIRID ZYG dm1 dep1 age1 dm2 dep2 age2
1 21 1 0 0 73 0 0 73
2 22 4 0 0 74 NA NA NA
3 23 2 NA NA NA 0 1 73
4 24 2 0 1 74 0 0 74
5 26 4 NA NA NA 0 0 74
6 29 1 0 0 74 0 0 74
7 31 4 NA NA NA 0 0 NA
8 33 4 0 0 NA 0 0 NA
9 34 4 NA NA NA 0 0 NA
10 35 1 0 0 NA 0 0 NA
Kind regards
Carol
Log in or register to post comments
In reply to Thank you. This is what I got by CarolKan
No problem with mxFactor
There is no problem with mxFactor here. There is just some confusion about how R represents factors.
> require(OpenMx)
>
> set.seed(46) # Make repeatable
>
> data <- data.frame(x1=sample(0:2, 50, replace=TRUE))
> data$x2 <- data$x1+1
>
> data[1:10,]
x1 x2
1 0 1
2 0 1
3 1 2
4 1 2
5 0 1
6 1 2
7 2 3
8 1 2
9 2 3
10 2 3
>
> data$x1F <- mxFactor(data$x1, levels=0:2)
> data$x2F <- mxFactor(data$x2, levels=1:3)
> data[1:10,]
x1 x2 x1F x2F
1 0 1 0 1
2 0 1 0 1
3 1 2 1 2
4 1 2 1 2
5 0 1 0 1
6 1 2 1 2
7 2 3 2 3
8 1 2 1 2
9 2 3 2 3
10 2 3 2 3
> str(data)
'data.frame': 50 obs. of 4 variables:
$ x1 : int 0 0 1 1 0 1 2 1 2 2 ...
$ x2 : num 1 1 2 2 1 2 3 2 3 3 ...
$ x1F: Ord.factor w/ 3 levels "0"<"1"<"2": 1 1 2 2 1 2 3 2 3 3 ...
..- attr(*, "mxFactor")= logi TRUE
$ x2F: Ord.factor w/ 3 levels "1"<"2"<"3": 1 1 2 2 1 2 3 2 3 3 ...
..- attr(*, "mxFactor")= logi TRUE
I create two variables. The first has values of 0, 1, and 2. The second variable is identical to the first plus 1. I then apply mxFactor to both variables. Notice that when I just look at the data, the mxFactor'ed variables are still printed like their non-mxFactor'ed relatives. However, when I look at str(data) you can see the underlying representation of factors in R. The 1 1 2 2 1 2 3 2 3 3 refers to which level of the factor occurs, not the value of the level. So, levels 1 1 2 2 1 2 ... refers to the values "0" "0" "1" "1" "0" "1" in x1F, but it refers to "1" "1" "2" "2" "1" "2" in x2F.
Does that help to clarify the situation?
Log in or register to post comments
In reply to Thank you. This is what I got by CarolKan
Did you ever resolve this issue?
Hi there,
Did you ever figure out the issue with your script?
I am getting a similar error message (although it doesn't happen until my third group: "Error: In model 'Sat' I was expecting 1 thresholds in column 'nssi1' of matrix/algebra 'DZf.expThresDZf' but I hit NA values after only 0 thresholds. You need to increase the number of thresholds for 'nssi1' and give them values other than NA").
My factors appear to be set up correctly (I found everyone's comments to be very helpful!) and the threshold start value seems fine...
I would love to know what you figured out! Thanks, Brooke
Log in or register to post comments
what is in MxModel?
OpenMx is saying that the thresholds matrix is set for zero thresholds for variable dm1.
But as Rob said, with just
SatFit <- mxRun(SatModel)
It's hard to say why... need to see the rest of what is in SatModel, in particular how you are setting the mxFIMLObjective and what matrix you are passing the thresholds argument to this function.
Log in or register to post comments