Displaying 20 results from an estimated 100 matches for "xlevel".
Did you mean:
level
2004 Jun 09
2
Specifying xlevels in effects library
...The effect is evaluated at the mean age.
> e
Sex effect
Sex
F M
43.33083 44.48531
>
> e$model.matrix
(Intercept) Age SexM
1 1 130.5859 0
23 1 130.5859 1
To evaluate the effect at Age=120 I tried:
e <-effect("Sex",mod,xlevels=list(Age=c(120)))
but the effect was still evaluated at 130.5859.
Is this an incorrect usage of xlevels?
Thanks, David
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 has...
2018 Mar 07
3
Names of variables needed in newdata for predict.glm
...= runif(200,0.5,10) )
mx <- glm( D ~ ns(x,knots=1:2,Bo=c(0,5)) + f:I(x^2) , offset=log(Y) , family=poisson, data=dd)
mi <- glm( D ~ ns(x,knots=1:2,Bo=c(0,5)) + f:I(x^2) + offset(log(Y)), family=poisson, data=dd)
attr(mx$terms,"dataClasses")
attr(mi$terms,"dataClasses")
mi$xlevels
mx$xlevels
...so far not quite there.
Regards,
Bendix Carstensen
Senior Statistician
Steno Diabetes Center
Clinical Epidemiology
Niels Steensens Vej 2-4
DK-2820 Gentofte, Denmark
b at bxc.dk
bendix.carstensen at regionh.dk
http://BendixCarstensen.com
________________________________
Denne e...
2018 Mar 08
0
Names of variables needed in newdata for predict.glm
Hi,
Some try:
> names(mi$xlevels)
[1] "f"
> all.vars(mi$formula)
[1] "D" "x" "f" "Y"
> names(mx$xlevels)
[1] "f"
> all.vars(mx$formula)
[1] "D" "x" "f"
When offset is indicated out of the formula, it does not work...
Marc
Le 0...
2017 Jun 15
2
duplicated factor labels.
...#39;ve been wondering about this for a while. I am sorry to ask for your
time, but can one of you help me understand this?
This concerns duplicated labels, not levels, in the factor function.
I think it is hard to understand that factor() fails, but levels()
after does not
> x <- 1:6
> xlevels <- 1:6
> xlabels <- c(1, NA, NA, 4, 4, 4)
> y <- factor(x, levels = xlevels, labels = xlabels)
Error in `levels<-`(`*tmp*`, value = if (nl == nL)
as.character(labels) else paste0(labels, :
factor level [3] is duplicated
> y <- factor(x, levels = xlevels)
> levels(y) &...
2011 Jun 14
1
Expand DF with all levels of a variable
...lt;- cut(a, breaks=c(0,2,6,9,12), right=FALSE )
(x <- data.frame(a, a.cut))
# In 'x' the level "[0,2)" is "missing".
AddMissingLevel <- function(xdf) {
xfac <- factor( c("[0,2)", "[2,6)", "[6,9)", "[9,12)") )
xlevels <- levels(xfac)
if(length(xlevels) != nlevels(factor(xdf$a.cut))) {
v <- setdiff(xlevels, factor(xdf$a.cut))
u <- data.frame(a = 0, a.cut = v)
x <- rbind(u, x)
}
return(x)
}
AddMissingLevel(x)
Does a more general approach exist, e.g. using "exp...
2012 Feb 25
1
Unexpected behavior in factor level ordering
..."), labels=c("Before Christ","After Christ"))
y <- rnorm(6)
m1 <- lm (y ~ xf )
plot(y ~ xf)
abline (m1)
## Just a little problem the line does not "go through" the box
## plot in the right spot because contrasts(xf) is 0,1 but
## the plot uses xf in 1,2.
xlevels <- levels(xf)
newdf <- data.frame(xf=xlevels)
ypred <- predict(m1, newdata=newdf)
##Watch now: the plot comes out "reversed", AC before BC
plot(ypred ~ newdf$xf)
## Ah. Now I see:
levels(newdf$xf)
## Why doesnt newdf$xf respect the ordering of the levels?
--
Paul E. Joh...
2019 Aug 30
3
inconsistent handling of factor, character, and logical predictors in lm()
...e discovered an inconsistency in how lm() and similar functions handle logical predictors as opposed to factor or character predictors. An "lm" object for a model that includes factor or character predictors includes the levels of a factor or unique values of a character predictor in the $xlevels component of the object, but not the FALSE/TRUE values for a logical predictor even though the latter is treated as a factor in the fit.
For example:
------------ snip --------------
> m1 <- lm(Sepal.Length ~ Sepal.Width + Species, data=iris)
> m1$xlevels
$Species
[1] "setosa"...
2018 Mar 31
1
Names of variables needed in newdata for predict.glm
....vars(mg$terms)
all.vars(mg$formula)
________________________________________
Fra: Marc Girondot <marc_grt at yahoo.fr>
Sendt: 8. marts 2018 06:26
Til: Bendix Carstensen; r-help at r-project.org
Emne: Re: [R] Names of variables needed in newdata for predict.glm
Hi,
Some try:
> names(mi$xlevels)
[1] "f"
> all.vars(mi$formula)
[1] "D" "x" "f" "Y"
> names(mx$xlevels)
[1] "f"
> all.vars(mx$formula)
[1] "D" "x" "f"
When offset is indicated out of the formula, it does not work...
Marc
Le 0...
2008 Jun 12
3
Problem with Freq function {prettyR}
Dear list,
I have a problem with freq from prettyR.
Please have a look at my syntax with a litte example:
library(prettyR)
#Version 1
test.df<-data.frame(q1=sample(1:4,8,TRUE), gender=sample(c("f","m"),8,TRUE))
test.df
freq(test.df) #No error message
#Version 2
test.df<-data.frame(gender=sample(c("f","m"),8,TRUE), q1=sample(1:4,8,TRUE))
test.df
2019 Aug 31
2
inconsistent handling of factor, character, and logical predictors in lm()
...ould argue about what's the better approach but not about what lm() does. BTW, I prefer treating a logical predictor as a factor because the predictor is essentially categorical.
>
> I note that the use factors and characters, doesn't necessarily
> produce consistent output, for $xlevels.
> (Because factors can have their levels re-ordered).
Again, this misses the point: Both factors and character predictors produce elements in $xlevels; logical predictors do not, even though they are treated in the model as factors. That factors have levels that aren't necessarily ordered...
2012 Jun 05
1
model.frame and predvars
I was looking at how the model.frame method for lm works and comparing
it to my own for coxph.
The big difference is that I try to retain xlevels and predvars
information for a new model frame, and lm does not.
I use a call to model.frame in predict.coxph, which is why I went that
route, but never noted the difference till now (preparing for my course
in Nashville).
Could someone shed light on the rationale for non-preservation?
Terry...
2004 Jun 14
0
inheritance problem in multcomp package (PR#6978)
...to mathematical function
> names(aovmod)
[1] "coefficients" "residuals" "effects" "rank"
[5] "fitted.values" "assign" "qr" "df.residual"
[9] "contrasts" "xlevels" "call" "terms"
[13] "model"
> names(lmmod)
[1] "coefficients" "residuals" "effects" "rank"
[5] "fitted.values" "assign" "qr"...
2011 Dec 26
2
glm predict issue
...d 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,
Best regards,
Giova...
2014 Jan 03
1
Tab formatting in dummy.coef.R
...err <- attr(Terms,"specials")$Error - 1
tl <- attr(Terms, "term.labels")[-err]
int <- attr(Terms, "intercept")
facs <- attr(Terms, "factors")[-c(1,1+err), -err, drop=FALSE]
vars <- rownames(facs)
xl <- attr(object, "xlevels")
if(!length(xl)) { # no factors in model
return(as.list(coef(object)))
}
nxl <- setNames(rep.int(1, length(vars)), vars)
tmp <- unlist(lapply(xl, length))
nxl[names(tmp)] <- tmp
lterms <- apply(facs, 2L, function(x) prod(nxl[x > 0]))
nl <-...
2017 Jun 15
0
duplicated factor labels.
...sorry to ask for your
> time, but can one of you help me understand this?
> This concerns duplicated labels, not levels, in the factor function.
> I think it is hard to understand that factor() fails, but levels()
> after does not
>> x <- 1:6
>> xlevels <- 1:6
>> xlabels <- c(1, NA, NA, 4, 4, 4)
>> y <- factor(x, levels = xlevels, labels = xlabels)
> Error in `levels<-`(`*tmp*`, value = if (nl == nL)
> as.character(labels) else paste0(labels, :
> factor level [3] is duplicated
>> y &...
2005 Aug 15
2
stepAIC invalid scope argument
...~ x2 + x3 + x1, data = df, drop.unused.levels = TRUE)
11: eval(expr, envir, enclos)
10: eval(mf, parent.frame())
9: lm(formula = y ~ x2 + x3 + x1, data = df, method = "model.frame")
8: eval(expr, envir, enclos)
7: eval(fcall, env, parent.frame())
6: model.frame.lm(fob, xlev = object$xlevels)
5: model.frame(fob, xlev = object$xlevels)
4: stats:::add1.lm(object, scope = scope, scale = scale)
3: addterm.lm(fit, scope$add, scale = scale, trace = max(0, trace - 1), k = k, ...)
2: addterm(fit, scope$add, scale = scale, trace = max(0, trace - 1), k = k, ...)
1: stepAIC(mid, scope = lis...
2002 Jan 22
1
documentation and plotting with lqs
...e package "lqs"?
> names(slts)
[1] "crit" "sing" "coefficients" "bestone"
[5] "fitted.values" "residuals" "scale" "terms"
[9] "call" "xlevels" "model"
Also is there any plotting available for lqs?
And trying plot on the lqs object doesn't work:
> data(stackloss)
> set.seed(123)
> examplelqs <- lqs(stack.loss ~ ., data = stackloss)
> plot (examplelqs)
Error in as.double.default(x) : (list) objec...
2009 Feb 26
1
using predict method with an offset
...n predictor + offset :
longer object length is not a multiple of shorter object length
When predict used with model for which offset was defined in
the formula, an error occurs
predict( c1f.glm, newdata = nd )
Error in model.frame.default(Terms, newdata, na.action = na.action,
xlev = object$xlevels) :
variable lengths differ (found for 'offset(q25)')
even if a column for offset is included in newdata,
ndf <- cbind( nd, "offset(q25)" = rep( qlogis(0.25), length(cc) ) )
predict( c1f.glm, newdata = ndf )
Error in model.frame.default(Terms, newdata, na.action = na.acti...
2003 Apr 23
3
regression parms var-cov matrix
...ression analysis in R. Using "names( blah.lm )"
in R yields
[1] "coefficients" "residuals" "effects" "rank"
[5] "fitted.values" "assign" "qr" "df.residual"
[9] "xlevels" "call" "terms" "model"
In Splus, the same command yields
[1] "coefficients" "residuals" "fitted.values" "effects"
[5] "R" "rank" "assign&quo...