File: effects.R

package info (click to toggle)
r-cran-sem 3.1.16-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 936 kB
  • sloc: ansic: 2,241; cpp: 1,646; sh: 4; makefile: 2
file content (31 lines) | stat: -rw-r--r-- 925 bytes parent folder | download | duplicates (5)
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
# added 2011-11-04 by J. Fox

effects.sem <- function(object, ...) {
	A <- object$A
	m <- object$m
	I <- diag(m)
	endog <- classifyVariables(object$semmod)$endogenous  
	AA <- - A
	diag(AA) <- 1
	Total <- solve(AA) - I
	Indirect <-  Total - A
	result <- list(Total=Total[endog, ], Direct=A[endog, ], Indirect=Indirect[endog, ])
	class(result) <- "semeffects"
	result
}

print.semeffects <- function(x, digits=getOption("digits"), ...){
	cat("\n Total Effects (column on row)\n")
	Total <- x$Total
	Direct <- x$Direct
	Indirect <- x$Indirect
	select <- !(apply(Total, 2, function(x) all( x == 0)) & 
				apply(Direct, 2, function(x) all( x == 0)) & 
				apply(Indirect, 2, function(x) all( x == 0)))
	print(Total[, select], digits=digits)
	cat("\n Direct Effects\n")
	print(Direct[, select], digits=digits)
	cat("\n Indirect Effects\n")
	print(Indirect[, select], digits=digits)
	invisible(x)
}