partition_variance | R Documentation |
Calculate the proportion of variance for a response variable that is attributed to another set of predictor variables, calculated across lags from from 0 (simultaneous effects) to a user-specified maximum lag.
partition_variance(object, which_response, n_times = 10)
object |
Output from |
which_response |
string matching colnames from |
n_times |
Number of lags over which to calculate total effects |
This function calculates the variance for each variable and lag, and then
recalculates it when setting exogenous variance to zero for all variables except
which_pred
. It then calculates the ratio of the diagonal of these two.
This represents the proportion of variance in the full model that is attributable
to one or more variables.
This function is under development and may still change or be removed.
A list with two elements:
A matrix of the total variance for each variable (column)
and each time from 1 to n_times
A matrix of the proportion of variance
explained for variable which_response
by each model variable
(column) and each time from 1 to n_times
Note that in a model with lagged effects, the total_variance and variance_explained will vary for each time (row), and the analyst might want to either choose a time for which the value has stabilized.
# Simulate linear model
x = rnorm(100)
y = 1 + 1 * x + rnorm(100)
data = data.frame(x=x, y=y)
# Fit as DSEM
fit = dsem( sem = "x -> y, 0, beta",
tsdata = ts(data),
control = dsem_control(quiet=TRUE) )
# Apply
partition_variance( fit,
which_response = "y",
n_times = 10 )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.