Movatterモバイル変換


[0]ホーム

URL:


An example on how to use automated modelparameter search

Nina Purg, Jure Demšar and Grega Repovš

2024-01-16

In this example we show how you can use theautohrfpackage to automatically generate data-informed event models for generallinear modeling of task-based fMRI data. Let us start this example byloading required libraries and the data from the spatial working memorystudy.

# librarieslibrary(autohrf)# load the datadf<- swmhead(df)
##   roi t          y## 1 L_1 0 0.02712162## 2 L_1 1 0.06248649## 3 L_1 2 0.12908108## 4 L_1 3 0.30183784## 5 L_1 4 0.51691892## 6 L_1 5 0.65970270

The loaded data frame has 11520 observations, each with 3 variables(roi, t, and y)roi denotes the region of interest,t the time stamp andy the value ofthe BOLD signal. Note that input data for theautohrfpackage should be always organized in this manner.

Next, we define two different model constraints, which will be usedby theautohrf function to find the best fitting modelgiven these constraints.

# model constraints for three event predictorsmodel1<-data.frame(event =c("encoding","delay","response"),start_time =c(0,0.15,10),end_time =c(0.15,10,13))# model constraints for four event predictorsmodel2<-data.frame(event =c("encoding","early_delay","late_delay","response"),start_time =c(0,0.15,5,10),end_time =c(0.15,5,10,13))# join different model constraintsmodels<-list(model1, model2)

Once we define the constraints for our models we can use theautohrf function to automatically find model parametersthat fit our data best. Note that this is only an illustrative exampleand the set amount of the population size and iterations of the geneticalgorithm is way too small for any kind of proper analysis.

# to speed vignette building we here load results from a previous autohrf runautofit<- swm_autofit# in practice you should run# autofit <- autohrf(df, models, tr = 1, population = 10, iter = 10)

When the automated fitting process is completed, we can use theplot_fitness function to check whether our modelsolutions converged.

# plot models' fitness across iterationsplot_fitness(autofit)

Next, we can use theget_best_models function toextract the best model for each of the provided constraints.

# return automatically derived parametersbest<-get_best_models(autofit)
## ## ----------------------------------------## ## Model 1 ## ## Fitness:  0.682151 ## ##      event start_time duration## 1 encoding       0.09     0.04## 2    delay       2.16     7.48## 3 response      11.73     0.95## ## ----------------------------------------## ## ----------------------------------------## ## Model 2 ## ## Fitness:  0.7601532 ## ##         event start_time duration## 1    encoding       0.06     0.02## 2 early_delay       0.48     2.80## 3  late_delay       7.63     1.15## 4    response      11.83     0.74## ## ----------------------------------------

Based on calculated fitness scores we can see that the second modelfits our data better. Furthermore, we can use theplot_best_models function to visually inspect the bestmodels.

# visualize automatically derived parametersplot_best_models(autofit)


[8]ページ先頭

©2009-2025 Movatter.jp