1

I hope I don't have a big gap in education. I need to get the final best alpha - learning rate of the model, but I can't manage to get the function right.

I have a data that looks something like this:

ID Turn_no p_mean t_mean
1  1       170    99
1  2       176    93
1  3       138    92
1  4       172    118
1  5       163    96
1  6       170    105
1  7       146    99
1  8       172    94

and so on...

I want to use the equation: p(turn) = p(turn-1) + alpha[(p(turn-1) - t(turn-1)]

I'm pretty stuck on making a function and log-likelihood based on the Rescorla-Wagner model. This is the function so far:

RWmodel = function(data, par) {
  ll <- NA
  alpha <- par[1]

  ID <- data$ID
  Turn_no <- data$Turn_no
  p_mean<- data$p_mean
  t_mean<- data$t_mean

  num_reps <- length(df$Turn_no) 

  i <- 2
  for (i in 2:num_reps) {

  #calculate prediction error
  PE <- p_mean[i-1] - t_mean[i-1]

  #update p's value
  p_mean[i] <- p_mean[i-1] + alpha*PE
}
#minus maximum log likelihood, use sum and log functions
  ll <- -sum(log(??))

  #return ll
  ll
}`

I know I'm missing an important step in the function, I just can't figure out how to execute the log likelihood right in this situation.

LoveDekel
  • 21
  • 2

0 Answers0