# Inflated degrees of freedom

7 posts / 0 new
Offline
Joined: 08/23/2009 - 21:06
Inflated degrees of freedom

When I run the following model, the program is telling me that I have 7405 degrees of freedom when there should only be around 370. I'm just wondering if anyone can offer any insight into what could be causing this discrepancy? Here's the code I'm running:

library(OpenMx)

MissDataModel3<-mxModel("Missing Data Simulation Structural Model with Phantom Constructs",
type="RAM",
mxData(MissDataSim2,
type="raw"
),

manifestVars=c("a1","a2","a3","a4","a5","a6","a7","a8","a9","a10",
"b1","b2","b3","b4","b5","b6","b7","b8","b9","b10",
"c1","c2","c3","c4","c5","c6","c7","c8","c9","c10"),

latentVars=c("FA","FB","FC","PA","PB","PC"),

# residual variances
mxPath(from=c("a1","a2","a3","a4","a5","a6","a7","a8","a9","a10",
"b1","b2","b3","b4","b5","b6","b7","b8","b9","b10",
"c1","c2","c3","c4","c5","c6","c7","c8","c9","c10"),
arrows=2,
free=TRUE,
values=c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
labels=c("e1","e2","e3","e4","e5","e6","e7","e8","e9","e10",
"e11","e12","e13","e14","e15","e16","e17","e18","e19","e20",
"e21","e22","e23","e24","e25","e26","e27","e28","e29","e30")
),

# latent variances and covariance
mxPath(from=c("FA","FB","FC"),
arrows=2,
all=2,
free=c(FALSE,FALSE,FALSE,
FALSE,FALSE,FALSE,
FALSE,FALSE,FALSE),
values=c(0,0,0,
0,0,0,
0,0,0),
labels=c("varFA","covAB","covAC",
"covBA","varFB","covBC",
"covCA","covCB","varFC")
),

# phantom variances and covariance
mxPath(from=c("PA","PB","PC"),
arrows=2,
all=2,
free=c(FALSE,FALSE,FALSE,
FALSE,FALSE,FALSE,
FALSE,FALSE,FALSE),
values=c(1,0,0,
0,1,0,
0,0,1),
labels=c("varPA","covPAB","covPAC",
"covPBA","varPB","covPBC",
"covPCA","covPCB","varPC")
),

mxPath(from="FA",
to=c("a1","a2","a3","a4","a5","a6","a7","a8","a9","a10"),
arrows=1,
free=c(TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE),
values=c(1,1,1,1,1,1,1,1,1,1),
labels=c("l1","l2","l3","l4","l5","l6","l7","l8","l9","l10")
),

#Effects Coding

mxMatrix(type = "Full", nrow = 1, ncol = 1,
free = TRUE, values = 1, labels = "l1", name = "la"),
mxMatrix(type = "Full", nrow = 1, ncol = 1,
free = TRUE, values = 1, labels = "l2", name = "lb"),
mxMatrix(type = "Full", nrow = 1, ncol = 1,
free = TRUE, values = 1, labels = "l3", name = "lc"),
mxMatrix(type = "Full", nrow = 1, ncol = 1,
free = TRUE, values = 1, labels = "l4", name = "ld"),
mxMatrix(type = "Full", nrow = 1, ncol = 1,
free = TRUE, values = 1, labels = "l5", name = "le"),
mxMatrix(type = "Full", nrow = 1, ncol = 1,
free = TRUE, values = 1, labels = "l6", name = "lf"),
mxMatrix(type = "Full", nrow = 1, ncol = 1,
free = TRUE, values = 1, labels = "l7", name = "lg"),
mxMatrix(type = "Full", nrow = 1, ncol = 1,
free = TRUE, values = 1, labels = "l8", name = "lh"),
mxMatrix(type = "Full", nrow = 1, ncol = 1,
free = TRUE, values = 1, labels = "l9", name = "li"),
mxMatrix(type = "Full", nrow = 1, ncol = 1,
free = TRUE, values = 1, labels = "l10", name = "lj"),
mxMatrix(type = "Full", nrow = 1, ncol = 1,
free = FALSE, values = 10, labels = "con", name = "cona"),

mxAlgebra(name="sa",
la+lb+lc+ld+le+lf+lg+lh+li+lj
),
mxConstraint("sa","=","cona"),

mxPath(from="FB",
to=c("b1","b2","b3","b4","b5","b6","b7","b8","b9","b10"),
arrows=1,
free=c(TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE),
values=c(1,1,1,1,1,1,1,1,1,1),
labels=c("l11","l12","l13","l14","l15","l16","l17","l18","l19","l20")
),

#Effects Coding

mxMatrix(type = "Full", nrow = 1, ncol = 1,
free = TRUE, values = 1, labels = "l11", name = "lba"),
mxMatrix(type = "Full", nrow = 1, ncol = 1,
free = TRUE, values = 1, labels = "l12", name = "lbb"),
mxMatrix(type = "Full", nrow = 1, ncol = 1,
free = TRUE, values = 1, labels = "l13", name = "lbc"),
mxMatrix(type = "Full", nrow = 1, ncol = 1,
free = TRUE, values = 1, labels = "l14", name = "lbd"),
mxMatrix(type = "Full", nrow = 1, ncol = 1,
free = TRUE, values = 1, labels = "l15", name = "lbe"),
mxMatrix(type = "Full", nrow = 1, ncol = 1,
free = TRUE, values = 1, labels = "l16", name = "lbf"),
mxMatrix(type = "Full", nrow = 1, ncol = 1,
free = TRUE, values = 1, labels = "l17", name = "lbg"),
mxMatrix(type = "Full", nrow = 1, ncol = 1,
free = TRUE, values = 1, labels = "l18", name = "lbh"),
mxMatrix(type = "Full", nrow = 1, ncol = 1,
free = TRUE, values = 1, labels = "l19", name = "lbi"),
mxMatrix(type = "Full", nrow = 1, ncol = 1,
free = TRUE, values = 1, labels = "l20", name = "lbj"),
mxMatrix(type = "Full", nrow = 1, ncol = 1,
free = FALSE, values = 10, labels = "cons", name = "conb"),

mxAlgebra(name="sb",
lba+lbb+lbc+lbd+lbe+lbf+lbg+lbh+lbi+lbj
),
mxConstraint("sb","=","conb"),

mxPath(from="FC",
to=c("c1","c2","c3","c4","c5","c6","c7","c8","c9","c10"),
arrows=1,
free=c(TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE),
values=c(1,1,1,1,1,1,1,1,1,1),
labels=c("l21","l22","l23","l24","l25","l26","l27","l28","l29","l30")
),

#Effects Coding

mxMatrix(type = "Full", nrow = 1, ncol = 1,
free = TRUE, values = 1, labels = "l21", name = "lca"),
mxMatrix(type = "Full", nrow = 1, ncol = 1,
free = TRUE, values = 1, labels = "l22", name = "lcb"),
mxMatrix(type = "Full", nrow = 1, ncol = 1,
free = TRUE, values = 1, labels = "l23", name = "lcc"),
mxMatrix(type = "Full", nrow = 1, ncol = 1,
free = TRUE, values = 1, labels = "l24", name = "lcd"),
mxMatrix(type = "Full", nrow = 1, ncol = 1,
free = TRUE, values = 1, labels = "l25", name = "lce"),
mxMatrix(type = "Full", nrow = 1, ncol = 1,
free = TRUE, values = 1, labels = "l26", name = "lcf"),
mxMatrix(type = "Full", nrow = 1, ncol = 1,
free = TRUE, values = 1, labels = "l27", name = "lcg"),
mxMatrix(type = "Full", nrow = 1, ncol = 1,
free = TRUE, values = 1, labels = "l28", name = "lch"),
mxMatrix(type = "Full", nrow = 1, ncol = 1,
free = TRUE, values = 1, labels = "l29", name = "lci"),
mxMatrix(type = "Full", nrow = 1, ncol = 1,
free = TRUE, values = 1, labels = "l30", name = "lcj"),
mxMatrix(type = "Full", nrow = 1, ncol = 1,
free = FALSE, values = 10, labels = "const", name = "conc"),

mxAlgebra(name="sc",
lca+lcb+lcc+lcd+lce+lcf+lcg+lch+lci+lcj
),
mxConstraint("sc","=","conc"),

mxPath(from="PA",
to="FA",
arrows=1,
free=TRUE,
values=1,
labels="b1"
),

mxPath(from="PB",
to="FB",
arrows=1,
free=TRUE,
values=1,
labels="b2"
),

mxPath(from="PC",
to="FC",
arrows=1,
free=TRUE,
values=1,
labels="b3"
),

mxPath(from="PA",
to="PB",
arrows=1,
free=TRUE,
values=1,
labels="bp1"
),

mxPath(from="PB",
to="PC",
arrows=1,
free=TRUE,
values=1,
labels="bp2"
),

mxPath(from="one",
to=c("a1","a2","a3","a4","a5","a6","a7","a8","a9","a10",
"b1","b2","b3","b4","b5","b6","b7","b8","b9","b10",
"c1","c2","c3","c4","c5","c6","c7","c8","c9","c10",
"FA","FB","FC","PA","PB","PC"),
arrows=1,
free=c(TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,
TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,
TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,
FALSE,FALSE,FALSE,FALSE,FALSE,FALSE),
values=c(1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,
0,0,0,0,0,0),
labels=c("meana1","meana2","meana3","meana4","meana5",
"meana6","meana7","meana8","meana9","meana10",
"meanb1","meanb2","meanb3","meanb4","meanb5",
"meanb6","meanb7","meanb8","meanb9","meanb10",
"meanc1","meanc2","meanc3","meanc4","meanc5",
"meanc6","meanc7","meanc8","meanc9","meanc10",
NA,NA,NA,NA,NA,NA)
)


)

