qqplot would not graph. Error in converting dataframe into a vector

Viewed 56
data = read.csv("HeatofCombustion.csv", header=T) 
attach(data)
library(lattice)
x = data[ , "Qc"]
qqplot(x=qexp(x), y=data, main="Exponential Q-Q Plot",
       xlab="Theoretical Quantiles", ylab= "Your Data Quantiles")

Errors:

Error in `[.data.frame`(x, order(x, na.last = na.last, decreasing = decreasing)) : 
  undefined columns selected
In addition: Warning messages:
1: In qexp(x) : NaNs produced
2: In xtfrm.data.frame(x) : cannot xtfrm data frames

Why does this happen? I thought I have already converted dataframe into a vector by using x = data[ , "Qc"] I am trying to graph an exponential Q-Q plot in R. Many thanks.

Data view: Image of the data Qc, E02 and Fuel Mass ratio

Actual data for variable Qc (heat capacity):

Qc = c(17.39, 6.68, 23.31, 47.74, 
19.53, 45.8, 26.75, 26.86, 29.62, 28.39, 34.21, 43.65, 24.13, 
31.37, 25.42, 27.91, 30.9, 31.07, 38.35, 29.18, 26.45, 25.27, 
26.92, 24.97, 39.84, 29.38, 31.53, 31.06, 18.71, 29.92, 32.5, 
31.07, 31.48, 31.23, 31.15, 31.65, 26.03, 28.61, 30.65, 34.39, 
30.28, 30.63, 34.89, 26.5, 29.59, 29.06, 26.54, 25.92, 33.64)

1 Answers

This function is perhaps a little too fancy, but should do what you want. (The qfun.args/do.call nonsense is to allow you to include extra shape parameters for the target distribution, which doesn't seem to be necessary here — because of the way that Q-Q plots are assessed, changes in scale and location parameters don't affect their appearance much.)

It's basically just encapsulating and generalizing the chi-squared example shown in ?qqplot ... to generate the x-variable, you use ppoints() to generate an appropriate set of equally spaced quantile points, then the quantile (q*) function of your target distribution to convert those to theoretical quantiles.

qfun <- function(y, qfun = qnorm, qfun.args = NULL, ...) {
    n <- length(y)
    qqplot(do.call(qfun,
                   c(list(ppoints(n)), qfun.args)),
           xlab = "",
           y, ...)
    qqline(y,
           distribution = function(p) do.call(qfun, c(list(p), qfun.args)),
           probs = c(0.1, 0.6), col = 2)
}

Try it out:

qfun(Qc, main = "Gaussian")
qfun(Qc, qexp, main = "Exponential")

library(VGAM)
qfun(Qc, qgumbel, main = "Gumbel")

enter image description here

Related