作者: 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://webptt.com/cn.aspx?n=bbs/R_Language/M.1540859231.A.848.html
※ 编辑: AmigoSafin (129.21.69.148), 10/30/2018 08:45:53
1F:→ andrew43: 题目有贴完整吗? 10/30 10:13
2F:→ 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
3F:→ 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
4F:→ AmigoSafin: A大您是说我的code的pdf吗?uniform 那个吗? 10/30 11:50
5F:→ andrew43: p(x,y)这个pdf确认有没有贴正确。写得严谨一点 10/30 11:55
※ 编辑: AmigoSafin (129.21.71.84), 11/01/2018 02:31:58
6F:→ AmigoSafin: 已修正 谢谢~~ 11/01 02:32
8F:→ AmigoSafin: 谢谢A大~ 11/02 21:56
9F:→ andrew43: 我漏了句 library(plot3D) 11/02 22:14
10F:→ andrew43: 推错 11/02 22:14
11F:→ andrew43: 啊没推错,请自行补上 library(plot3D) 11/02 22:14
12F:→ AmigoSafin: 谢谢A大~我在找时间重新做一遍 又有其他工作追杀lol 11/03 04:17