Dynamic Causal Modelling in R. This package is an R reimplementation of the DCM algorithm found in the SPM toolbox (https://www.fil.ion.ucl.ac.uk/spm/). Current version includes the bilinear deterministic DCM algorithm.
Model type:
bilinear
nonlinear (untested)
two-state (untested)
Data fitting
deterministic (time-series)
stochastic (NOT IMPLEMENTED)
cross-spectra (NOT IMPLEMENTED)
R ( >= 3.2.0 )
CMake ( >= 2.8 )
GSL (libgsl-dev)
methods
R.matlab
Matrix
matrixcalc
exmp
numDeriv
pracma
plyr
stringr
> library('ReDCM')
> Amx = array( c(1, 1, 0, 1, 1, 1, 0, 1, 1), dim=c(3,3) )
> Amx
[,1] [,2] [,3]
[1,] 1 1 0
[2,] 1 1 1
[3,] 0 1 1
> DCMe = ReDCM_estimate( ReDCM::DCM, A=Amx ) #change priors of matrix A
> DCMe@Fe
[1] -3577.417
> class(DCMe@Ep[[1]])
[1] "Params"
attr(,"package")
[1] "ReDCM"
> DCMe@Ep@A
[,1] [,2] [,3]
[1,] 0.50456649 0.3927084 0.000000
[2,] 0.02413916 0.3689886 -0.305103
[3,] 0.00000000 0.3392079 0.125141
ReDCM can currently estimate models specified in Matlab, using the SPM toolbox (https://www.fil.ion.ucl.ac.uk/spm/) and exported using the -v6 option, i.e. save('DCM.mat', 'DCM', '-v6').
ReDCM_estimate = function(DCM.mat, A=NULL, B=NULL, C=NULL)
Function:
Estimates DCM model parameters.
Arguments:
DCM.mat - A .mat file of a DCM structure exported from Matlab, OR a ReDCM structure built with ReDCM_prepare_dcm() function.
A - A numeric array of zeros and ones specifying the endogenous connectivity matrix of DCM. Size of 'A' have to match the size of DCM.n * DCM.n, where DCM.n is the number of regions in the DCM model.
B - A numeric array of zeros and ones specifying the modulatory effects of DCM. Size of 'B' have to match the size of DCM.n * DCM.n * DCM.uN, where DCM.n is the number of regions and DCM.uN is the number of inputs in the DCM model.
C - A numeric array of zeros and ones specifying the direct regional effects of DCM. Size of 'C' have to match the size of DCM.n * DCM.uN, where DCM.n is the number of regions and DCM.uN is the number of inputs in the DCM model.
ReDCM_prepare_dcm = function(DCM.mat)
Function:
Prepares DCM structure for ReDCM_estimate() using a .mat file of a DCM structure exported from Matlab.
Arguments:
DCM.mat - A .mat file of a DCM structure exported from Matlab.
ReDCM_run_BMS = function( Fe, method, model.names=NULL )
Function:
Performs Bayesian Model Selection by fixed or random effects analysis.
Arguments:
Fe - An N x M numeric array or matrix containing estimated Bayesian model evidence (in terms of free-energy) for N subjects and M models.
method - A character string selecting BMS method. Use 'ffx' for fixed effects and 'rfx' for random effects analysis.
model.names - An array of M character strings, where M is the number of models. This must match the number of columns in Fe.