[R] [effects] allEffects does not accept integer value for xlevels
Rolf Turner
r@turner @end|ng |rom @uck|@nd@@c@nz
Wed Sep 4 23:39:15 CEST 2019
I'm obviously not understanding something here, but it seems to me that
the conjecture
>>> It appears to me that the cause is buried in effects:::Analyze.model
>>>
>>> in or close to the the lines
>>>
>>> if (is.numeric(xlevels) & length(xlevels) == 1L) {
>>> levs <- xlevels
>>> for (name in focal.predictors) xlevels[[name]] <- levs
>>> }
>>>
>>>
>>>
>>> where xlevels -- while not being a list in this case --
>>> is subscripted by xlevels[[name]].
is not correct. There is no problem with using [[...]] to extract
entries from vectors. E.g.:
x <- 1:3
names(x) <- c("mung","gorp","clyde")
x[["gorp"]]
produces
[1] 2
cheers,
Rolf
On 5/09/19 2:19 AM, Fox, John wrote:
> Dear Gerrit,
>
> Yes, that appears to be a bug in Effect() -- too bad that it wasn't discovered earlier because a new version of the package was submitted yesterday, but thank you for the bug report.
>
> We'll fix the bug, but until then a work-around is to specify the number of levels for each numeric predictor, as in
>
> allEffects(mod.cowles, xlevels=list(neuroticism=4, extraversion=4))
>
> I used 4 levels here to verify that this works correctly, since 5 is the default.
>
> As well, although unrelated to this bug, you might take a look at predictorEffects(), which we recommend in preference to allEffects().
>
> Best,
> John
>
> --------------------------------------
> John Fox, Professor Emeritus
> McMaster University
> Hamilton, Ontario, Canada
> Web: socialsciences.mcmaster.ca/jfox/
>
>
>
>> -----Original Message-----
>> From: R-help [mailto:r-help-bounces using r-project.org] On Behalf Of Gerrit
>> Eichner
>> Sent: Wednesday, September 4, 2019 9:25 AM
>> To: r-help using r-project.org
>> Subject: [R] [effects] allEffects does not accept integer value for
>> xlevels
>>
>> Dear list,
>>
>> citing from allEffects' help page (of package effects 4.1-2):
>> "If xlevels=n is an integer, then each numeric predictor is represented by
>> n equally spaced values rounded to 'nice' numbers."
>>
>>
>> However, adapting the first example from allEffects' help page throws an
>> an error:
>>
>> mod.cowles <- glm(volunteer ~ sex + neuroticism*extraversion,
>> data=Cowles, family=binomial) allEffects(mod.cowles,
>> xlevels=5) Error in xlevels[[name]] : subscript out of bounds
>>
>>
>> It appears to me that the cause is buried in effects:::Analyze.model
>>
>> in or close to the the lines
>>
>> if (is.numeric(xlevels) & length(xlevels) == 1L) {
>> levs <- xlevels
>> for (name in focal.predictors) xlevels[[name]] <- levs
>> }
>>
>>
>>
>> where xlevels -- while not being a list in this case -- is subscripted by
>> xlevels[[name]].
>>
>> Is anyone aware of a workaround (without having to specify all numeric
>> predictors of the used model explicitly in a list and giving it to xlevels
>> when calling allEffects), and without having to write my own Analyze.model
>> function? ;-)
>>
>>
>> Thx in advance and best regards -- Gerrit
>>
>>
>>
>> PS: sessionInfo()
>>
>> R version 3.6.1 (2019-07-05)
>> Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64
>> (build 18362)
>>
>> Matrix products: default
>>
>> Random number generation:
>> RNG: Mersenne-Twister
>> Normal: Inversion
>> Sample: Rounding
>>
>> locale:
>> [1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252 [3]
>> LC_MONETARY=German_Germany.1252 LC_NUMERIC=C [5]
>> LC_TIME=German_Germany.1252
>>
>> attached base packages:
>> [1] stats graphics grDevices utils datasets methods base
>>
>> other attached packages:
>> [1] effects_4.1-2 carData_3.0-2
>>
>> loaded via a namespace (and not attached):
>> [1] Rcpp_1.0.2 lattice_0.20-38 MASS_7.3-51.4 grid_3.6.1
>>
>> [5] DBI_1.0.0 nlme_3.1-141 survey_3.36
>> estimability_1.3
>> [9] minqa_1.2.4 nloptr_1.2.1 Matrix_1.2-17 boot_1.3-23
>>
>> [13] splines_3.6.1 lme4_1.1-21.9001 survival_2.44-1.1 compiler_3.6.1
>> [17] colorspace_1.4-1 mitools_2.4 nnet_7.3-12
>>
>>
>> ---------------------------------------------------------------------
>> Dr. Gerrit Eichner Mathematical Institute, Room 212
>> gerrit.eichner using math.uni-giessen.de Justus-Liebig-University Giessen
>> Tel: +49-(0)641-99-32104 Arndtstr. 2, 35392 Giessen, Germany
>> http://www.uni-giessen.de/eichner
>>
>> ______________________________________________
>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-
>> guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Honorary Research Fellow
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276
More information about the R-help
mailing list