看板 R_Language 關於我們 聯絡資訊
作者: AmigoSafin () 看板: R_Language 標題: [問題] uniform distribution畫scatterplot 時間: Tue Oct 30 08:27:08 2018 [問題類型]: 程式諮詢(我想用R 做某件事情,但是我不知道要怎麼用R 寫出來) [問題敘述]: 請簡略描述你所要做的事情,或是這個程式的目的 [Update] 我朋友說 marginal Y 不是 1/(2\theta) 苦手了 [Update] 不知道這個可行嗎? ### par(mfrow=c(2,2)) df.1 <- data.frame(x = rnorm(10000, 1, 1), y.1 = runif(10000, -0.1, 0.1)) p.1 <- ggplot(df.1, aes(x, y.1)) + geom_point() + theme_classic() ggExtra::ggMarginal(p.1, type = "histogram") df.2 <- data.frame(x = rnorm(10000, 1, 1), y.2 = runif(10000, -3, 3)) p.2 <- ggplot(df.2, aes(x, y.2)) + geom_point() + theme_classic() ggExtra::ggMarginal(p, type = "histogram") df.3 <- data.frame(x = rnorm(10000, 1, 1), y.3 = runif(10000, -5, 5)) p.3 <- ggplot(df.3, aes(x, y.3)) + geom_point() + theme_classic() ggExtra::ggMarginal(p.3, type = "histogram") df.4 <- data.frame(x = rnorm(10000, 1, 1), y.4 = runif(10000, -25, 25)) p.4 <- ggplot(df.4, aes(x, y.4)) + geom_point() + theme_classic() ggExtra::ggMarginal(p.4, type = "histogram") #### 大家好 想請教大家如果我已知marginal distribution of Y= 1/(2\theta) 題目請我: Graph an approximation to the marginal distribution of Y when \theta=0.1, \theta=3, \theta=5, \theta=25 Use n = 10000 for each \theta 我不太確定我有無理解錯誤 因為他是先給joint p.d.f. p(x,y)=1/[(2\theta)\sqrt(2\pi)] e^{(-(1/2)\times(y-x)^2} ,y \in R x \in [-\theta, \theta] 也給了X marginal density p_x(x)=1/2\theta 所以我直接算出Y的marginal 然後用以下的code(我在網路上找的) 想要畫出題目所要求的 但失敗了 其實我不是很明白題目想要做的 想請教各位高手 題目應該是要我畫出不同的\theta值下 Y的marginal 的變化 請問有大大願意幫忙嗎? 感激不盡 [程式範例]: par(mfrow=c(2,2)) py1 <- runif(10000, min = -0.1, max = 0.1) plot(py1, main="Marginal PDF of Y Scatterplot", pch=19) py2 <- runif(10000, min = -3, max = 3) plot(py2, main="Marginal PDF of Y Scatterplot", pch=19) py3 <- runif(10000, min = -5, max = 5) plot(py3, main="Marginal PDF of Y Scatterplot", pch=19) py4 <- runif(10000, min = -25, max = 25) plot(py4, main="Marginal PDF of Y Scatterplot", pch=19) -- -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 129.21.69.148 ※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1540859231.A.848.html ※ 編輯: AmigoSafin (129.21.69.148), 10/30/2018 08:45:53
andrew43: 題目有貼完整嗎? 10/30 10:13
AmigoSafin: 謝A大 剛我朋友說不是uniform 讓我來改 10/30 10:36
※ 編輯: AmigoSafin (8.41.66.201), 10/30/2018 11:03:09 ※ 編輯: AmigoSafin (8.41.66.201), 10/30/2018 11:29:33
andrew43: 隨意代入幾個數字,pdf就破1了。 10/30 11:41
哎 還是做不出來 我覺得我沒有搞懂題目要求的 所以code也做不出來 marginal Y 是joint p.d.f.對X的範圍做積分 我覺得我的code要往這個方向做 或者找出marginal Y和 E(Y|X)以及joint p.d.f.的關係 因為題目有說 用以上兩個pdf去做 但...想不出來>"< marginal Y=P(x,y)*P(x|y) 但p(x|y)沒有給 不好意思排版有點亂 還是希望有高手願意分享如果有用R的marginal plot 做過類似題目的 看看要怎麼做 通常答案都比想象的簡單 但自己就是做不出來 ※ 編輯: AmigoSafin (8.41.66.201), 10/30/2018 11:48:32
AmigoSafin: A大您是說我的code的pdf嗎?uniform 那個嗎? 10/30 11:50
andrew43: p(x,y)這個pdf確認有沒有貼正確。寫得嚴謹一點 10/30 11:55
※ 編輯: AmigoSafin (129.21.71.84), 11/01/2018 02:31:58
AmigoSafin: 已修正 謝謝~~ 11/01 02:32
andrew43: 參考 https://ideone.com/NW4ENl 11/01 10:07
AmigoSafin: 謝謝A大~ 11/02 21:56
andrew43: 我漏了句 library(plot3D) 11/02 22:14
andrew43: 推錯 11/02 22:14
andrew43: 啊沒推錯,請自行補上 library(plot3D) 11/02 22:14
AmigoSafin: 謝謝A大~我在找時間重新做一遍 又有其他工作追殺lol 11/03 04:17