| Line 1... |
Line 1... |
| 1 |
% File src/library/stats/man/checkMFClasses.Rd
|
1 |
% File src/library/stats/man/checkMFClasses.Rd
|
| 2 |
% Part of the R package, https://www.R-project.org
|
2 |
% Part of the R package, https://www.R-project.org
|
| 3 |
% Copyright 1995-2007 R Core Team
|
3 |
% Copyright 1995-2019 R Core Team
|
| 4 |
% Distributed under GPL 2 or later
|
4 |
% Distributed under GPL 2 or later
|
| 5 |
|
5 |
|
| 6 |
\name{.checkMFClasses}
|
6 |
\name{.checkMFClasses}
|
| 7 |
\alias{.checkMFClasses}
|
7 |
\alias{.checkMFClasses}
|
| 8 |
\alias{.MFclass}
|
8 |
\alias{.MFclass}
|
| Line 11... |
Line 11... |
| 11 |
\description{
|
11 |
\description{
|
| 12 |
\code{.checkMFClasses} checks if the variables used in a predict
|
12 |
\code{.checkMFClasses} checks if the variables used in a predict
|
| 13 |
method agree in type with those used for fitting.
|
13 |
method agree in type with those used for fitting.
|
| 14 |
|
14 |
|
| 15 |
\code{.MFclass} categorizes variables for this purpose.
|
15 |
\code{.MFclass} categorizes variables for this purpose.
|
| - |
|
16 |
|
| - |
|
17 |
\code{.getXlevels()} extracts factor levels from \code{\link{factor}} or
|
| - |
|
18 |
\code{\link{character}} variables.
|
| 16 |
}
|
19 |
}
|
| 17 |
\usage{
|
20 |
\usage{
|
| 18 |
.checkMFClasses(cl, m, ordNotOK = FALSE)
|
21 |
.checkMFClasses(cl, m, ordNotOK = FALSE)
|
| 19 |
.MFclass(x)
|
22 |
.MFclass(x)
|
| 20 |
.getXlevels(Terms, m)
|
23 |
.getXlevels(Terms, m)
|
| 21 |
}
|
24 |
}
|
| 22 |
\arguments{
|
25 |
\arguments{
|
| 23 |
\item{cl}{a character vector of class descriptions to match.}
|
26 |
\item{cl}{a character vector of class descriptions to match.}
|
| 24 |
\item{m}{a model frame.}
|
27 |
\item{m}{a model frame (\code{\link{model.frame}()} result).}
|
| 25 |
\item{x}{any \R object.}
|
28 |
\item{x}{any \R object.}
|
| 26 |
\item{ordNotOK}{logical: are ordered factors different?}
|
29 |
\item{ordNotOK}{logical: are ordered factors different?}
|
| 27 |
\item{Terms}{a \code{terms} object.}
|
30 |
\item{Terms}{a \code{terms} object (\code{\link{terms.object}}).}
|
| 28 |
}
|
31 |
}
|
| 29 |
\details{
|
32 |
\details{
|
| 30 |
For applications involving \code{model.matrix} such as linear models
|
33 |
For applications involving \code{\link{model.matrix}()} such as linear models
|
| 31 |
we do not need to differentiate between ordered factors and factors as
|
34 |
we do not need to differentiate between \emph{ordered} factors and factors as
|
| 32 |
although these affect the coding, the coding used in the fit is
|
35 |
although these affect the coding, the coding used in the fit is
|
| 33 |
already recorded and imposed during prediction. However, other
|
36 |
already recorded and imposed during prediction. However, other
|
| 34 |
applications may treat ordered factors differently:
|
37 |
applications may treat ordered factors differently:
|
| 35 |
\code{\link[rpart]{rpart}} does, for example.
|
38 |
\code{\link[rpart]{rpart}} does, for example.
|
| 36 |
}
|
39 |
}
|
| 37 |
\value{
|
40 |
\value{
|
| - |
|
41 |
\code{.checkMFClasses()} checks and either signals an error calling
|
| - |
|
42 |
\code{\link{stop}()} or returns \code{\link{NULL}} invisibly.
|
| - |
|
43 |
|
| 38 |
\code{.MFclass} returns a character string, one of \code{"logical"},
|
44 |
\code{.MFclass()} returns a character string, one of \code{"logical"},
|
| 39 |
\code{"ordered"}, \code{"factor"}, \code{"numeric"}, \code{"nmatrix.*"}
|
45 |
\code{"ordered"}, \code{"factor"}, \code{"numeric"}, \code{"nmatrix.*"}
|
| 40 |
(a numeric matrix with a number of columns appended) or \code{"other"}.
|
46 |
(a numeric matrix with a number of columns appended) or \code{"other"}.
|
| 41 |
|
47 |
|
| 42 |
\code{.getXlevels} returns a named character vector, or \code{NULL}.
|
48 |
\code{.getXlevels} returns a named \code{\link{list}} of character
|
| - |
|
49 |
vectors, possibly empty, or \code{\link{NULL}}.
|
| - |
|
50 |
}
|
| - |
|
51 |
\examples{
|
| - |
|
52 |
sapply(warpbreaks, .MFclass) # "numeric" plus 2 x "factor"
|
| - |
|
53 |
sapply(iris, .MFclass) # 4 x "numeric" plus "factor"
|
| - |
|
54 |
|
| - |
|
55 |
mf <- model.frame(Sepal.Width ~ Species, iris)
|
| - |
|
56 |
mc <- model.frame(Sepal.Width ~ Sepal.Length, iris)
|
| - |
|
57 |
|
| - |
|
58 |
.checkMFClasses("numeric", mc) # nothing else
|
| - |
|
59 |
.checkMFClasses(c("numeric", "factor"), mf)
|
| - |
|
60 |
|
| - |
|
61 |
## simple .getXlevels() cases :
|
| - |
|
62 |
(xl <- .getXlevels(terms(mf), mf)) # a list with one entry " $ Species" with 3 levels:
|
| - |
|
63 |
stopifnot(exprs = {
|
| - |
|
64 |
identical(xl$Species, levels(iris$Species))
|
| - |
|
65 |
identical(.getXlevels(terms(mc), mc), xl[0]) # a empty named list, as no factors
|
| - |
|
66 |
is.null(.getXlevels(terms(x~x), list(x=1)))
|
| - |
|
67 |
})
|
| 43 |
}
|
68 |
}
|
| 44 |
\keyword{utilities}
|
69 |
\keyword{utilities}
|