epinowcast
Loading...
Searching...
No Matches
combine_effects.stan File Reference

Go to the source code of this file.

Functions

vector combine_effects (array[] real intercept, vector beta, int nobs, int neffs, matrix fdesign, tuple(vector, array[] int, array[] int) sparse, vector beta_sd, matrix rdesign, int add_intercept, int sparse_design)
 

Function Documentation

◆ combine_effects()

vector combine_effects ( array[]real  intercept,
vector  beta,
int  nobs,
int  neffs,
matrix  fdesign,
tuple(vector, array[] int, array[] int)  sparse,
vector  beta_sd,
matrix  rdesign,
int  add_intercept,
int  sparse_design 
)

Combine nested regression effects using design matrices

This function combines nested regression effects based on a design matrix and applies effect pooling using a second design matrix. It allows for scaling of effects with specified standard deviations, enabling the pooling of these effects. The function can also incorporate an intercept into the linear predictions.

Parameters
interceptArray containing the regression intercept (length one).
betaVector of regression effects, typically unit-scaled for possible rescaling with beta_sd.
nobsInteger the number of observations (i.e. design matrix columns).
neffsInteger the number of effects (i.e. the number of rows in the design matrix).
fdesignDense matrix mapping observations (rows) to fixed effects (columns).
beta_sdVector of standard deviations for scaling and pooling effects.
rdesignDense matrix relating effect sizes to standard deviations. The first column indicates no scaling for independent effects.
sparseSparse matrix components for fixed effects design matrix. The output from csr_extract(fdesign).
add_interceptBinary flag to indicate if the intercept should be added to the beta vector.
sparse_designBinary flag to indicate whether to use sparse or dense matrices.
Returns
A vector of linear predictions without error.
Note
The function scales the beta vector using the product of beta_sd and rdesign, then combines these scaled effects with the fdesign matrix. If add_intercept is true, the intercept is included in the linear predictions. The function handles cases with no effects by returning a vector of the intercept repeated for each observation.
# Example usage in R:
intercept <- 1
beta <- c(0.1, 0.2, 0.4)
design <- matrix(c(1, 1, 1, 0,
0, 1, 0, 0,
0, 1, 1, 1), nrow = 3, byrow = TRUE)
beta_sd <- c(0.1)
sd_design <- matrix(c(1, 1, 0,
0, 0, 1), nrow = 2, byrow = TRUE)
# Check effects are combined as expected:
intercept, beta, 4, 3, design, list({}, {}, {}), beta_sd, sd_design, 1, 0
)
# Output: 1.04 1.12 1.00 1.04
vector combine_effects(array[] real intercept, vector beta, int nobs, int neffs, matrix fdesign, tuple(vector, array[] int, array[] int) sparse, vector beta_sd, matrix rdesign, int add_intercept, int sparse_design)

Definition at line 62 of file combine_effects.stan.