[問題] 用R plot all the possibilities
[問題類型]:
程式諮詢(我想用R 做某件事情,但是我不知道要怎麼用R 寫出來)
[軟體熟悉度]:
入門(寫過其他程式,只是對語法不熟悉)
[問題敘述]:
大家好
我現在遇到一個問題 有4個藍色玩具 B1 B2 B3 B4
另有6個紅色玩具 R1 R2 ... R6
現在要看隨機抽出三個玩具 顏色相同的機率
我的做法是 (2C1*4C3 + 2C1*6C3)/10C3 不知道這樣對嗎?
然後現在我遇到一個問題是
write a piece of R code to empirically compute the prob. of the three toys
in the same color, let n be the number of random samples in the bag.
我用的R code如下 當n=50,000
n <- 50000
f <- 0
for(i in 1:n)
f <- f + ifelse((sample(3)[1]==sample(3)[1]),1,0)
print(f/n)
但現在問題要我 Plot your estimated probabilities as a function of n (log scale again here,
please) 根據 n=50,100,200,.....,50000 用R繪製出機率的圖表
我在想這是不是要先把取出三種同顏色的玩具的C.D.F.先求出來
再用plot C.D.F的方式去繪製呢?
想了兩天都還是沒頭緒
老師有給蒙地卡羅模擬的參考資料
但我覺得這好像不是
另外還有buffon needle probability的參考資料
但我都無法refer 這些資料 又覺得並沒有我想的複雜
但還是目前無法動彈
不知道有沒有大大願意給小魯一點指點
感謝不盡~
也希望大家颱風天都一切平安
[關鍵字]:
選擇性,也許未來有用
--
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 8.41.66.215
※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1537055950.A.AD8.html
→
09/16 08:33,
6年前
, 1F
09/16 08:33, 1F
→
09/16 08:35,
6年前
, 2F
09/16 08:35, 2F
→
09/16 08:35,
6年前
, 3F
09/16 08:35, 3F
→
09/16 08:35,
6年前
, 4F
09/16 08:35, 4F
→
09/16 10:19,
6年前
, 5F
09/16 10:19, 5F
→
09/16 10:33,
6年前
, 6F
09/16 10:33, 6F
推
09/19 22:30,
6年前
, 7F
09/19 22:30, 7F
推
09/19 22:33,
6年前
, 8F
09/19 22:33, 8F
→
09/19 22:33,
6年前
, 9F
09/19 22:33, 9F
大大真是高手
我回去找老師給的資料
有看到以下說明:
# The randomness generated a computer is not entirely random indeed
# It is referred to as pseudo-randomness
set.seed(8262009)
這就是您說的嗎?
其實我還是不甚明白啊 因為我沒有學過這個/_\
那就藉此再問一下
Compute Pr[1 X 3] where X FX(x) with fX(x) = 3x2 in [0,1].
我用的code:
n <- 10000
z <- rnorm(n)
proba <- length(which(abs(z)<1/4))/n
print(proba)
根據的是老師給的資料
Probability as expectation
(因為Monte Carlo Simulation有兩種 Probability as expectation/
Probability using the uniform density as the weighting/importance function
我用的是前者
不知道這樣對嗎?
謝謝大家~~
※ 編輯: AmigoSafin (8.41.66.215), 09/21/2018 10:27:39
→
09/21 10:28,
6年前
, 10F
09/21 10:28, 10F
→
09/21 10:29,
6年前
, 11F
09/21 10:29, 11F
→
09/21 14:56,
6年前
, 12F
09/21 14:56, 12F
→
09/21 14:56,
6年前
, 13F
09/21 14:56, 13F
→
09/21 19:41,
6年前
, 14F
09/21 19:41, 14F
→
09/21 21:22,
6年前
, 15F
09/21 21:22, 15F
→
09/21 22:24,
6年前
, 16F
09/21 22:24, 16F
→
09/21 23:52,
6年前
, 17F
09/21 23:52, 17F
→
09/21 23:54,
6年前
, 18F
09/21 23:54, 18F
→
09/22 00:04,
6年前
, 19F
09/22 00:04, 19F
→
09/22 08:34,
6年前
, 20F
09/22 08:34, 20F
→
09/22 08:35,
6年前
, 21F
09/22 08:35, 21F
R_Language 近期熱門文章
PTT數位生活區 即時熱門文章