Skip to content

Commit fedb071

Browse files
soumyarayNicholasDanks
authored andcommitted
Basic fSquared function for effect size of iv on dv (#123)
1 parent b236fbb commit fedb071

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

R/evaluate_effects.R

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#' seminr fSquared Function
2+
#'
3+
#' The \code{fSquared} function calculates f^2 effect size for a given IV and DV
4+
#'
5+
#' @param seminr_model A \code{seminr_model} containing the estimated seminr model.
6+
#' @param iv An independent variable in the model.
7+
#' @param dv A dependent variable in the model.
8+
#'
9+
#' @usage
10+
#' fsquared(model, iv, dv)
11+
#'
12+
#' @references Cohen, J. (2013). Statistical power analysis for the behavioral sciences. Routledge.
13+
#'
14+
#' @examples
15+
#' mobi_mm <- constructs(
16+
#' reflective("Image", multi_items("IMAG", 1:5)),
17+
#' reflective("Expectation", multi_items("CUEX", 1:3)),
18+
#' reflective("Quality", multi_items("PERQ", 1:7)),
19+
#' reflective("Value", multi_items("PERV", 1:2)),
20+
#' reflective("Satisfaction", multi_items("CUSA", 1:3)),
21+
#' reflective("Complaints", single_item("CUSCO")),
22+
#' reflective("Loyalty", multi_items("CUSL", 1:3))
23+
#' )
24+
#'
25+
#' mobi_sm <- relationships(
26+
#' paths(from = "Image", to = c("Expectation", "Satisfaction", "Loyalty")),
27+
#' paths(from = "Expectation", to = c("Quality", "Value", "Satisfaction")),
28+
#' paths(from = "Quality", to = c("Value", "Satisfaction")),
29+
#' paths(from = "Value", to = c("Satisfaction")),
30+
#' paths(from = "Satisfaction", to = c("Complaints", "Loyalty")),
31+
#' paths(from = "Complaints", to = "Loyalty")
32+
#' )
33+
#'
34+
#' mobi_pls <- estimate_pls(data = mobi,
35+
#' measurement_model = mobi_mm,
36+
#' structural_model = mobi_sm)
37+
#'
38+
#' fSquared(mobi_pls, "Image", "Satisfaction")
39+
#' @export
40+
# fSquared as per Cohen (2013)
41+
42+
fSquared <- function(seminr_model, iv, dv) {
43+
with_sm <- seminr_model$smMatrix
44+
without_sm <- subset(with_sm, !((with_sm[, "source"] == iv) & (with_sm[, "target"] == dv)))
45+
capture.output(
46+
without_pls <- estimate_pls(data = seminr_model$data,
47+
measurement_model = seminr_model$mmMatrix,
48+
structural_model = without_sm)
49+
)
50+
51+
with_r2 <- seminr_model$rSquared["Rsq", dv]
52+
without_r2 <- without_pls$rSquared["Rsq", dv]
53+
54+
(with_r2 - without_r2) / (1 - with_r2)
55+
}

0 commit comments

Comments
 (0)