[R] QQ plot
Rolf Turner
rolf.turner at xtra.co.nz
Fri Feb 17 10:31:51 CET 2012
On 17/02/12 21:32, nandan amar wrote:
> Hello,
> I am having two data set original and predicted.
> I want to dind QQ-plot fot it.
> I tried in following manner :
>> qq(original~predicted)
> and error was :
>
> Error in qq.formula(o ~ p) : y must have exactly 2 levels
>
> There is an option "qtype" which dosent make any difference.
>
> What is the correct way for plotting QQ-plot or am I missing something.
To start with, you are missing telling us that the function qq() is
from the *lattice* package.
Secondly you are missing reading the error message. What
does it *say*? Think about it.
It says that (rather strangely, it seems to me) that the left hand
side of the formula must be a factor with two levels. Obviously
then you must combine your observations into a single vector
and create a factor indicating to which of the two samples each
entry of that vector belongs. Something like:
y <- c(original,predicted)
f <- factor(rep(c("o","p"),c(length(original),length(predicted))))
require(lattice)
print(qq(f ~ y))
Alternatively you could save hassle and use base graphics:
qqplot(original,predicted)
cheers,
Rolf Turner
More information about the R-help
mailing list