R Help -
I'm attempting to use fminsearch and it continues to give me errors. I have
a normal Rescorla Wagner function that has 2 parameters and returns total
error. for some reason fminsearch keeps saying the type of errors below,
I've put the function and data after it using dput
> sol <- fminsearch(rescorlaWagner(learningRate,decision_slope),
c(-1.2,1))
Error in this$fun(x = x, index = index, fmsfundata = this$costfargument) :
attempt to apply non-function> sol <- fminsearch(rescorlaWagner,c(alphaPlus = alphaPlus, decision_slope
= decision_slope), c(-1.2,1))
Error in options[[name]] : subscript out of bounds
rescorlaWagner <- function(alphaPlus, decision_slope){
# alphaPlus <- parameters[1]
# decision_slope <_- parameters[2]
#dat <- mainData[mainData$participants == subjects[s],]
dat$choice <- ifelse(dat$cueResp.keys == 5, 1, 0)
dat$reward <- dat$trialChange
# numberTrials[s] <<- length(dat$choice)
numberTrials <<- length(dat$choice)
V1 <- 0; V0 <- 0; totError <- 0; thList = 0; block = 0; valueOne <-
0; valueZero
<- 0; probOfStim1 <- .000001; probOfStim2 <- .000001; logLike <- 0;
V1[1] = 0; V0[1] = 0;
for (i in 2:length(dat$choice))
{
if (dat$choice[i-1] == 1) # Chose pattern 1 last time
{
logLike[i] <- logLike[i-1] - log(probOfStim1[i-1])
#print(logLike)
delta1 <- dat$reward[i] - V1[i-1]
V1[i] <- V1[i-1] + alphaPlus * delta1
V0[i] <- V0[i-1]
}
else # Chose pattern 0 last time instead of pattern 1
{
logLike[i] <- logLike[i-1] - log(probOfStim2[i-1])
delta0 <- dat$reward[i] - V0[i-1]
V0[i] <- V0[i-1] + alphaPlus * delta0
V1[i] <- V1[i-1]
}
probOfStim1[i] <- exp(decision_slope * V1[i])/(exp(decision_slope * V1
[i] + exp(decision_slope * V0[i])))
probOfStim2[i] <- exp(decision_slope * V0[i])/(exp(decision_slope * V1
[i] + exp(decision_slope * V0[i])))
valueOne[i] <- V1[i]
valueZero[i] <- V0[i]
newList <- list("EVpattern1" = valueOne,
"EVpattern0" valueZero, "ProbabilityStim1"
= probOfStim1, "ProbabilityStim2" = probOfStim2,
"LogLikelihood" = logLike)
logLike[i]
}
#return(newList)
return(logLike[i])
}
dput(dat)
structure(list(highCueImg = c("1.bmp", "1.bmp",
"1.bmp", "1.bmp",
"1.bmp", "1.bmp", "1.bmp", "1.bmp",
"1.bmp", "1.bmp", "1.bmp",
"1.bmp", "1.bmp", "1.bmp", "1.bmp",
"1.bmp", "1.bmp", "1.bmp",
"1.bmp", "1.bmp", "1.bmp", "1.bmp",
"1.bmp", "1.bmp", "1.bmp",
"1.bmp", "1.bmp", "1.bmp", "1.bmp",
"1.bmp", "1.bmp", "1.bmp",
"1.bmp", "1.bmp", "1.bmp", "1.bmp",
"1.bmp", "1.bmp", "1.bmp",
"1.bmp"), fixationDuration = c(2.900504833, 2.137709799, 3.314149929,
3.034789701, 3.44018723, 3.559188201, 4, 3.397855819, 2.424957014,
3.010173792, 2.754706831, 2.183118953, 3.328269233, 3.058698132,
3.030312482, 2.948379082, 2.48854601, 2.635627291, 2.62972477,
3.071401111, 3.343837986, 3.452638681, 3.044377797, 2, 3.139145494,
2.821634126, 3.463414658, 2.974553193, 2.887472182, 3.276110294,
2.774994095, 2.538595411, 2, 2, 2, 2.937451712, 3.030693282,
3.533087478, 2.821526274, 2), condition = c("gain", "gain",
"gain",
"gain", "gain", "gain", "gain",
"gain", "gain", "gain", "gain",
"gain", "gain", "gain", "gain",
"gain", "gain", "gain", "gain",
"gain", "gain", "gain", "gain",
"gain", "gain", "gain", "gain",
"gain", "gain", "gain", "gain",
"gain", "gain", "gain", "gain",
"gain", "gain", "gain", "gain",
"gain"), value = c(1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L), lowCueImg = c("2.bmp", "2.bmp",
"2.bmp",
"2.bmp", "2.bmp", "2.bmp", "2.bmp",
"2.bmp", "2.bmp", "2.bmp",
"2.bmp", "2.bmp", "2.bmp", "2.bmp",
"2.bmp", "2.bmp", "2.bmp",
"2.bmp", "2.bmp", "2.bmp", "2.bmp",
"2.bmp", "2.bmp", "2.bmp",
"2.bmp", "2.bmp", "2.bmp", "2.bmp",
"2.bmp", "2.bmp", "2.bmp",
"2.bmp", "2.bmp", "2.bmp", "2.bmp",
"2.bmp", "2.bmp", "2.bmp",
"2.bmp", "2.bmp"), trials.thisRepN = c(0L, 0L, 0L, 0L, 0L,
0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L), trials.thisTrialN = c(0L, 2L, 4L, 6L, 10L, 12L, 14L,
15L, 18L, 19L, 21L, 24L, 30L, 36L, 0L, 6L, 9L, 10L, 12L, 15L,
16L, 22L, 27L, 31L, 33L, 36L, 37L, 0L, 3L, 4L, 6L, 7L, 8L, 11L,
14L, 23L, 30L, 32L, 33L, 35L), trials.thisN = c(0L, 2L, 4L, 6L,
10L, 12L, 14L, 15L, 18L, 19L, 21L, 24L, 30L, 36L, 0L, 6L, 9L,
10L, 12L, 15L, 16L, 22L, 27L, 31L, 33L, 36L, 37L, 0L, 3L, 4L,
6L, 7L, 8L, 11L, 14L, 23L, 30L, 32L, 33L, 35L), trials.thisIndex = c(0L,
2L, 4L, 6L, 10L, 12L, 14L, 15L, 18L, 19L, 21L, 24L, 30L, 36L,
0L, 6L, 9L, 10L, 12L, 15L, 16L, 22L, 27L, 31L, 33L, 36L, 37L,
0L, 3L, 4L, 6L, 7L, 8L, 11L, 14L, 23L, 30L, 32L, 33L, 35L), high = c(5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L), low = c(6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L), cueTime = c(0.119068770004, 20.0149482278, 39.3913808842,
59.2522502599, 97.990193226, 117.999774375, 137.977367394, 147.956777102,
177.930680089, 187.577239771, 207.587493584, 237.544439209, 295.992193444,
355.789316562, 0.133269903658, 59.9700627473, 89.6437574958,
99.3573393621, 119.250773587, 149.107854998, 159.088620573, 217.669339096,
266.886893568, 306.807173693, 326.067568655, 356.041074367, 366.021205168,
0.133207719696, 29.9990445702, 39.9951733175, 59.9719083577,
69.9688165736, 79.7328835322, 108.989916701, 138.230480484, 226.768412694,
295.246161918, 315.222909848, 325.219804178, 345.196583306),
chooseTime = c(0.164843432754, 20.0597509983, 39.4367907433,
59.313679519, 98.0511001692, 118.044607117, 138.038122245,
148.018215406, 177.991826923, 187.638709517, 207.632219355,
237.589165691, 296.053516823, 355.850799047, 0.183364513565,
60.0152965201, 89.688980897, 99.4025104961, 119.296034835,
149.153016207, 159.149770617, 217.714112771, 266.931477687,
306.868519435, 326.128944696, 356.085867007, 366.065983813,
0.185307595107, 30.0603012765, 40.0403847835, 60.017241203,
70.0139768887, 79.794160632, 109.051319454, 138.275161454,
226.813068733, 295.29086624, 315.267703221, 325.281141721,
345.241325264), responseTime = c(1.69766205347, 21.3426436282,
40.5030967752, 60.7465334017, 99.1007329297, 119.910673908,
139.720902175, 149.800975001, 179.474667321, 189.521422584,
209.498269564, 239.188629276, 297.68630058, 357.466910556,
1.73283767373, 61.6480800894, 91.6549971296, 101.118596189,
120.962149647, 150.869099694, 161.315733453, 219.846762291,
268.547610394, 308.284709937, 327.795056685, 357.63537071,
367.465509636, 1.20163811838, 31.5431323218, 41.6065368123,
61.6833602893, 71.4468475335, 81.5602346449, 111.017339739,
139.857969642, 228.229268719, 296.857001011, 316.667249551,
326.780638151, 346.690839156), cueResp.keys = c("6",
"5",
"5", "5", "5", "5", "5",
"5", "5", "5", "5", "5",
"5", "5",
"5", "5", "5", "5", "5",
"5", "5", "5", "5", "5",
"5", "5",
"5", "5", "5", "5", "5",
"5", "5", "5", "5", "5",
"5", "5",
"5", "5"), cueResp.corr = c(0L, 1L, 1L, 1L, 1L, 1L, 1L,
1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L), cueResp.rt = c(0.533380177969, 0.266532022104,
0.0500725925289,
0.433291462956, 0.0500901515477, 0.84986263882, 0.683214172019,
0.783185845703, 0.48325372425, 0.883164556527, 0.849827385453,
0.58323989324, 0.633225596632, 0.616585605117, 0.566592999914,
0.616564437308, 0.949764760595, 0.699886593775, 0.649905965244,
0.699878703306, 1.16631698494, 1.11640042371, 0.599932215969,
0.416623022147, 0.66655325704, 0.533264790669, 0.383298154791,
0.0334208235774, 0.483276527291, 0.549915251434, 0.649906660688,
0.416622732692, 0.766502526153, 0.966452151311, 0.566611852083,
0.399999961871, 0.549913251563, 0.383312123816, 0.499929660817,
0.433279880996), outcome = c("False", "True",
"False", "True",
"True", "False", "False", "True",
"False", "False", "True",
"True", "True", "True", "False",
"True", "True", "True",
"True", "True", "True", "False",
"True", "True", "True",
"True", "False", "True", "True",
"True", "True", "True",
"True", "True", "True", "True",
"True", "True", "True", "True"
), trialChange = c(0L, 1L, 0L, 1L, 1L, 0L, 0L, 1L, 0L, 0L,
1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L,
1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L
), runningBankTotal = c(0L, 1L, 1L, 1L, 0L, 0L, -1L, 0L,
-1L, -1L, 0L, 1L, 2L, 1L, 0L, 0L, 1L, 2L, 2L, 3L, 4L, 2L,
2L, 3L, 4L, 5L, 5L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 6L, 6L, 5L,
6L, 7L, 8L), feedbackTime = c(5.03210832814, 25.0095173362,
44.3865482735, 64.2634794111, 103.000923924, 122.994382759,
142.971258771, 152.95144046, 182.924951435, 192.588530855,
212.581993437, 242.53893663, 300.986634339, 360.783862007,
5.03530764075, 64.965030954, 94.6387330854, 104.368972999,
124.245816409, 154.102824448, 164.082872867, 222.680585645,
271.897999411, 311.818302701, 331.062036785, 361.035651024,
371.015758808, 5.03618633224, 34.9934144733, 44.9901716237,
64.9670543311, 74.9637716194, 84.7439667717, 113.984431745,
143.224937046, 231.762859821, 300.240661343, 320.21753607,
330.214242471, 350.191541889), fixationTime = c(7.26391823943,
27.2241332653, 46.6011578196, 66.4780221495, 105.215460197,
125.208968288, 145.185827933, 155.165931423, 185.139538768,
194.80307024, 214.796575853, 244.753504942, 303.201212026,
362.998467215, 7.26574414055, 67.179653612, 96.8533502551,
106.583513696, 126.460384852, 156.317372687, 166.297459825,
224.895128913, 274.112492525, 314.032860656, 333.276624081,
363.250234207, 373.230329086, 7.26770291281, 37.2079844656,
47.2047548558, 67.18160346, 77.1783364203, 86.9585412487,
116.199012703, 145.439518309, 233.977453785, 302.455211908,
322.432067869, 332.428831237, 352.405710448), expStartTime = c("Sat Aug
18 18:07:45 2012",
"Sat Aug 18 18:07:45 2012", "Sat Aug 18 18:07:45 2012",
"Sat Aug 18
18:07:45 2012",
"Sat Aug 18 18:07:45 2012", "Sat Aug 18 18:07:45 2012",
"Sat Aug 18
18:07:45 2012",
"Sat Aug 18 18:07:45 2012", "Sat Aug 18 18:07:45 2012",
"Sat Aug 18
18:07:45 2012",
"Sat Aug 18 18:07:45 2012", "Sat Aug 18 18:07:45 2012",
"Sat Aug 18
18:07:45 2012",
"Sat Aug 18 18:07:45 2012", "Sat Aug 18 18:15:02 2012",
"Sat Aug 18
18:15:02 2012",
"Sat Aug 18 18:15:02 2012", "Sat Aug 18 18:15:02 2012",
"Sat Aug 18
18:15:02 2012",
"Sat Aug 18 18:15:02 2012", "Sat Aug 18 18:15:02 2012",
"Sat Aug 18
18:15:02 2012",
"Sat Aug 18 18:15:02 2012", "Sat Aug 18 18:15:02 2012",
"Sat Aug 18
18:15:02 2012",
"Sat Aug 18 18:15:02 2012", "Sat Aug 18 18:15:02 2012",
"Sat Aug 18
18:22:19 2012",
"Sat Aug 18 18:22:19 2012", "Sat Aug 18 18:22:19 2012",
"Sat Aug 18
18:22:19 2012",
"Sat Aug 18 18:22:19 2012", "Sat Aug 18 18:22:19 2012",
"Sat Aug 18
18:22:19 2012",
"Sat Aug 18 18:22:19 2012", "Sat Aug 18 18:22:19 2012",
"Sat Aug 18
18:22:19 2012",
"Sat Aug 18 18:22:19 2012", "Sat Aug 18 18:22:19 2012",
"Sat Aug 18
18:22:19 2012"
), vers = c("A", "A", "A", "A",
"A", "A", "A", "A", "A",
"A", "A", "A", "A", "A",
"B", "B", "B", "B", "B",
"B", "B",
"B", "B", "B", "B", "B",
"B", "C", "C", "C", "C",
"C", "C",
"C", "C", "C", "C", "C",
"C", "C"), expName = c("None", "None",
"None", "None", "None", "None",
"None", "None", "None", "None",
"None", "None", "None", "None",
"None", "None", "None", "None",
"None", "None", "None", "None",
"None", "None", "None", "None",
"None", "None", "None", "None",
"None", "None", "None", "None",
"None", "None", "None", "None",
"None", "None"), mriMode = c("Scan",
"Scan", "Scan", "Scan", "Scan",
"Scan", "Scan", "Scan", "Scan",
"Scan", "Scan", "Scan", "Scan",
"Scan", "Scan", "Scan", "Scan",
"Scan", "Scan", "Scan", "Scan",
"Scan", "Scan", "Scan", "Scan",
"Scan", "Scan", "Scan", "Scan",
"Scan", "Scan", "Scan", "Scan",
"Scan", "Scan", "Scan", "Scan",
"Scan", "Scan", "Scan"),
session = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), triggerWallTime
c("Sat Aug 18 18:07:58 2012",
"Sat Aug 18 18:07:58 2012", "Sat Aug 18 18:07:58 2012",
"Sat Aug 18
18:07:58 2012",
"Sat Aug 18 18:07:58 2012", "Sat Aug 18 18:07:58 2012",
"Sat Aug 18
18:07:58 2012",
"Sat Aug 18 18:07:58 2012", "Sat Aug 18 18:07:58 2012",
"Sat Aug 18
18:07:58 2012",
"Sat Aug 18 18:07:58 2012", "Sat Aug 18 18:07:58 2012",
"Sat Aug 18
18:07:58 2012",
"Sat Aug 18 18:07:58 2012", "Sat Aug 18 18:15:13 2012",
"Sat Aug 18
18:15:13 2012",
"Sat Aug 18 18:15:13 2012", "Sat Aug 18 18:15:13 2012",
"Sat Aug 18
18:15:13 2012",
"Sat Aug 18 18:15:13 2012", "Sat Aug 18 18:15:13 2012",
"Sat Aug 18
18:15:13 2012",
"Sat Aug 18 18:15:13 2012", "Sat Aug 18 18:15:13 2012",
"Sat Aug 18
18:15:13 2012",
"Sat Aug 18 18:15:13 2012", "Sat Aug 18 18:15:13 2012",
"Sat Aug 18
18:22:28 2012",
"Sat Aug 18 18:22:28 2012", "Sat Aug 18 18:22:28 2012",
"Sat Aug 18
18:22:28 2012",
"Sat Aug 18 18:22:28 2012", "Sat Aug 18 18:22:28 2012",
"Sat Aug 18
18:22:28 2012",
"Sat Aug 18 18:22:28 2012", "Sat Aug 18 18:22:28 2012",
"Sat Aug 18
18:22:28 2012",
"Sat Aug 18 18:22:28 2012", "Sat Aug 18 18:22:28 2012",
"Sat Aug 18
18:22:28 2012"
), date = c("2012_Aug_18_1807", "2012_Aug_18_1807",
"2012_Aug_18_1807",
"2012_Aug_18_1807", "2012_Aug_18_1807",
"2012_Aug_18_1807",
"2012_Aug_18_1807", "2012_Aug_18_1807",
"2012_Aug_18_1807",
"2012_Aug_18_1807", "2012_Aug_18_1807",
"2012_Aug_18_1807",
"2012_Aug_18_1807", "2012_Aug_18_1807",
"2012_Aug_18_1815",
"2012_Aug_18_1815", "2012_Aug_18_1815",
"2012_Aug_18_1815",
"2012_Aug_18_1815", "2012_Aug_18_1815",
"2012_Aug_18_1815",
"2012_Aug_18_1815", "2012_Aug_18_1815",
"2012_Aug_18_1815",
"2012_Aug_18_1815", "2012_Aug_18_1815",
"2012_Aug_18_1815",
"2012_Aug_18_1822", "2012_Aug_18_1822",
"2012_Aug_18_1822",
"2012_Aug_18_1822", "2012_Aug_18_1822",
"2012_Aug_18_1822",
"2012_Aug_18_1822", "2012_Aug_18_1822",
"2012_Aug_18_1822",
"2012_Aug_18_1822", "2012_Aug_18_1822",
"2012_Aug_18_1822",
"2012_Aug_18_1822"), participant = c("1285",
"1285", "1285",
"1285", "1285", "1285", "1285",
"1285", "1285", "1285", "1285",
"1285", "1285", "1285", "1285",
"1285", "1285", "1285", "1285",
"1285", "1285", "1285", "1285",
"1285", "1285", "1285", "1285",
"1285", "1285", "1285", "1285",
"1285", "1285", "1285", "1285",
"1285", "1285", "1285", "1285",
"1285"), mean_rt = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), bank = c(0L, 1L, 1L, 1L, 0L,
0L, -1L, 0L, -1L, -1L, 0L, 1L, 2L, 1L, 0L, 0L, 1L, 2L, 2L,
3L, 4L, 2L, 2L, 3L, 4L, 5L, 5L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
6L, 6L, 5L, 6L, 7L, 8L), X = c(NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA), resp = c("Right", "Left", "Left",
"Left", "Left",
"Left", "Left", "Left", "Left",
"Left", "Left", "Left", "Left",
"Left", "Left", "Left", "Left",
"Left", "Left", "Left", "Left",
"Left", "Left", "Left", "Left",
"Left", "Left", "Left", "Left",
"Left", "Left", "Left", "Left",
"Left", "Left", "Left", "Left",
"Left", "Left", "Left")), .Names =
c("highCueImg", "fixationDuration",
"condition", "value", "lowCueImg",
"trials.thisRepN", "trials.thisTrialN",
"trials.thisN", "trials.thisIndex", "high",
"low", "cueTime",
"chooseTime", "responseTime", "cueResp.keys",
"cueResp.corr",
"cueResp.rt", "outcome", "trialChange",
"runningBankTotal", "feedbackTime",
"fixationTime", "expStartTime", "vers",
"expName", "mriMode",
"session", "triggerWallTime", "date",
"participant", "mean_rt",
"bank", "X", "resp"), row.names = c(241L, 243L,
245L, 247L, 251L,
253L, 255L, 256L, 259L, 260L, 262L, 265L, 271L, 277L, 281L, 287L,
290L, 291L, 293L, 296L, 297L, 303L, 308L, 312L, 314L, 317L, 318L,
321L, 324L, 325L, 327L, 328L, 329L, 332L, 335L, 344L, 351L, 353L,
354L, 356L), class = "data.frame")
[[alternative HTML version deleted]]