Skip to contents

TODO: Allow embedding L_tau(A) and L(A) in addition to A

Usage

netmediate(graph, formula, rank, coembedding = c("U", "V", "Z", "Y"))

Arguments

graph

A tidygraph::tbl_graph() object.

formula

Details about the nodal design matrix. Of the form outcome ~ nodal_formula. For now, no interactions or fancy stuff are allowed in the formula.

rank

Integer describing desired rank of embedding dimension.

coembedding

TODO

Value

A network_mediation object.

Examples


library(tidygraph)
#> 
#> Attaching package: ‘tidygraph’
#> The following object is masked from ‘package:stats’:
#> 
#>     filter

data(smoking)

smokeint <- smoking |>
  mutate(
    smokes_int = as.integer(smokes) - 1
  )

netmed <- smokeint |>
  netmediate(smokes_int ~ sex, rank = 7)

netmed
#> A network mediation object
#> ------------------------
#> 
#> Outcome model:
#> --------------
#> 
#> Call:
#> stats::lm(formula = y ~ W + X + 0)
#> 
#> Residuals:
#>      Min       1Q   Median       3Q      Max 
#> -0.85098 -0.19972 -0.01797  0.15513  0.87135 
#> 
#> Coefficients:
#>              Estimate Std. Error t value Pr(>|t|)    
#> W(Intercept)  0.14519    0.12436   1.168 0.244798    
#> Wsexmale      0.22585    0.09499   2.378 0.018663 *  
#> X1            0.08570    0.23583   0.363 0.716813    
#> X2            0.08491    0.08525   0.996 0.320815    
#> X3           -0.01819    0.08608  -0.211 0.832902    
#> X4           -0.06179    0.08229  -0.751 0.453845    
#> X5            0.28977    0.08585   3.375 0.000935 ***
#> X6            0.28659    0.10694   2.680 0.008170 ** 
#> X7            0.42534    0.20348   2.090 0.038236 *  
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> 
#> Residual standard error: 0.3622 on 153 degrees of freedom
#> Multiple R-squared:  0.5332,	Adjusted R-squared:  0.5057 
#> F-statistic: 19.42 on 9 and 153 DF,  p-value: < 2.2e-16
#> 
#> Mediator model:
#> ---------------
#> 
#> Analysis of Variance Table
#> 
#>            Df Pillai approx F num Df den Df    Pr(>F)    
#> W           2 1.5746   81.967     14    310 < 2.2e-16 ***
#> Residuals 160                                            
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> 
#> Estimated direct and indirect effects:
#> ---------------------------------------
#> 
#> # A tibble: 2 × 5
#>   term    estimand estimate conf.low conf.high
#>   <chr>   <chr>       <dbl>    <dbl>     <dbl>
#> 1 sexmale nde         0.226   0.0382     0.414
#> 2 sexmale nie         0.246   0.0927     0.400