forked from metrumresearchgroup/metrumrg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathomegacor.R
55 lines (53 loc) · 1.76 KB
/
omegacor.R
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
51
52
53
54
unilogcov <- function(
pattern,
run=0,
project=getwd(),
tool='nm7',
extfile=file.path(project,run,paste(run,'ext',sep='.')),
pxml=as.pxml.ext(extfile),
unilog=as.unilog.pxml(x=pxml,run=run,tool=tool,...),
...
){
#ord.ceiling <- function(n)ceiling(sqrt(0.25+2*n)-0.5)
startpattern <- glue('^',pattern)
unilog <- unilog[with(unilog,contains(startpattern,parameter) & moment=='estimate'),]
if(nrow(unilog)==0)stop('no estimates found for unilog parameters with pattern',startpattern)
if(length(unique(unilog$run))!=1)stop('need exactly one unique value of run')
unilog$value <- suppressWarnings(as.numeric(as.character(unilog$value)))
unilog <- data.frame(cast(unilog,parameter~moment))
indices <- as.character(text2decimal(as.character(unilog$parameter)))
splits <- strsplit(indices,'.',fixed=TRUE)
all <- unlist(splits)
ord <- max(as.numeric(all))
nms <- names(half(diag(ord)))
nms <- glue(pattern,nms)
val <- with(unilog, estimate[match(nms,parameter)])
cov <- as.matrix(as.halfmatrix(val))
cov
}
unilogcor <- function(
pattern,
run=0,
project=getwd(),
tool='nm7',
extfile=file.path(project,run,paste(run,'ext',sep='.')),
pxml=as.pxml.ext(extfile),
unilog=as.unilog.pxml(x=pxml,run=run,tool=tool,...),
...
){
cov <- unilogcov(
pattern=pattern,
run=run,
project=project,
tool=tool,
extfile=extfile,
pxml=pxml,
unilog=unilog,
...
)
cov2cor(cov)
}
omegacov <- function(run,project=getwd(),...)unilogcov(pattern='OMEGA',run=run,project=project,...)
sigmacov <- function(run,project=getwd(),...)unilogcov(pattern='SIGMA',run=run,project=project,...)
omegacor <- function(run,project=getwd(),...)unilogcor(pattern='OMEGA',run=run,project=project,...)
sigmacor <- function(run,project=getwd(),...)unilogcor(pattern='SIGMA',run=run,project=project,...)