File: semCors.R

package info (click to toggle)
r-cran-semplot 1.1.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 464 kB
  • sloc: makefile: 2
file content (73 lines) | stat: -rw-r--r-- 2,417 bytes parent folder | download | duplicates (4)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
semCors <- function(object,include,vertical=TRUE,titles=FALSE,layout,maximum,...){
  if (!"semPlotModel"%in%class(object)) object <- semPlotModel(object) 
  
  if (!object@Computed) stop("SEM model has not been evaluated; there are no implied covariances")
  
  if (missing(layout)) layout <- NULL
  
  Ng <- max(sapply(list(object@ObsCovs,object@ImpCovs),length))
  if (missing(include))
  {
    include <- c("observed","expected")[c(length(object@ObsCovs)==Ng,length(object@ImpCovs)==Ng)]
  }
  Groups <- unique(object@Pars$group)
  
  l <- matrix(1:(Ng*length(include)),length(include),)
  if (vertical) layout(t(l)) else layout(l)
  
  Res <- list()
  
  for (g in 1:Ng)
  {
    Res[[g]] <- list()
    
    if (any(grepl("obs",include,ignore.case=TRUE)))
    {
      Res[[g]]$Observed <- qgraph(round(cov2cor(object@ObsCovs[[g]]),5),maximum=ifelse(missing(maximum),1,maximum),layout=layout,...)
      layout <- Res[[g]]$Observed$layout
      if (titles) 
      {
        if (Ng > 1)
        {
          text(mean(par('usr')[1:2]),par("usr")[4],paste("Group",Groups[g],"(observed)"), adj = c(0.5,1))
        } else {
          text(mean(par('usr')[1:2]),par("usr")[4],"Observed", adj = c(0.5,1))
        }
      }
    }
    
    if (any(grepl("exp",include,ignore.case=TRUE)) | any(grepl("imp",include,ignore.case=TRUE)))
    {
      Res[[g]]$Implied <- qgraph(round(cov2cor(object@ImpCovs[[g]]),5),maximum=ifelse(missing(maximum),1,maximum),layout=layout,...)
      layout <- Res[[g]]$Implied$layout
      if (titles) 
      {
        if (Ng > 1)
        {
          text(mean(par('usr')[1:2]),par("usr")[4],paste("Group",Groups[g],"(implied)"), adj = c(0.5,1))
        } else {
          text(mean(par('usr')[1:2]),par("usr")[4],"Implied", adj = c(0.5,1))
        }
      }
    }
    
    
    if (any(grepl("dif",include,ignore.case=TRUE)) | any(grepl("res",include,ignore.case=TRUE)))
    {
      Res[[g]]$Difference <- qgraph(round(cov2cor(object@ObsCovs[[g]]) - cov2cor(object@ImpCovs[[g]]),5),maximum=ifelse(missing(maximum),.1,maximum),layout=layout,diag = TRUE, ...)
      if (titles) 
      {
        if (Ng > 1)
        {
          text(mean(par('usr')[1:2]),par("usr")[4],paste("Group",Groups[g],"(observed - implied)"), adj = c(0.5,1))
        } else {
          text(mean(par('usr')[1:2]),par("usr")[4],"Observed - Implied", adj = c(0.5,1))
        }
      }
    }
    
    
  }
  
  invisible(Res)
}