R 用ggplot2叠加非对称t分布
我试图证明非对称t分布还是正态分布更适合某个数据集。在此过程中,我决定将拟合正态分布和拟合t分布叠加起来。对于正态分布,使用stat_fun没有问题:R 用ggplot2叠加非对称t分布,r,ggplot2,statistics,R,Ggplot2,Statistics,我试图证明非对称t分布还是正态分布更适合某个数据集。在此过程中,我决定将拟合正态分布和拟合t分布叠加起来。对于正态分布,使用stat_fun没有问题: x <- data.frame(rnorm(500)) names(x) <- c("test.data") ggplot(x,aes(x=test.data)) + stat_function(fun = dnorm, args=list(mean=mean(x$test.data,na.
x <- data.frame(rnorm(500))
names(x) <- c("test.data")
ggplot(x,aes(x=test.data)) +
stat_function(fun = dnorm, args=list(mean=mean(x$test.data,na.rm=TRUE),
sd=sd(x$test.data,na.rm=TRUE)), aes(colour = 'Normal')) +
geom_histogram(aes(y = ..density..), alpha = 0.4)
x试试这个:
library(ggplot2)
set.seed(1)
x <- data.frame(rt(5000,df=5,ncp=1)*10+7)
names(x) <- c("test.data")
# Define a Student t distribution with shape (nu) and location (mu)
dt2 <- function(x, mu, nu, df, ncp) {
dt((x-mu)/nu,df,ncp)/nu
}
ggplot(x,aes(x=test.data)) +
stat_function(fun = dt2, args=list(mu=7, nu=10, df=5, ncp=1),
aes(colour = 'Student t'), lwd=1) +
geom_histogram(aes(y = ..density..), bins=100, alpha = 0.4)
库(ggplot2)
种子(1)
x