0

I have two matrices in R showing the probability of each scoreline in the first half, and second half of a soccer game. I want to combine these to have one object (I'm guessing a 4 dimensional array) giving me the probability of each HT/FT scoreline combination.

Here is what I currently have, for simplicity here I have assume each team can score a maximum of 3 goals in each half, but in practice I will allow for more than this

# Probability of teams scoring 0,1,2,3 goals in each half
t1_h1 <- c(0.5, 0.3, 0.1, 0.1)
t2_h1 <- c(0.8, 0.1, 0.06, 0.04)
t1_h2 <- c(0.5, 0.4, 0.05, 0.05)
t2_h2 <- c(0.7, 0.1, 0.1, 0.1)

# Create matrix showing probability of possible first half scorelines 
h1 <- t(t1_h1 %*% t(t2_h1))    
h1
     [,1]  [,2]  [,3]  [,4]
[1,] 0.40 0.240 0.080 0.080
[2,] 0.05 0.030 0.010 0.010
[3,] 0.03 0.018 0.006 0.006
[4,] 0.02 0.012 0.004 0.004

# Create matrix showing probability of possible second half scorelines 
h2 <- t(t1_h2 %*% t(t2_h2))
h2
         [,1] [,2]  [,3]  [,4]
[1,] 0.35 0.28 0.035 0.035
[2,] 0.05 0.04 0.005 0.005
[3,] 0.05 0.04 0.005 0.005
[4,] 0.05 0.04 0.005 0.005

So for example from h1 you can see the probability of it being 0-0 at HT is 0.4, probability of it being 0-1 is 0.250 etc.

I want to end up with an object which gives the probability of each possible combination HT/FT. For example, it would tell me that the probability of it being 0-0 at HT and 0-0 at FT is 0.40 * 0.35 = 0.14. Or the probability of it being 1-1 at HT and 1-1 at FT (i.e. no goals in second half) is 0.03 * 0.35 =0.0105. It should also be clever enough to know that the probability of it being 1-0 at HT and 0-0 at FT is zero (FT goals cannot be less than HT goals).

It perhaps might be easier to end up with an object which shows HT/Second Half scoreline rather than HT/FT so we can ignore the last constraint that FT score can not be less than HT score.

4

1 回答 1

1

它认为您正在寻找的是outer

myscores <- outer(t(t1_h1 %*% t(t2_h1)), t(t2_h2 %*% t(t1_h2)))
dim(myscores)  # 4 4 4 4

正如你提到的,它是四维的

myscores[1,1,1,1] # 0.14
myscores[3,1,1,1] # 0.0105

计算您想要的概率。导航此对象的工作原理是遵循您所提出问题中矩阵的坐标。

于 2016-05-20T17:28:23.350 回答