簡體   English   中英

在R中繪制正常,左和右傾斜分布

[英]Plot normal, left and right skewed distribution in R

我想創建3個圖表用於說明目的: - 正態分布 - 右傾斜分布 - 左偏斜分布

這應該是一個簡單的任務,但我發現只有這個鏈接 ,它只顯示正態分布。 我該怎么辦?

如果你不太正常,那么我建議你使用beta分布,它可以是對稱的,右傾斜的,或者根據形狀參數左傾斜。

hist(rbeta(10000,5,2))
hist(rbeta(10000,2,5))
hist(rbeta(10000,5,5))

最后我得到了它的工作,但在你的幫助下,但我依靠這個網站

 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)

在此輸入圖像描述

這也是一個有效的解決方案:

curve(dbeta(x,8,4),xlim=c(0,1))
title(main="posterior distrobution of p")

只需使用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。 例子

## 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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM