File: GREML_intercept_check.R

package info (click to toggle)
r-cran-openmx 2.21.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 14,412 kB
  • sloc: cpp: 36,577; ansic: 13,811; fortran: 2,001; sh: 1,440; python: 350; perl: 21; makefile: 5
file content (50 lines) | stat: -rw-r--r-- 1,741 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#
#   Copyright 2007-2019 by the individuals mentioned in the source code history
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
# 
#        http://www.apache.org/licenses/LICENSE-2.0
# 
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.


require(OpenMx)
require(mvtnorm)

set.seed(21204)
Sigma <- matrix(0.5,4,4)
diag(Sigma) <- 1
Dat <- rmvnorm(n=26,mean=rep(0,4),sigma=Sigma)
Dat <- matrix(t(Dat))
colnames(Dat) <- "y"
famid <- sort(rep(LETTERS,4))
CRM <- outer(famid,famid,"==") + 0
ge <- mxExpectationGREML(V="V", yvars="y")

Cmod <- mxModel(
	"GREMLtest",
	mxData(observed = Dat, type="raw", sort=FALSE),
	ge,
	mxFitFunctionGREML(),
	mxMatrix(type = "Diag", nrow = 104, ncol=104, free=T, values = 0.5, labels = "ve", 
					 lbound = 0.0001, name = "Ve"),
	mxMatrix(type="Full",nrow=1,ncol=1,free=T,values=0.5,labels="vc",name="Vc"),
	mxMatrix(type="Full",nrow=104,ncol=104,free=F,values=CRM,name="C",condenseSlots = T),
	mxAlgebra( (Vc%x%C) + Ve, name="V")
)
Crun <- mxRun(Cmod)
Csumm <- summary(Crun)

#Compare to lme4 REML results:
omxCheckCloseEnough(Csumm$GREMLfixeff$coeff[1],-0.01313328,1e-5)
omxCheckCloseEnough(Csumm$GREMLfixeff$se[1],0.1533185,1e-4)
omxCheckCloseEnough(Crun$output$estimate,c(0.3797,0.5162),1e-3)

#Intercept should equal grand mean:
omxCheckCloseEnough(Csumm$GREMLfixeff$coeff[1],mean(Dat),1e-12)