#FOLLOWING function computes maximax and maximin #decision values assuming rows are actions in payoff matrix mmax=function(payoff){ nact=nrow(payoff) #number of actions nj=ncol(payoff) #number of states of nature maxact=apply(payoff,1,max) #find row maximum minact=apply(payoff,1,min) #maxact=rep(0,nact) #initialize #i=1 #while (i<=nact) { #maxact[i]=max(payoff[i,]) #i=i+1} print(maxact) om=order(maxact) print(c("maximax choice is action number=",om[length(om)]),q=F) sortact=sort(maxact) #optimistic criterion maximax maximax=max(maxact) print(minact) om=order(minact) maximin=max(minact) print(maximin) print(c("maximin choice is action number=",om[length(om)]),q=F) list(maximax=maximax, maximin=maximin, maxact=maxact, minact=minact) } ### end mmax function #FOLLOWING function computes minimax regret # max expected value and minimum expected regret #decision values assuming rows are actions in payoff matrix max.expvalue=function(payoff, prob){ if (sum(prob)!=1) print("ERROR in prob input to max.expvalue function") nact=nrow(payoff) #number of actions nj=ncol(payoff) #number of states of nature colmax=apply(payoff,2,max) #maximize by column best= matrix(colmax,nact,nj,byrow=T) print(best) regret=best-payoff print(regret) maxreg=apply(regret,1,max) #now by row max print("maximum regret values") print(maxreg) print(min(maxreg)) #minimize max regret om=order(maxreg) print(c("minimax Regret choice is action number=",om[1]),q=F) wpayoff=payoff wregret=regret #for (j in 1:nj) { #wpayoff[,j]=payoff[,j]*prob[j] #wregret[,j]=regret[,j]*prob[j] #} wpayoff=payoff%*%diag(prob) wregret=regret %*%diag(prob) print(wpayoff) print("weighted payoff above and weighted regret below") print(wregret) ev=rep(NA,nact) #initialize ereg=rep(NA,nact) #initialize for (i in 1:nact) { ev[i]=sum(wpayoff[i,]) ereg[i]=sum(wregret[i,]) } print(ev) print("expected value above, expected regret below") print(ereg) print("ordered exp value for each action") print(order(ev)) sortev=sort(ev) #sorted expected values maxev=max(ev) minreg=min(ereg) om=order(ev) print(c("max Expected value choice is action number=",om[length(om)]),q=F) om=order(ereg) print(c("min expected Regret choice is action number=",om[1]),q=F) list(maxev=maxev, ev=ev, maxev=maxev, minreg=minreg) } ### end max.expvalue function #example from the powerpoint payoff=matrix(c(200,90,40, 50,120,30, -120,-30,20), 3,3) #define data mmax(payoff) #apply first function to these data prob=c(.3,.5,.2) #define probabilities max.expvalue(payoff,prob) #apply second function with probabilities