这是针对burr X类型分布的qqplot的程序。我知道编码是对的,但我不明白为什么我不能运行情节?
burrx.loglike <- function(params, x)
{
theta <- params[1]
sigma <- params[2]
n <- length(x)
if (theta <= 0 || sigma <= 0)
{
ans <- -Inf
}
else
{
ans <- (n*log(2) + sum(log(x)) + n*log(theta) - 2*n*log(sigma)
- sum(x^2)/sigma^2 + (theta-1)*sum(log(1-exp(-1*(x/sigma)^2))))
}
return(ans)
}
burrx.mle2 <- function(x, par0=c(1,1))
{
temp.mle <- optim(par0, burrx.loglike, x=x, method="Nelder-Mead", control=list(fnscale=-1))
return(temp.mle)
}
qqburrx <- function(x, theta, sigma, use.mle=TRUE)
{
# Check to see if we calculate the MLE.
if(use.mle == TRUE)
{
par0 <- c(theta,sigma)
temp.mle <- burrx.mle2(x, par0)
theta <- temp.mle$par[1]
sigma <- temp.mle$par[2]
}
# Sample Quantiles
x.sort <- sort(x)
# Theoretical Quantiles
n <- length(x)
i <- 1:n
x.quantiles <- qburrx(q=i/(n+1), theta=theta, sigma=sigma)
# Plot the data.
plot.min <- min(x.sort, x.quantiles)
plot.max <- max(x.sort, x.quantiles)
plot(x.quantiles, x.sort,
main="Burr type X Q-Q Plot\nNote: For the BurrX to be appropriate,data must fall near the 40deg line.",
xlab="Theoretical Quantiles", ylab="Sample Quantiles",
xlim=c(plot.min,plot.max), ylim=c(plot.min,plot.max))
# Add 45-degree line
line.coord <- c(plot.min, plot.max)
lines(line.coord, line.coord)
}
基本上我是r的初学者。也许我在输入参数时出现了一些错误。
答案 0 :(得分:0)
只需使用
qqburrx(1:2000,2,1,use.mle=TRUE)
根据您的参数将x更改为:b。