77# # To run, this script requires some additional R packages to be installed, the rcpp file, as well as a data file.
88sink(sprintf(" output_log_%s.txt" , format(Sys.time(),' %y-%m-%d_%H-%M-%S' )), split = TRUE )
99rm(list = ls())
10- print(" TEST" )
1110start_time <- Sys.time()
1211
1312# ------------------------------------------------------------------------------
@@ -194,16 +193,17 @@ fitFunctionSSP <- function(
194193
195194library(" DEoptim" )
196195library(" Rcpp" )
197- analysis_path = " /Users/fzaki001/thrive-theta-ddm/" # local
198- # analysis_path = "/home/data/NDClab/analyses/thrive-theta-ddm/" # HPC
196+ library(" dplyr" )
197+ # analysis_path = "/Users/fzaki001/thrive-theta-ddm/" # local
198+ analysis_path = " /home/data/NDClab/analyses/thrive-theta-ddm/" # HPC
199199
200200# set up default parms and upper/lower values (for now, not using default values, just upper/lower with DEoptim)
201201Upper <- c(0.232 , 0.420 , 0.630 , 0.067 , 3.093 ); # mean of white 2011 Exp1 plus 5 sd
202202Lower <- c(0.032 , 0.180 , 0.130 , 0.0001 , 0.493 ); # mean of white 2011 Exp1 minus 5 sd
203203numParams <- length(Upper )
204204
205205# how many trials to simulate per condition
206- nTrials = 10
206+ nTrials = 10000
207207
208208data_dir = sprintf(" %sderivatives/behavior/" , analysis_path )
209209input_data <- sprintf(" %sfull_df.csv" , data_dir )
@@ -229,17 +229,19 @@ importDat <- subset(importDat,
229229# find only subjects with both valid soc and nonsoc condition and subset them
230230thrive_id_soc <- read.csv(sprintf(" %sthrive_data_soc.csv" , data_dir ), header = TRUE )
231231thrive_id_nonsoc <- read.csv(sprintf(" %sthrive_data_nonsoc.csv" , data_dir ), header = TRUE )
232- importDat <- subset(importDat , importDat $ sub %in% intersect(thrive_id_soc $ sub , thrive_id_nonsoc $ sub ))
233-
232+ already_fitted <- read.csv(" fitted_id.csv" , header = TRUE )
233+ # importDat <- subset(importDat, importDat$sub %in% intersect(thrive_id_soc$sub, thrive_id_nonsoc$sub))
234+ importDat <- bind_rows(thrive_id_soc , thrive_id_nonsoc )
235+ importDat <- subset(importDat , ! (importDat $ sub %in% (already_fitted $ sub )))
234236# convert rt values from ms to secs to be consistent with rest of script
235237# importDat$rt <- as.numeric(importDat$rt / 1000)
236-
238+ print(unique( importDat $ sub ))
237239# get sub list
238- subList <- (unique(importDat $ sub ))
240+ subList <- (unique(importDat $ sub ))[ 37 : 40 ]
239241
240242# initialize output vector
241- fitOutput <- data.frame (matrix (ncol = 10 , nrow = 0 ))
242- colnames(fitOutput ) <- c(" subject" , " a" , " ter" , " p" , " rd" , " sda" , " fitStat" , " iterNum" , " pre_accuracy" , " condition_soc" )
243+ fitOutput <- data.frame (matrix (ncol = 11 , nrow = 0 ))
244+ colnames(fitOutput ) <- c(" subject" , " a" , " ter" , " p" , " rd" , " sda" , " fitStat" , " iterNum" , " pre_accuracy" , " condition_soc" , " seed " )
243245fitOutput <- data.frame (fitOutput )
244246# also write a .csv to append parms to at the end of loops
245247write.csv(fitOutput , FitOutputName , row.names = FALSE , na = " " , quote = F )
@@ -301,7 +303,10 @@ for (cond in 1:2) {
301303
302304 # pull out data for this condition (for this subject)
303305 preacc_data <- subset(dataCondSoc , dataCondSoc $ pre_accuracy == preAccuracy ) # this is for having post-err/corr conditions
304-
306+
307+ seed <- sample(1 : 10e6 , 1 )
308+ set.seed(seed ) # For reproducibility
309+
305310 # Loop over congruency conditions
306311 for (i in 1 : 2 ) {
307312 # clear out variable for this iteration of loop
@@ -430,7 +435,7 @@ for (cond in 1:2) {
430435 control = DEoptim.control(
431436 itermax = 200 ,
432437 steptol = 20 ,
433- parallelType = " auto " ,
438+ parallelType = 1 ,
434439 packages = c(" Rcpp" ),
435440 parVar = c(" nTrials" ," cutPoints" ," humanProps" ," HumanTrialCounts" )
436441 ),
@@ -470,7 +475,7 @@ for (cond in 1:2) {
470475
471476 newRow <- NULL
472477 # make new row with values created above
473- newRow <- data.frame (subject , bestParms1 , bestParms2 , bestParms3 , bestParms4 , bestParms5 , bestFitStat , iter , preAccuracy , conditionSoc )
478+ newRow <- data.frame (subject , bestParms1 , bestParms2 , bestParms3 , bestParms4 , bestParms5 , bestFitStat , iter , preAccuracy , conditionSoc , seed )
474479
475480 # appending the parms to the csv created before the loops
476481 write.table(newRow , file = FitOutputName , sep = " ," , append = TRUE , col.names = FALSE , row.names = FALSE )
@@ -491,4 +496,4 @@ print(
491496 round((end_time - start_time ) / 60 , 2 )
492497 )
493498 )
494- sink()
499+ sink()
0 commit comments