如何叠加红线以显示拟合的t密度?

时间:2019-01-19 09:54:22

标签: r histogram probability density-plot

我正在RStudio中的一个小型QRM项目上工作,遇到了以下问题:当我想叠加一条红线以显示拟合的t密度时,出现以下错误消息:

"Error in plot.xy(xy.coords(x, y), type = type, ...) : 
  graphical parameter "lend" has the wrong length"

您在下面有我的代码。 您能帮我了解发生了什么吗?

谢谢!

# Fit a Student t distribution to djx
tfit <- fit.st(djx)

# Define tpars, nu, mu, and sigma
tpars <- tfit$par.ests
nu <- tpars[1]
mu <- tpars[2]
sigma <- tpars[3]

# Plot a histogram of djx
hist(djx, nclass = 20, probability = TRUE, ylim = range(0, 40))

# Compute the fitted t density at the values djx
yvals <- dt((djx - mu)/sigma, df = nu)/sigma

# Superimpose a red line to show the fitted t density
lines(djx, yvals, col = "red")

0 个答案:

没有答案