Benjamin Dickgiesser
2006-Oct-25 17:47 UTC
[R] Drawing a reference line for a qqplot with reference to Weibull distribution
Hi, I'm trying to create a qqplot with reference to a Weibull distribution including a reference line. This is my current code: lights.data <- scan("lights.dat") #Generate Weibull quantiles prob.grid <- ppoints(length(lights.data)) prob.quant <- qweibull(prob.grid , 1.5,4) #Draw QQ plot qqplot(prob.quant,lights.data) #add red reference line qqline(lights.data,col = 2) Obviously the reference line isn't correct this way. How would I go about fitting one? I am grateful for any help, Ben
Richard M. Heiberger
2006-Oct-25 20:37 UTC
[R] Drawing a reference line for a qqplot with reference to Weibull distribution
The reference line needs to know the distribution. The qqline function has the normal built in. You need to write something similar. qqline puts a line through the quartiles. I extended that to the t-distribution in the qqline.t function appended here. You need to do something similar to get Weibull or any other distribution recognized. ## qqline.t is based on qqline with an additional, optional argument. ## When df is not missing, the function draws a line through the ## quartiles of a t distribution. When df is missing, qqline.t is ## identical to the original qqline and produces the line through the ## quartiles of the normal. qqline.t <- function(x, df, ...) { data.quartiles <- quantile(x, c(0.25, 0.75), na.rm = T) norm.quartiles <- if (missing(df)) qnorm(c(0.25, 0.75)) else qt(c(0.25, 0.75), df=df) b <- (data.quartiles[2] - data.quartiles[1]) / (norm.quartiles[2] - norm.quartiles[1]) a <- data.quartiles[1] - norm.quartiles[1] * b abline(a, b, ...) ans <- as.vector(c(a, b)) names(ans) <- c("intercept", "slope") invisible(ans) }