# Design matrix for fMRI group analysis

### Description

This function returns a design matrix for multi-subject fMRI data to fit a Linear Mixed-effects Model (one-stage procedure) with given stimuli, polynomial drift terms and a set of known population parameters.

### Usage

1 | ```
fmri.designG(hrf, subj = 1, runs = 1, group = NULL, XG = NULL)
``` |

### Arguments

`hrf` |
vector or matrix containing expected BOLD response(s)
for one session, typically a |

`subj` |
number of subjects in the study. |

`runs` |
number of repeated measures within subjects. |

`group` |
optional vector to define groups.
It is expected one value per subject. A grouping factor can also be part of |

`XG` |
optionally, a group-level design matrix of class |

### Details

Based on the dimensionality of the `hrf`

object, which provides the total number of scans (time-points) within each session, the entered number of subjects and repeated measures the auxiliary variables: "subj", "run", "scan" and "session" are generated as first part of the returned design matrix.

If no `group`

argument is specified, only one population will be assumed; otherwise group labels are replicated within sessions of the same subject.

First a design matrix for a single run is created by calling: `x <- fmri.design(hrf, order = 2)`

. Hence the polynomial drift terms are defined orthogonal to the stimuli (see `fmri.design`

). This matrix is replicated blockwise to all sessions assuming the same experimental design for all runs. The first drift term, a column of ones, is called "drift0" and models an intercept.

If given, further subject characteristics are filled in the design matrix.

### Value

A design matrix as a data frame, which contains the following variables:

`subj` |
consecutive subject number: 1 to |

`run` |
consecutive run number within the subjects: 1 to |

`scan` |
consecutive scan number: 1 to T within each session |

`session` |
consecutive experiment number: 1 to |

`group` |
grouping variable specified as factor, one group by default |

`hrf, hrf2, ...` |
replicated expected BOLD-response(s) |

`drift0, drift1, drift2` |
replicated polynomial drift terms
created with |

`...` |
further expanded between-subject factors and covariates |

### Author(s)

Sibylle Dames

### References

Polzehl, J. and Tabelow, K.(2007). *fmri: A Package for Analyzing fmri Data*, R News, 7:13-17.

### See Also

`fmri.stimulus`

, `fmri.design`

, `fmri.lmePar`

### Examples

1 2 3 4 5 6 7 8 9 10 | ```
subj <- 6
runs <- 1
scans <- 121
times <- c(12, 48, 84, 120, 156, 192, 228, 264)
duration <- 24
tr <- 2.5
hrf <- fmri.stimulus(scans, times, duration, tr, times = TRUE)
x.group <- fmri.designG(hrf, subj = subj, runs = runs)
# View(x.group)
``` |