Displaying 20 results from an estimated 66 matches for "xlev".
Did you mean:
xdev
2018 Mar 24
1
Function 'factor' issues
I am trying once again.
By just changing
f <- match(xlevs[f], nlevs)
to
f <- match(xlevs, nlevs)[f]
, function 'factor' in R devel could be made more consistent and back-compatible. Why not picking it?
--------------------------------------------
On Sat, 25/11/17, Suharto Anggono Suharto Anggono <suharto_anggono at yahoo.com> wrote:
S...
2024 Sep 20
1
model.matrix() may be misleading for "lme" models
...round this problem by defining a model.matrix.lme()
method, which is used internally in the car package but not registered:
--------- snip ---------
model.matrix.lme <- function(object, ...){
data <- object$data
contrasts <- object$contrasts
if (length(contrasts) == 0) {
xlev <- NULL
} else {
xlev <- vector(length(contrasts), mode="list")
names(xlev) <- names <- names(contrasts)
for (name in names){
xlev[[name]] <- rownames(contrasts[[name]])
}
}
if (is.null(data)){
NextMethod(formula(object), data=eval(...
2013 Apr 05
2
model.frame: object is not a matrix
...ade ago there was a problem with model.frame when the variable
names were long:
https://stat.ethz.ch/pipermail/r-help/2002-August/024492.html
I have similar symptoms with R 2.15.3 on Windows 7:
Browse[2]> x <- model.matrix(formula(myform), p$data)
Error in model.frame.default(object, data, xlev = xlev) (from mice.R#601) :
object is not a matrix
My attempt at a work-around did not help:
Browse[2]> x <- model.matrix(formula(myform), as.matrix(p$data))
Error in model.frame.default(object, data, xlev = xlev) (from mice.R#601) :
'data' must be a data.frame, not a matrix or...
2017 Nov 25
0
Function 'factor' issues
...devel, I saw attempts to speed up subsetting and 'match', and to cache results of conversion of small nonnegative integers to character string. That's good.
I am sorry for pushing, still.
Is the partial new behavior of function 'factor' with respect to NA really worthy?
match(xlevs, nlevs)[f] looks nice, too.
- Using
f <- match(xlevs, nlevs)[f]
instead of
f <- match(xlevs[f], nlevs)
for remapping
- Remapping only if length(nlevs) differs from length(xlevs)
Applying changes similar to above to function 'levels<-.factor' will not change 'levels<-.fact...
2003 Mar 26
5
predict (PR#2686)
...ata.frame( y=runif( 3), disc=factor( c( 'cat', 'dog',
'cat'), levels=c( 'cat', 'dog', 'earwig')))
test> lm.predbug.2_ lm( y~disc, data=scrunge.data.2)
test> predict(lm.predbug.2, newdata=scrunge.data.2)
Error in model.frame.default(object, data, xlev = xlev) :
factor disc has new level(s) earwig
A cure for this seems to be to add the commented line below towards the end
of `model.frame.default':
<<...>>
if (length(xlev) > 0) {
for (nm in names(xlev)) if (!is.null(xl <- xlev[[nm]])) {...
2024 Sep 21
1
model.matrix() may be misleading for "lme" models
Dear list members,
After further testing, I found that the following simplified version of
model.matrix.lme(), which omits passing xlev to the default method, is
more robust. The previous version generated spurious warnings in some
circumstances.
model.matrix.lme <- function(object, ...){
data <- object$data
if (is.null(data)){
NextMethod(formula(object), data=eval(object$call$data),
contrasts.a...
2009 Sep 28
1
model.matrix troubles with AlgDesign
...e in the global
environment and variables that are in the data frame given with the formula,
but not calculation results from the intermediate calling environment.
Results from traceback():
9: nrow(aus)
8: eval(expr, envir, enclos)
7: eval(predvars, data, env)
6: model.frame.default(object, data, xlev = xlev)
5: model.frame(object, data, xlev = xlev)
4: model.matrix.default(frml, data, ...)
3: model.matrix.formula(1:nrow(aus) ~ ., data = aus)
2: model.matrix(1:nrow(aus) ~ ., data = aus)
1: fac.design(nlevels = c(2, 6, 2))
If I reset model.matrix.formula to model.matrix.default, the problem
disa...
2010 Aug 15
0
unexpected behaviour with sparse.model.matrix
Hi,
I'm trying to get sparse.model.matrix to retain unused levels. I can't
seem to get this working through the most obvious routes such as
specifying drop.unused.levels = FALSE in the model.frame or trying to
pass all levels in xlev,which is an argument to sparse.model.matrix
(see code below).
Any help would be gratefully received.
Cheers,
Jarrod
fac<-factor(rep(1:10,10), levels=1:100)
mf<-model.frame(~fac, drop.unused.levels = TRUE)
mf2<-model.frame(~fac, drop.unused.levels = FALSE)
dim(model.matrix(~fac, mf)...
2011 Mar 30
1
Using xlevels
I'm working on predict.survreg and am confused about xlevels.
The model.frame method has the argument, but none of the standard
methods (model.frame.lm, model.frame.glm) appear to make use of it.
The documentation for model.matrix states:
xlev: to be used as argument of model.frame if data has no "terms"
attribute.
But the terms attribute ha...
2004 Jan 30
0
Two apparent bugs in aov(y~ *** -1 + Error(***)), with suggested (PR#6510)
...lt;- "model.frame"
mf <- eval(lmcall, parent.frame())
xvars <- as.character(attr(Terms, "variables"))[-1]
if ((yvar <- attr(Terms, "response")) > 0)
xvars <- xvars[-yvar]
if (length(xvars) > 0) {
xlev <- lapply(mf[xvars], levels)
xlev <- xlev[!sapply(xlev, is.null)]
} else xlev <- NULL
resp <- model.response(mf)
qtx <- model.matrix(Terms, mf, contrasts)
cons <- attr(qtx, "contrasts")
dnx <- colnames(qtx)
a...
2002 Oct 24
3
model.matrix (via predict) (PR#2206)
...incorrect fitted values in version 1.5.1 and an
error in 1.6.0
Error in "contrasts<-"(*tmp*, value = "contr.treatment") :
contrasts apply only to factors
In addition: Warning message:
variable ihalf is not a factor in: model.frame.default(object, data, xlev =
xlev)
The problem in 1.5.1 seems to be model.matrix return inconsistently ordered
interaction terms. There are abviously several work arounds.
### Start of example
dfr <- expand.grid(i=0:154,j=0:154)
dfr <- dfr[with(dfr,i+j<=154),]
dfr$logj <- with(dfr,log(j+0.5))
dfr$jmin6 <-...
2017 Oct 21
0
Function 'factor' issues
My idea (like in https://bugs.r-project.org/bugzilla/attachment.cgi?id=1540 ):
- For remapping, use
f <- match(xlevs, nlevs)[f]
instead of
f <- match(xlevs[f], nlevs)
(I have mentioned it).
- Remap only if length(nlevs) differs from length(xlevs) .
On use of 'order' in function 'factor' in R devel, factor.Rd still says 'sort.list' in "Details" section.
My comments on the p...
2004 Feb 02
0
Two apparent bugs in aov(y~ *** -1 + Error(***)), with (PR#6520)
...gt; mf <- eval(lmcall, parent.frame())
> xvars <- as.character(attr(Terms, "variables"))[-1]
> if ((yvar <- attr(Terms, "response")) > 0)
> xvars <- xvars[-yvar]
> if (length(xvars) > 0) {
> xlev <- lapply(mf[xvars], levels)
> xlev <- xlev[!sapply(xlev, is.null)]
> } else xlev <- NULL
> resp <- model.response(mf)
> qtx <- model.matrix(Terms, mf, contrasts)
> cons <- attr(qtx, "contrasts")
> dnx...
2002 Dec 19
0
Ongoing unhappiness with NA and factor behavior of distributed lm/predict.lm
...ot;),levels=c("blue","green","yellow"))))
y x1 x2
1 0.90 1 blue
2 2.05 2 blue
3 3.02 3 green
4 NA 4 green
5 5.20 NA green
> fit<-lm(y~x1+x2,data=data,na.action=na.exclude)
> predict(fit,data)
Error in model.frame.default(object, data, xlev = xlev) :
factor x2 has new level(s) yellow
Interpretation:
Since level "yellow" was not used (is in some sense missing) in the data, predict.lm blocks. This should not happen. Maybe a warning should be given. But predict.lm should not quit with error.
Here is problem 3:
> print(...
2000 Dec 05
1
Inconsistency, possibly a bug? (PR#758)
...> fit.lm <- lm(y ~ x + z, data=xyz, subset=(z != "C"))
> fit.glm <- glm(y ~ x + z, family=gaussian, data=xyz, subset=(z != "C"))
> zz <- z[1:10]
> xx <- rnorm(10)
> predict(fit.lm,data.frame(x=xx,z=zz))
Error in model.frame.default(formula, data, xlev = xlev) :
factor z has new level(s) C
> predict(fit.glm,data.frame(x=xx,z=zz))
1 2 3 4 5 6
2.570970 -18.007372 18.108771 12.498562 9.566029 10.518460
7 8 9 10
-9.132206 11.440242 -16.054621 -3.0...
2003 Dec 17
6
Factor names & levels
When I alter the levels of a factor, why does it alter the names too?
f <- factor(c(A="one",B="two",C="one",D="one",E="three"),
levels=c("one","two","three"))
names(f)
-- gives [1] "A" "B" "C" "D" "E"
levels(f) <-
2011 Dec 26
2
glm predict issue
...nd then I would like to predict the response variable (Throughput) for unseen factor levels.
When I try to predict I get the following error:
> throughput.pred <- predict(throughput.fit,experiments,type="response")
Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) :
factor 'No_databases' has new level(s) 200, 400, 600, 800, 1000
Of course these are new factor levels, it is exactly what I am trying to achieve i.e. extrapolate the values of Throughput.
Can anyone please advice? Below I include all details.
Thanks in advance,
Bes...
2001 Jun 21
0
factors in model.frame.default
...Send mail to mime@docserver.cac.washington.edu for more info.
--1133331701-635408861-993124011=:10449
Content-Type: TEXT/PLAIN; charset=US-ASCII
I'm not sure if the warning messages
Warning messages:
1: variable 67 is not a factor in: model.frame.default(Terms, newdata,
na.action = act, xlev = attr(object,
2: variable 70 is not a factor in: model.frame.default(Terms, newdata,
na.action = act, xlev = attr(object,
3: variable 71 is not a factor in: model.frame.default(Terms, newdata,
na.action = act, xlev = attr(object,
reported by model.frame.default (thru predict.rpart)
are corr...
2003 Mar 26
2
predict (PR#2685)
....data)
# terms will be re-ordered
test> predict( lm.bug, scrunge.data)
Error in "contrasts<-"(*tmp*, value = "contr.treatment") :
contrasts apply only to factors
In addition: Warning message:
variable discrete is not a factor in: model.frame.default(object, data, xlev
= xlev)
This actually turns out to be a bug in `model.frame.default', to do with an
inconsistency between `predvars' and `vars' when `model.frame.default' is
called inside `predict'. AFAICS it can be fixed by including the commented
line below in `model.frame.default':...
2018 Feb 24
3
Regression Tree Questions
....
1. I'm using a regression tree to predict the selling prices of 10 new records (homes). The following code is resulting in an error message: pred <- predict(model, newdata = outOfSample[, -6])
The error message is:
Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = attr(object, :
factor Sq. Feet has new levels 1375, 1421, 1547, 1621, 1868, 2211, 2265, 2530, 2672, 3365
Does anybody know what is causing this? I've pasted a snippet of my original dataset (Crankshaw) and my out-of-sample dataset below. Below it appears all code which I entered leading...