2016-07-17 5 views
0

確率表の形で、限界確率分布のために7と5で割り切れる分位数のベクトルと、条件付き確率に対して5を与えた分数ベクトルを説明したいと思います。ベクトルを使って確率テーブルを作る

>prob.table(table(x)) # discrete number and its probability 
     20  22  23  24  25  26  27  28  29  30  31 
0.000152 0.000625 0.000796 0.001224 0.003138 0.003043 0.004549 0.006444 0.005938 0.009301 0.009456 
     32  33  34  35  36  37  38  39  40  41  42 
0.013448 0.019839 0.018596 0.026613 0.028902 0.027377 0.035156 0.041379 0.041092 0.047733 0.055827 
     43  44  45  46  47  48  49  50  51  52  53 
0.046099 0.051624 0.055131 0.049779 0.056992 0.049801 0.052912 0.031924 0.049114 0.022880 0.042279 
     54  55  56  57  58  59  61  63  65 
0.013946 0.032340 0.003466 0.021240 0.001227 0.011734 0.005115 0.001491 0.000278 

私は数字が限界と条件付き確率のための7および/または5で割り切れるかを示し、双方向の確率テーブルにこれを有効にするにはどうすればよい:

だが、これが私のデータであると仮定しましょうか?

これは私が迅速な返信用

 Yes  NO # Probability of numbers divisible by 7 
Yes 0.02754 0.02886 
No 0.02656 0.02831 
# Probability of numbers divisible by 5 

答えて

1
x <- sample(1:100, 100, replace = TRUE) 

# %% is the mod operator, which gives the remainder after the division of the left-hand side by the right-hand side. x %% y == 0 therefore returns TRUE if x is divisible by y 
db5 <- x %% 5 == 0 
db7 <- x %% 7 == 0 

table(db5, db7)/length(x) 

#  db7 
# db5  FALSE TRUE 
# FALSE 0.62 0.13 
# TRUE 0.24 0.01 
+0

おかげで見えるようにテーブルを期待したいものです!また、どのように条件付き確率 'db5 ==" TRUE "'与えられた 'db7 ==" TRUE "を得るでしょうか? –

+0

' sum(db5&db7)/ sum(db7) ' – RoyalTS

関連する問題