R-help -

This code iterates over a function with 2 free parameters to find a list of
values (which are the number of incorrect predictions for a computational
model).  I want to find the values of i,e when there is the minimum number
of incorrect predictions.  In other words, the value of "i" and "e" when
variable "thesum" is at the lowest possible number.  The bestDeltas variable
at the bottom worked with 1 free parameter.

structure(list(grid = c(3162L, 3162L, 3162L, 3162L, 3162L, 3162L,
3162L, 3162L, 3162L, 3162L, 3162L, 3162L, 3162L, 3162L, 3162L,
3162L, 3162L, 3162L, 3162L, 3162L), RepNum = c(1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L
), stimbinary = c(1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1,
0, 0, 0, 0, 1), choice = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 1, 1, 1, 1), accuracy = c(0L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 0L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 0L), actualcorrect = c(1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1), correctstim = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), choseright = c(0,
1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1), reward = c(0L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 1L, 1L,
1L, 1L, 0L), resp = structure(c(5L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
5L, 3L, 5L, 3L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 3L), .Label = c("f11.bmp",
"f13.bmp", "f14.bmp", "f4.bmp", "f7.bmp", "f9.bmp"), class =
"factor")), .Names = c("grid",
"RepNum", "stimbinary", "choice", "accuracy", "actualcorrect",
"correctstim", "choseright", "reward", "resp"), row.names = c(NA,
20L), class = "data.frame")



install.packages("Hmisc", dependencies = T)
library(Hmisc)
bestDeltas= 0; betterThanChance = 0; minErr = 0
fitProp<- 0
thresholded_test <- 0

calc.probs <- function(delta,gamma){
  # initial starting probabilities
thList = 0
block = 0
# finMatrix <- 0
for (i in 1:length(dat2$choice))
    {
      if (dat2$RepNum[i] != block)
      {
         pL = 0.5
         pR = 0.5
         block = dat2$RepNum[i]
         certState = 0.5
      }
      # Markov Transitions
      pL <- pL*(1-delta) + pR*delta
      pR <- 1-pL
      # Apply feedback
      #denom <- p(F|L,C) * p(L) + p(F|R,C) * p(R)

      pflc <- ifelse(dat2$choice[i] == dat2$reward[i], .8, .2)
      pfrc <- 1 - pflc
      denom <- pflc * pL + pfrc * pR

      # What's the new belief given observation
      posteriorL <- pflc * pL/denom
      posteriorR <- 1-posteriorL

      pL <- posteriorL
      pR <- posteriorR

      certState = gamma * certState + (1 - gamma) * pL

      thList[i] = ifelse(certState > 0.55, 1, ifelse(certState < 0.45, 0,
ifelse(pL > 0.5, 1, 0)))
    }

return(thList)
}

thesum=0
j = 1
      minx = 0.01; maxx = 0.5; incx = 0.05;
      x = seq(minx, maxx, incx)
      miny = 0.0; maxy = 1; incy = 0.05;
      y = seq(miny, maxy, incy)
for (i in x)
{
  for (e in y)

{
  thresholded = calc.probs(i, e)
  diff <- abs(dat2$choice - Lag(thresholded))
  diff = ifelse(is.na(diff), 0, diff)
  thesum[j] = sum(diff, na.rm = T)
  j = j + 1
}
}
minSum = min(thesum)
minErr[s] = min(thesum)
bestDeltas[s] = min(which(thesum==minSum)) * incx + minx
# bestDeltasGammas[s] <- matrix(min(which(thsum==minSum))*inc + min)
betterThanChance[s] = sum(pbinom(0:minSum, length(dat2$choice), 0.5))


-- 
Edward H. Patzelt
Research Assistant – TRiCAM Lab
University of Minnesota – Psychology/Psychiatry
VA Medical Center
Office: S355 Elliot Hall - Twin Cities Campus
Phone: 612-626-0072  Email: patze...@umn.edu

Please consider the environment before printing this email
www.psych.umn.edu/research/tricam

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to