MissDataPhantom2Fit <- mxRun(MissDataModel3)

MissDataPhantom2Fit@output

summary(MissDataPhantom2Fit)

And here's the pertinent output that results:

Observed statistics: 7500
Estimated parameters: 95
Degrees of freedom: 7405
-2 log likelihood: 20470.93
Saturated -2 log likelihood:
Chi-Square:
p:
AIC (Mx): 5660.932
BIC (Mx): -10207.74
RMSEA: 0

Offline
Joined: 07/31/2009 - 14:25
You have "all=2" in a call to

You have "all=2" in a call to mxPath

That should have been checked and produced an error.

Valid settings are:

all=(TRUE|FALSE)

Offline
Joined: 07/31/2009 - 14:25
Also, a useful tip for

Also, a useful tip for writing unwieldy long parameter values like
values=c( "e1","e2","e3","e4","e5","e6","e7","e8","e9","e10" "e11" "e12" "e13" "e14" "e15" "e16" "e17" "e18" "e19" "e20" "e21" "e22" "e23" "e24" "e25" "e26" "e27" "e28","e29", "e30")

this is equivalent and much more maintainable

values= paste("e", 1:30, sep="")

it says "glue these things together using the separator I give you. Oh, and if you see an array, make an array of glued-together things"

Offline
Joined: 08/23/2009 - 21:06
Thanks for the help, but

Thanks for the help, but there's something else going on as well. I tried removing those commands and changing them to all=FALSE, but both solutions ended up with the same 7405 degrees of freedom.

Is there anything else you can see in there?

P.S. I apologize for posting such a long script; I'm in the process of streamlining it, but the new and improved version isn't running yet.

Offline
Joined: 07/31/2009 - 15:24

Please use the "attach a file" option to post your R script for next time. That would be more helpful in cases when the script is longer than a handful of lines. Thanks!

Offline
Joined: 07/31/2009 - 15:24
Do you have a sense for which

Do you have a sense for which is incorrect: the number of observed statistics, or the number of estimated parameters, or both?

Observed statistics: 7500
Estimated parameters: 95

Offline
Joined: 07/30/2009 - 14:03
So, you have 30 variables.

So, you have 30 variables. How many lines in your data set? I'm guessing 250. Which would give you 7500 observed statistics.

By what calculation are you arriving at 370?