r - R 新手,想模拟一个函数 10000 次
问题描述
PI<-0.5825702
pJ<-1-PI
s<-simulate_game(1,2)
K<-true_RA[13]-s[1]/PI
K
elo_Rating<-function(RA_i,RA_j,k) {
PI<-(1/(1+exp((RA_j-RA_i)))) # Expected score for player i
PJ<-(1/(1+exp((RA_j-RA_i)))) # Expected score for player j
new_RA_i_wins <-RA_i+ k*(1-PI) #new rankling based on wins of i,
#used the formula which is given
new_RA_i_defets <-RA_i-k*PI #new rankling based on lost of i
new_RA_j_wins<-RA_j+ k*(1-PJ) #new rankling based on wins of j
new_RA_j_defets <-RA_j-k*PJ #new rankling based on lost of j
I_wins<-round(data.frame(I_wins=c(new_RA_i_wins,new_RA_j_defets)), digits=0)
J_wins<-round(data.frame(J_wins=c(new_RA_i_defets,new_RA_i_defets)), digits=0)
df<-cbind(I_wins, J_wins)
rownames(df) <- c('playerI', 'playerJ')
return(df)
}
RA_i<-s[1]
RA_j<-s[2]
elo_Rating(398.333333 ,-1.666667,-681.7516)
我有这个功能,想模拟 10000 次。并将结果保存在矩阵中(13 行和 10000 列)。我知道我需要使用复制。但不知道如何编写一个函数来复制我当前的函数并将其放入矩阵中。