I want to create 3 plots for illustration purposes: - normal distribution - right skewed distribution - left skewed distribution
我想创建3个图来说明:-正态分布-右偏态分布-左偏态分布
This should be an easy task, but I found only this link, which only shows a normal distribution. How do I do the rest?
这应该是一个简单的任务,但是我只找到了这个链接,它只显示了一个正态分布。剩下的怎么办呢?
3 个解决方案
#1
22
If you are not too tied to normal, then I suggest you use beta distribution which can be symmetrical, right skewed or left skewed based on the shape parameters.
如果你不太受正常的束缚,那么我建议你使用对称的分布,根据形状参数可以是右偏或左偏。
hist(rbeta(10000,5,2))
hist(rbeta(10000,2,5))
hist(rbeta(10000,5,5))
#2
11
Finally I got it working, but with both of your help, but I was relying on this site.
最后,我得到了它的工作,但是在你们的帮助下,但是我依赖这个网站。
N <- 10000
x <- rnbinom(N, 10, .5)
hist(x,
xlim=c(min(x),max(x)), probability=T, nclass=max(x)-min(x)+1,
col='lightblue', xlab=' ', ylab=' ', axes=F,
main='Positive Skewed')
lines(density(x,bw=1), col='red', lwd=3)
This is also a valid solution:
这也是一个有效的解决办法:
curve(dbeta(x,8,4),xlim=c(0,1))
title(main="posterior distrobution of p")
#3
8
just use fGarch
package and these functions:
只需使用fGarch包及以下功能:
dsnorm(x, mean = 0, sd = 1, xi = 1.5, log = FALSE)
psnorm(q, mean = 0, sd = 1, xi = 1.5)
qsnorm(p, mean = 0, sd = 1, xi = 1.5)
rsnorm(n, mean = 0, sd = 1, xi = 1.5)
** mean, sd, xi location parameter mean, scale parameter sd, skewness parameter xi. Examples
**均值、sd、xi位置参数均值、尺度参数sd、偏度参数xi。例子
## snorm -
# Ranbdom Numbers:
par(mfrow = c(2, 2))
set.seed(1953)
r = rsnorm(n = 1000)
plot(r, type = "l", main = "snorm", col = "steelblue")
# Plot empirical density and compare with true density:
hist(r, n = 25, probability = TRUE, border = "white", col = "steelblue")
box()
x = seq(min(r), max(r), length = 201)
lines(x, dsnorm(x), lwd = 2)
# Plot df and compare with true df:
plot(sort(r), (1:1000/1000), main = "Probability", col = "steelblue",
ylab = "Probability")
lines(x, psnorm(x), lwd = 2)
# Compute quantiles:
round(qsnorm(psnorm(q = seq(-1, 5, by = 1))), digits = 6)
#1
22
If you are not too tied to normal, then I suggest you use beta distribution which can be symmetrical, right skewed or left skewed based on the shape parameters.
如果你不太受正常的束缚,那么我建议你使用对称的分布,根据形状参数可以是右偏或左偏。
hist(rbeta(10000,5,2))
hist(rbeta(10000,2,5))
hist(rbeta(10000,5,5))
#2
11
Finally I got it working, but with both of your help, but I was relying on this site.
最后,我得到了它的工作,但是在你们的帮助下,但是我依赖这个网站。
N <- 10000
x <- rnbinom(N, 10, .5)
hist(x,
xlim=c(min(x),max(x)), probability=T, nclass=max(x)-min(x)+1,
col='lightblue', xlab=' ', ylab=' ', axes=F,
main='Positive Skewed')
lines(density(x,bw=1), col='red', lwd=3)
This is also a valid solution:
这也是一个有效的解决办法:
curve(dbeta(x,8,4),xlim=c(0,1))
title(main="posterior distrobution of p")
#3
8
just use fGarch
package and these functions:
只需使用fGarch包及以下功能:
dsnorm(x, mean = 0, sd = 1, xi = 1.5, log = FALSE)
psnorm(q, mean = 0, sd = 1, xi = 1.5)
qsnorm(p, mean = 0, sd = 1, xi = 1.5)
rsnorm(n, mean = 0, sd = 1, xi = 1.5)
** mean, sd, xi location parameter mean, scale parameter sd, skewness parameter xi. Examples
**均值、sd、xi位置参数均值、尺度参数sd、偏度参数xi。例子
## snorm -
# Ranbdom Numbers:
par(mfrow = c(2, 2))
set.seed(1953)
r = rsnorm(n = 1000)
plot(r, type = "l", main = "snorm", col = "steelblue")
# Plot empirical density and compare with true density:
hist(r, n = 25, probability = TRUE, border = "white", col = "steelblue")
box()
x = seq(min(r), max(r), length = 201)
lines(x, dsnorm(x), lwd = 2)
# Plot df and compare with true df:
plot(sort(r), (1:1000/1000), main = "Probability", col = "steelblue",
ylab = "Probability")
lines(x, psnorm(x), lwd = 2)
# Compute quantiles:
round(qsnorm(psnorm(q = seq(-1, 5, by = 1))), digits = 6)