[Distr-commits] r955 - in branches/distr-2.6/pkg/distrMod: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Aug 10 17:35:38 CEST 2014
Author: ruckdeschel
Date: 2014-08-10 17:35:37 +0200 (Sun, 10 Aug 2014)
New Revision: 955
Modified:
branches/distr-2.6/pkg/distrMod/R/qqplot.R
branches/distr-2.6/pkg/distrMod/man/qqplot.Rd
Log:
[distrMod]:
-qqplot:
+ new method for y being of class "Estimate" (which could also be
seen as "fitted" objects...);
+ output for all methods is captured by invisible()
Modified: branches/distr-2.6/pkg/distrMod/R/qqplot.R
===================================================================
--- branches/distr-2.6/pkg/distrMod/R/qqplot.R 2014-08-10 15:22:52 UTC (rev 954)
+++ branches/distr-2.6/pkg/distrMod/R/qqplot.R 2014-08-10 15:35:37 UTC (rev 955)
@@ -216,7 +216,7 @@
}
}
}
- return(c(ret,qqb))
+ return(invisible(c(ret,qqb)))
})
## into distrMod
@@ -236,7 +236,36 @@
if(!is(yD,"UnivariateDistribution"))
stop("Not yet implemented.")
- return(do.call(getMethod("qqplot", signature(x="ANY", y="UnivariateDistribution")),
- args=mcl))
+ return(invisible(do.call(getMethod("qqplot", signature(x="ANY", y="UnivariateDistribution")),
+ args=mcl)))
})
+setMethod("qqplot", signature(x = "ANY",
+ y = "Estimate"), function(x, y,
+ n = length(x), withIdLine = TRUE, withConf = TRUE,
+ withConf.pw = withConf, withConf.sim = withConf,
+ plot.it = TRUE, xlab = deparse(substitute(x)),
+ ylab = deparse(substitute(y)), ...){
+
+ mc <- match.call(call = sys.call(sys.parent(1)))
+ if(missing(xlab)) mc$xlab <- as.character(deparse(mc$x))
+ if(missing(ylab)) mc$ylab <- as.character(deparse(mc$y))
+ mcl <- as.list(mc)[-1]
+
+ param <- ParamFamParameter(main=untransformed.estimate(y), nuisance=nuisance(y),
+ fixed=fixed(y))
+
+ es.call <- y at estimate.call
+ nm.call <- names(es.call)
+ PFam <- NULL
+ if("ParamFamily" %in% nm.call)
+ PFam <- eval(as.list(es.call)[["ParamFamily"]])
+ if(is.null(PFam))
+ stop("There is no object of class 'ProbFamily' in the call of 'x'")
+
+ PFam0 <- modifyModel(PFam, param)
+ mcl$y <- PFam0
+ return(invisible(do.call(getMethod("qqplot", signature(x="ANY", y="ProbFamily")),
+ args=mcl)))
+ })
+
Modified: branches/distr-2.6/pkg/distrMod/man/qqplot.Rd
===================================================================
--- branches/distr-2.6/pkg/distrMod/man/qqplot.Rd 2014-08-10 15:22:52 UTC (rev 954)
+++ branches/distr-2.6/pkg/distrMod/man/qqplot.Rd 2014-08-10 15:35:37 UTC (rev 955)
@@ -30,10 +30,16 @@
withConf.pw = withConf, withConf.sim = withConf,
plot.it = TRUE, xlab = deparse(substitute(x)),
ylab = deparse(substitute(y)), ...)
+\S4method{qqplot}{ANY,Estimate}(x, y,
+ n = length(x), withIdLine = TRUE, withConf = TRUE,
+ withConf.pw = withConf, withConf.sim = withConf,
+ plot.it = TRUE, xlab = deparse(substitute(x)),
+ ylab = deparse(substitute(y)), ...)
}
\alias{qqplot}
\alias{qqplot-methods}
\alias{qqplot,ANY,ProbFamily-method}
+\alias{qqplot,ANY,Estimate-method}
\alias{qqplot,ANY,UnivariateDistribution-method}
\arguments{
@@ -115,10 +121,14 @@
}
\description{
We generalize function \code{\link[stats:qqnorm]{qqplot}} from package \pkg{stats} to
- be applicable to distribution and probability model objects. In this context,
+ be applicable to distribution and probability model objects, as well as
+ to estimate objects. In this context,
\code{qqplot} produces a QQ plot of data (argument \code{x}) against
- a (model) distribution.
- Graphical parameters may be given as arguments to \code{qqplot}.
+ a (model) distribution. If the second argument is of class \code{'Estimate'},
+ \code{qqplot} looks at the \code{estimate.call}-slot and checks whether
+ it can use an argument \code{ParamFamily} to conclude on the model
+ distribution. Graphical parameters may be given as arguments to
+ \code{qqplot}.
}
\value{
As for function \code{\link[stats:qqnorm]{qqplot}} from package \pkg{stats}: a
@@ -143,6 +153,17 @@
the \code{\dots} argument, all arguments valid for
\code{signature(x = "ANY", y = "UnivariateDistribution")}
are also valid for this signature.}
+\item{qqplot}{\code{signature(x = "ANY", y = "Estimate")}:
+produces a QQ plot of a dataset \code{x} against the theoretical
+quantiles of the model distribution of the model that can be reconstructed
+from the estimator \code{y}; more specifically, it tries to get hand at the
+argument \code{'ParamFamily'} of the esimator's call; if this is available,
+internally this model is shifted to the estimated parameter by a call to
+\code{modifyModel}, and then this shifted model is used in a call to the
+\code{(x = "ANY", y = "UnivariateDistribution")}-method. Passed through
+the \code{\dots} argument, all arguments valid for
+\code{signature(x = "ANY", y = "UnivariateDistribution")}
+are also valid for this signature.}
}
}
@@ -162,8 +183,12 @@
intervals.
}
\examples{
-qqplot(r(Norm(15,sqrt(30)))(40), Chisq(df=15))
-qqplot(r(Norm(15,sqrt(30)))(40), NormLocationFamily())
+set.seed(123)
+x <- rnorm(40,mean=15,sd=30)
+qqplot(x, Chisq(df=15))
+qqplot(x, NormLocationScaleFamily())
+mlE <- MLEstimator(x, NormLocationScaleFamily())
+qqplot(x, mlE)
}
\keyword{hplot}
\keyword{distribution}
More information about the Distr-commits
mailing list