-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdefries-fulker.R
48 lines (42 loc) · 1.73 KB
/
defries-fulker.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
# roxygen2 documentation in AceUnivariate.R
DeFriesFulkerMethod1 <- function(dataSet, oName_S1, oName_S2, rName = "R") {
lmDetails <- stats::lm(
dataSet[, oName_S1] ~
1 +
dataSet[, oName_S2] +
dataSet[, rName] +
dataSet[, oName_S2] * dataSet[, rName]
)
brief <- base::summary(lmDetails)
coeficients <- stats::coef(brief)
nDouble <- base::length(brief$residuals)
# b0 <- coeficients["(Intercept)", "Estimate"]
b1 <- coeficients["dataSet[, oName_S2]", "Estimate"]
# b2 <- coeficients["R", "Estimate"]
b3 <- coeficients["dataSet[, oName_S2]:dataSet[, rName]", "Estimate"]
eSquared <- 1 - (b1 + b3)
details <- base::list(lm = lmDetails)
aceEstimate <- NlsyLinks::CreateAceEstimate(aSquared = b3, cSquared = b1, eSquared = eSquared, caseCount = nDouble, details = details)
return(aceEstimate)
}
# roxygen2 documentation in AceUnivariate.R
DeFriesFulkerMethod3 <- function(dataSet, oName_S1, oName_S2, rName = "R") {
dv_S1Centered <- base::scale(dataSet[, oName_S1], center = TRUE, scale = FALSE)
dv_S2Centered <- base::scale(dataSet[, oName_S2], center = TRUE, scale = FALSE)
interaction <- dv_S2Centered * dataSet[, rName]
lmDetails <- stats::lm(
dv_S1Centered ~
0 +
dv_S2Centered +
interaction
) # The '0' specifies and intercept-free model.
brief <- base::summary(lmDetails)
coeficients <- stats::coef(brief)
nDouble <- base::length(brief$residuals)
b1 <- coeficients["dv_S2Centered", "Estimate"]
b2 <- coeficients["interaction", "Estimate"]
eSquared <- 1 - (b1 + b2)
details <- base::list(lm = lmDetails)
aceEstimate <- NlsyLinks::CreateAceEstimate(aSquared = b2, cSquared = b1, eSquared = eSquared, caseCount = nDouble, details = details)
return(aceEstimate)
}