[R] Remove all factor levels from an R dataframe

2020-11-09 Thread John
Hi,

   I would like to sort the following simple dataframe by "year"
(characters), but the factor structure prevents me from doing so. How can I
remove the factor structure? Thanks!

> df1
  year  country
4 2007 Asia; survey
5 2010 8 countries in E/SE Asia
6 2015Ghana
7
8 2000  US?
> str(df1)
'data.frame': 5 obs. of  2 variables:
 $ year   : Factor w/ 9 levels "2017","2016",..: 4 5 3 6 7
 $ country: Factor w/ 9 levels "Euro Area\\newline Testing the MP
performance of the Euro Area",..: 4 5 6 7 8
> df1[order(-year), ]
Error in order(-year) : object 'year' not found

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] paste() turns list element character vector into deparsed expression. Why?

2020-11-09 Thread Ege Rubak
I agree that it is weird, but I don't see that it is easy to coerce a
list to character of the same structure. In my example (missing the
trailing parenthesis, sorry...) the input is a length two list and the
output is a length two character vector, so in the general case the
rationale seems to be that the output should have the same length as
the input, which makes sense. What specific length two character vector
would you suggest for this example? Would you paste the elements
together with an arbitrary separator of your choice?

In the more general case these elements could be anything: numbers,
characters, functions or even new lists, and I agree that it most often
probably just would make most sense to return an error. Actually I
think it is a bad idea to call `as.character()` on a list in the first
place. Logically this doesn't make much sense. If you want to use
`as.charater()` on each element in the list you should use `lapply()`.

If you really insist on representing a complicated structure as a list
as character I don't see any better general way to represent the list
as character than what R currently does.

Kind regards,
Ege


On Mon, 2020-11-09 at 12:58 +, Boris Steipe wrote:
> Thanks Ege -
> 
> That narrows it down, ... but it's still weird.
> 
> My issue is that I don't consider "c(\"xyz\", \"uvw\")" to be a valid
> character representation of a list. c() is a function, so "c(\"xyz\",
> \"uvw\")" is a string representation of a function call that could
> be  eval(parse(...))'ed into a two-element vector ... but considering
> this a coercion seems really weird.
> 
> What do I think your example should return? An object of the same
> general structure as the input, with non-character components coerced
> to character. And if that's not possible because there is no good
> character representation (e.g. if its a closure) than it should
> return an error. 
> 
> 
> Cheers,
> Boris
> 
>  
> 
> 
> > On 2020-11-09, at 22:24, Ege Rubak  wrote:
> > 
> > EXTERNAL EMAIL:  Treat content with extra caution.
> > 
> > I think `paste()` just calls `as.character()` on each input
> > argument
> > and then collapses things afterwards. Calling `as.character()` on
> > the
> > first input argument generates exactly the output you show (and
> > didn't
> > expect) and there is nothing to collapse. So changing `collapse =
> > ""`
> > to anything else doesn't change behaviour.
> > 
> > The question is reduced to how `as.character()` should handle a
> > list as
> > input. It seems to me that this input is so generic that it is hard
> > to
> > handle graciously without all kinds of special cases. So you expect
> > the
> > length one list
> > 
> > as.character(list(s = c("xyz", "uvw"))
> > 
> > to return the length 2 character vector `c("xyz", "uvw")`? What
> > should
> > 
> > as.character(list(s = c("xyz", "uvw"), t = c("a", "b", "c"))
> > 
> > return?
> > 
> > Kind regards,
> > Ege
> > 
> > On Mon, 2020-11-09 at 11:38 +, Boris Steipe wrote:
> > > I was just surprised by very un-intuitive behaviour of paste(),
> > > which
> > > appears to collapse a one-column data frame or one-element list
> > > into
> > > a deparsed expression, rather than producing the expected string.
> > > Can
> > > someone kindly explain what's going on here?
> > > 
> > > 
> > > reprex:
> > > ===
> > > 
> > > list(s = c("xyz", "uvw"))
> > > # s
> > > # 1 xyz
> > > # 2 uvw
> > > 
> > > paste(list(s = c("xyz", "uvw")), collapse = "")
> > > # [1] "c(\"xyz\", \"uvw\")"   # This is unexpected!
> > > 
> > > I would have expected:
> > > # [1] "xyzuvw"
> > > 
> > > ... which I do get with e.g.
> > > paste(list(s = c("xyz", "uvw"))$s, collapse = "")
> > > 
> > > But what logic is there in returning a deparsed expression?
> > > 
> > > 
> > > 
> > > Thanks!
> > > Boris
> > > __
> > > R-help@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@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.


Re: [R] analyzing results from Tuesday's US elections

2020-11-09 Thread Bert Gunter
For those who are interested:

Very nice examples of (static) statistical graphics on election results can
be found here:
https://www.nytimes.com/interactive/2020/11/09/us/arizona-election-battleground-state-counties.html?action=click=Spotlight=Homepage

Takes multidisciplinary teams and lots of hard work to produce, I would
guess.


Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Mon, Nov 9, 2020 at 4:46 PM Abby Spurdle  wrote:

> RESENT
> INITIAL EMAIL, TOO BIG
> ATTACHMENTS REPLACED WITH LINKS
>
> I created a dataset, linked.
> Had to manually copy and paste from the NY Times website.
>
> > head (data, 3)
> STATE   EQCOUNTY RMARGIN_2016 RMARGIN_2020 NVOTERS_2020
> SUB_STATEVAL_2016
> 1 Alabama Mobile 13.3   12   181783
>  0
> 2 Alabama Dallas-37.5  -3817861
>  0
> 3 Alabama Tuscaloosa 19.3   1589760
>  0
>
> > tail (data, 3)
>STATE EQCOUNTY RMARGIN_2016 RMARGIN_2020 NVOTERS_2020
> SUB_STATEVAL_2016
> 4248 WyomingUinta 58.5   63 9400
>0
> 4249 Wyoming Sublette 63.0   62 4970
>0
> 4250 Wyoming  Johnson 64.3   61 4914
>0
>
> > head (data [data [,1] == "Alaska",], 3)
> STATE EQCOUNTY RMARGIN_2016 RMARGIN_2020 NVOTERS_2020 SUB_STATEVAL_2016
> 68 AlaskaED 40 14.7-24.0   82 1
> 69 AlaskaED 37 14.7 -1.7  173 1
> 70 AlaskaED 38 14.7 -0.4  249 1
>
> EQCounty, is the County or Equivalent.
> Several states, D.C., Alaska, Connecticut, Maine, Massachusetts, Rhode
> Island and Vermont are different.
> RMargin(s) are the republican percentages minus the democrate
> percentages, as 2 or 3 digit numbers between 0 and 100.
> The last column is 0s or 1s, with 1s for Alaska, Connecticut, Maine,
> Massachusetts, Rhode Island and Vermont, where I didn't have the 2016
> margins, so the 2016 margins have been replaced with state-levels
> values.
>
> Then I scaled the margins, based on the number of voters.
> i.e.
> wx2016 <- 1000 * x2016 * nv / max.nv
> (Where x2016 is equal to RMARGIN_2020, and nv is equal to NVOTERS_2020).
>
> There may be a much better way.
>
> And came up the following plots (linked) and output (follows):
>
> ---INPUT---
> PATH = ""
> data = read.csv (PATH, header=TRUE)
>
> #raw data
> x2016 <- as.numeric (data$RMARGIN_2016)
> x2020 <- as.numeric (data$RMARGIN_2020)
> nv <- as.numeric (data$NVOTERS_2020)
> subs <- as.logical (data$SUB_STATEVAL)
>
> #computed data
> max.nv <- max (nv)
> wx2016 <- 1000 * x2016 * nv / max.nv
> wx2020 <- 1000 * x2020 * nv / max.nv
> diffs <- wx2020 - wx2016
>
> OFFSET <- 500
> p0 <- par (mfrow = c (2, 2) )
>
> #plot 1
> plot (wx2016, wx2020,
> main="All Votes\n(By County, or Equivalent)",
> xlab="Scaled Republican Margin, 2016", ylab="Scaled Republican Margin,
> 2020")
> abline (h=0, v=0, lty=2)
>
> #plot 2
> OFFSET <- 200
> plot (wx2016, wx2020,
> xlim = c (-OFFSET, OFFSET), ylim = c (-OFFSET, OFFSET),
> main="All Votes\n(Zoomed In)",
> xlab="Scaled Republican Margin, 2016", ylab="Scaled Republican Margin,
> 2020")
> abline (h=0, v=0, lty=2)
>
> OFFSET <- 1000
>
> #plot 3
> J1 <- order (diffs, decreasing=TRUE)[1:400]
> plot (wx2016 [J1], wx2020 [J1],
> xlim = c (-OFFSET, OFFSET), ylim = c (-OFFSET, OFFSET),
> main="400 Biggest Shifts Towards Republican",
> xlab="Scaled Republican Margin, 2016", ylab="Scaled Republican Margin,
> 2020")
> abline (h=0, v=0, lty=2)
> abline (a=0, b=1, lty=2)
>
> #plot 4
> J2 <- order (diffs)[1:400]
> plot (wx2016 [J2], wx2020 [J2],
> xlim = c (-OFFSET, OFFSET), ylim = c (-OFFSET, OFFSET),
> main="400 Biggest Shifts Towards Democrat",
> xlab="Scaled Republican Margin, 2016", ylab="Scaled Republican Margin,
> 2020")
> abline (h=0, v=0, lty=2)
> abline (a=0, b=1, lty=2)
>
> par (p0)
>
> #most democrat
> I = order (wx2020)[1:30]
> cbind (data [I,], scaled.dem.vote = -1 * wx2020 [I])
>
> #biggest move toward democrat
> head (cbind (data [J2,], diffs = diffs [J2]), 30)
>
> ---OUTPUT---
> #most democrat
> > cbind (data [I,], scaled.dem.vote = -1 * wx2020 [I])
>   STATEEQCOUNTY RMARGIN_2016 RMARGIN_2020
> NVOTERS_2020 SUB_STATEVAL_2016 scaled.dem.vote
> 229  California Los Angeles-49.3  -44
> 3674850 0   44000.000
> 769IllinoisCook-53.1  -47
> 1897721 0   24271.164
> 4073 WashingtonKing-48.8  -53
> 1188152 0   17135.953
> 3092   PennsylvaniaPhiladelphia-67.0  -63
> 701647 0   12028.725
> 215  California Alameda-63.5  -64
> 625710 0   10897.163
> 227  

Re: [R] analyzing results from Tuesday's US elections

2020-11-09 Thread Abby Spurdle
RESENT
INITIAL EMAIL, TOO BIG
ATTACHMENTS REPLACED WITH LINKS

I created a dataset, linked.
Had to manually copy and paste from the NY Times website.

> head (data, 3)
STATE   EQCOUNTY RMARGIN_2016 RMARGIN_2020 NVOTERS_2020 SUB_STATEVAL_2016
1 Alabama Mobile 13.3   12   181783 0
2 Alabama Dallas-37.5  -3817861 0
3 Alabama Tuscaloosa 19.3   1589760 0

> tail (data, 3)
   STATE EQCOUNTY RMARGIN_2016 RMARGIN_2020 NVOTERS_2020 SUB_STATEVAL_2016
4248 WyomingUinta 58.5   63 9400 0
4249 Wyoming Sublette 63.0   62 4970 0
4250 Wyoming  Johnson 64.3   61 4914 0

> head (data [data [,1] == "Alaska",], 3)
STATE EQCOUNTY RMARGIN_2016 RMARGIN_2020 NVOTERS_2020 SUB_STATEVAL_2016
68 AlaskaED 40 14.7-24.0   82 1
69 AlaskaED 37 14.7 -1.7  173 1
70 AlaskaED 38 14.7 -0.4  249 1

EQCounty, is the County or Equivalent.
Several states, D.C., Alaska, Connecticut, Maine, Massachusetts, Rhode
Island and Vermont are different.
RMargin(s) are the republican percentages minus the democrate
percentages, as 2 or 3 digit numbers between 0 and 100.
The last column is 0s or 1s, with 1s for Alaska, Connecticut, Maine,
Massachusetts, Rhode Island and Vermont, where I didn't have the 2016
margins, so the 2016 margins have been replaced with state-levels
values.

Then I scaled the margins, based on the number of voters.
i.e.
wx2016 <- 1000 * x2016 * nv / max.nv
(Where x2016 is equal to RMARGIN_2020, and nv is equal to NVOTERS_2020).

There may be a much better way.

And came up the following plots (linked) and output (follows):

---INPUT---
PATH = ""
data = read.csv (PATH, header=TRUE)

#raw data
x2016 <- as.numeric (data$RMARGIN_2016)
x2020 <- as.numeric (data$RMARGIN_2020)
nv <- as.numeric (data$NVOTERS_2020)
subs <- as.logical (data$SUB_STATEVAL)

#computed data
max.nv <- max (nv)
wx2016 <- 1000 * x2016 * nv / max.nv
wx2020 <- 1000 * x2020 * nv / max.nv
diffs <- wx2020 - wx2016

OFFSET <- 500
p0 <- par (mfrow = c (2, 2) )

#plot 1
plot (wx2016, wx2020,
main="All Votes\n(By County, or Equivalent)",
xlab="Scaled Republican Margin, 2016", ylab="Scaled Republican Margin, 2020")
abline (h=0, v=0, lty=2)

#plot 2
OFFSET <- 200
plot (wx2016, wx2020,
xlim = c (-OFFSET, OFFSET), ylim = c (-OFFSET, OFFSET),
main="All Votes\n(Zoomed In)",
xlab="Scaled Republican Margin, 2016", ylab="Scaled Republican Margin, 2020")
abline (h=0, v=0, lty=2)

OFFSET <- 1000

#plot 3
J1 <- order (diffs, decreasing=TRUE)[1:400]
plot (wx2016 [J1], wx2020 [J1],
xlim = c (-OFFSET, OFFSET), ylim = c (-OFFSET, OFFSET),
main="400 Biggest Shifts Towards Republican",
xlab="Scaled Republican Margin, 2016", ylab="Scaled Republican Margin, 2020")
abline (h=0, v=0, lty=2)
abline (a=0, b=1, lty=2)

#plot 4
J2 <- order (diffs)[1:400]
plot (wx2016 [J2], wx2020 [J2],
xlim = c (-OFFSET, OFFSET), ylim = c (-OFFSET, OFFSET),
main="400 Biggest Shifts Towards Democrat",
xlab="Scaled Republican Margin, 2016", ylab="Scaled Republican Margin, 2020")
abline (h=0, v=0, lty=2)
abline (a=0, b=1, lty=2)

par (p0)

#most democrat
I = order (wx2020)[1:30]
cbind (data [I,], scaled.dem.vote = -1 * wx2020 [I])

#biggest move toward democrat
head (cbind (data [J2,], diffs = diffs [J2]), 30)

---OUTPUT---
#most democrat
> cbind (data [I,], scaled.dem.vote = -1 * wx2020 [I])
  STATEEQCOUNTY RMARGIN_2016 RMARGIN_2020
NVOTERS_2020 SUB_STATEVAL_2016 scaled.dem.vote
229  California Los Angeles-49.3  -44
3674850 0   44000.000
769IllinoisCook-53.1  -47
1897721 0   24271.164
4073 WashingtonKing-48.8  -53
1188152 0   17135.953
3092   PennsylvaniaPhiladelphia-67.0  -63
701647 0   12028.725
215  California Alameda-63.5  -64
625710 0   10897.163
227  California Santa Clara-52.1  -49
726186 09682.875
238  California   San Diego-19.7  -23
1546144 09676.942
2683   New YorkBrooklyn-62.0  -49
693937 09252.871
2162  MinnesotaHennepin-34.9  -43
753716 08819.350
2074   Michigan   Wayne-37.1  -37
863382 08692.908
2673   New York   Manhattan-76.9  -70
446861 08511.986
221  California   San Francisco-75.2  -73
413642 08216.898
3495  Texas   

Re: [R] [effects] Wrong xlevels in effects plot for mixed effects model when multiline = TRUE

2020-11-09 Thread Gerrit Eichner

Dear John,

thank you for prompt reply and your hints. The problem is that our
lmer model is much more complicated and has several interaction
terms:

Mass ~ Sex + I(YoE - 1996) + I(PAI/0.1 - 16) + I(gProt/10 - 6.2) +
I(Age/10 - 7.2) + I((Age/10 - 7.2)^2) + Diuretics +
Sex:I(PAI/0.1 - 16) + Sex:I(gProt/10 - 6.2) +
Sex:I(Age/10 - 7.2) + Sex:I((Age/10 - 7.2)^2) +
I(YoE - 1996):I(Age/10 - 7.2) + I(PAI/0.1 - 16):I(Age/10 - 7.2) +
I(gProt/10 - 6.2):I(Age/10 - 7.2) +
(I(Age/10 - 7.2) + I((Age/10 - 7.2)^2) | ID)

so that allEffects is quite efficient, and since I want to place
several interaction terms with Age in one figure with Age on the
horizontal axis the argument x.var = "Age" in plot would be very
helpful. :-)

Further hints using the above complex model: The following works well:
eff <- Effect(c("gProt", "Age"), m,
  xlevels = list(gProt = 1:6 * 30, Age = 60:100))
plot(eff, lines=list(multiline=TRUE), x.var = "Age")

But this fails (note that Age is missing in xlevels):
eff <- Effect(c("gProt", "Age"), m, xlevels = list(gProt = 1:6 * 30))
plot(eff, lines=list(multiline=TRUE), x.var = "Age")


And that just led me to a solutution also for allEffects: Specifying
Age in xlevels for allEffects (although it seems unnecessary when
x.var = "Age" is used in plot) produces the correct graphical
output! :-)

Thank you very much for your support and the brilliant effects
package in general! :-)

 Best regards  --  Gerrit

-
Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/eichner
-

Am 09.11.2020 um 19:51 schrieb John Fox:

Dear Gerrit,

This looks like a bug in plot.eff(), which I haven't yet tracked down, 
but the following should give you what you want:


eff <- Effect(c("gProt", "Age"), m, xlevels = list(gProt = 1:6 * 30, 
Age=60:100))

plot(eff, lines=list(multiline=TRUE))

or

eff <- predictorEffect("Age", m, xlevels = list(gProt = 1:6 * 30))
plot(eff, lines=list(multiline=TRUE))

A couple of comments on your code, unrelated to the bug in plot.eff():

You don't need allEffects() because there's only one high-order fixed 
effect in the model, I(gProt/10 - 6.2):I(Age/10 - 7.2) (i.e., the 
interaction of gProt with Age).


x.var isn't intended as an argument for plot() with allEffects() because 
there generally isn't a common horizontal axis for all of the high-order 
effect plots.


Finally, thank you for the bug report. Barring unforeseen difficulties, 
we'll fix the bug in due course.


I hope this helps,
  John

John Fox, Professor Emeritus
McMaster University
Hamilton, Ontario, Canada
web: https://socialsciences.mcmaster.ca/jfox/

On 2020-11-09 8:06 a.m., Gerrit Eichner wrote:

Dear list members,

I observe a strange/wrong graphical output when I set the xlevels
in (e. g.) allEffects for an lmer model and plot the effects with
multiline = TRUE. I have compiled a reprex for which you need the
lmer model and the environment in which the model was fitted. They
are contained in the zip file at
https://jlubox.uni-giessen.de/dl/fiSzTCc3bW8z2npZvPpqG1xr/m-and-G1.zip
After unpacking the following should work:

m <- readRDS("m.rds")   # The lmer-model.
G1 <- readRDS("G1.rds") # Environment in which the model
  # was fitted; needed by alaEffects.
summary(m) # Just to see the model.

library(effects)
aE <- allEffects(m, xlevels = list(gProt = 1:6 * 30))
  # Non-default values for xlevels.

plot(aE)  # Fine.
plot(aE, x.var = "Age")   # Fine.
plot(aE, lines = list(multiline = TRUE))  # Fine.

plot(aE, lines = list(multiline = TRUE),
   x.var = "Age")    # Nonsense.


Anybody any idea about the reason, my mistake, or a
workaround? Thx for any hint!

   Regards  --  Gerrit


PS:
  > sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

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.2-0 carData_3.0-4

loaded via a namespace (and not attached):
   [1] Rcpp_1.0.5   lattice_0.20-41  MASS_7.3-53  grid_4.0.2 
DBI_1.1.0
   [6] nlme_3.1-149 survey_4.0   estimability_1.3 minqa_1.2.4 
nloptr_1.2.2.2
[11] Matrix_1.2-18    boot_1.3-25  splines_4.0.2    statmod_1.4.34 
lme4_1.1-23
[16] tools_4.0.2  survival_3.2-3   yaml_2.2.1   compiler_4.0.2 
colorspace_1.4-1

[21] mitools_2.4  insight_0.9.5    

Re: [ESS] How to tame a jumpy iESS buffer?

2020-11-09 Thread John Haman via ESS-help
Okay, time for another update on this issue. 

I found another possible culprit: the smooth-scrolling package. I had it 
enabled for ages, and it enforces a margin near the top and bottom of the 
buffer.

Disabling the package seems to help with jumpiness.

Cheers,
John

On Wed, Sep 16, 2020, at 2:55 AM, Jeremie Juste wrote:
> 
> Hello John,
> 
> I apologize for the delayed response.
> 
> I still cannot reproduce your issue after
> > (setq eldoc-echo-area-use-multiline-p t)
> 
> I get the multi-line in eldoc but no jumps in the commit buffer.
> To test on your side I would suggest.
> 
> - $ emacs -Q
> 
> - then load ess-site. If you installed it with melpa then
>  - (package-initialize)
>  - (require 'ess-site)
>  (setq eldoc-echo-area-use-multiline-p t)
> 
> 
> HTH,
> Jeremie
> 
> - ess-version: 18.10.3snapshot [elpa: 20200825.829] (loaded from
> /home/djj/.emacs.d/elpa/ess-20200825.829/)
> - GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.5,
> cairo version 1.16.0) of 2020-09-01
> 
> 
> 
> 
> John Haman  writes:
> 
> > Thanks. I bisected my .emacs and found that that jumpiness is being
> > caused by my preferred eldoc setup. I use
> >
> >   (setq eldoc-echo-area-use-multiline-p t)
> >
> > which let's eldoc use more than one mini-buffer line. When the
> > minibuffer expands to 2+ lines, the comint buffer jumps.
> >
> > Maybe you can try enabling this and see if it causes comint jumpiness.
> >
> > FWIW I'm using Emacs 26.3, and the latest ESS on Melpa.
> >
> > Thanks.
> >
> > -John
> >
> > On 9/12/20 4:13 PM, Jeremie Juste wrote:
> >> Hello John,
> >>
> >> Unfortunately, I cannot reproduce your error. We can try to figure out
> >> how is Ess working with emacs -Q though.
> >>
> >> - $ emacs -Q
> >>
> >> - then load ess-site. If you installed it with melpa then
> >> - (package-initialize)
> >> - (ess-site)
> >>
> >> - Do you have the same issue when using IESS?
> >>
> >> Could you please specify the version of emacs and ess you are using? In
> >> case someone else comes across this problem.
> >>
> >> HTH,
> >>
> >> Jeremie
> >>
> >>
> >>
> >>
>

__
ESS-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/ess-help


Re: [ESS] how to change default emacs behavior, upon running R code, from 2 side-by-by side frames to top-and-bottom frames?

2020-11-09 Thread Jeremie Juste via ESS-help
Hello,

> When I execute a line of R code, the R buffer opens up as expected, but
> it opens in a frame adjacent to the frame containing my source buffer. I
> would like it to open the R buffer as a frame below my source code,
> rather than adjacent to it.Â

This section of the documentation might address your issue. You can
execute the command below for quick access.

(info "(ess) Controlling buffer display")

HTH,
Jeremie

__
ESS-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/ess-help


[ESS] how to change default emacs behavior, upon running R code, from 2 side-by-by side frames to top-and-bottom frames?

2020-11-09 Thread Christopher W. Ryan via ESS-help


I'm running, on Windows 10, Vince Goulet's version of emacs/ess, which
includesÂ

GNU Emacs 26.3 (build 1, x86_64-w64-mingw32)
 of 2019-08-29

When I execute a line of R code, the R buffer opens up as expected, but
it opens in a frame adjacent to the frame containing my source buffer. I
would like it to open the R buffer as a frame below my source code,
rather than adjacent to it.Â

How can I change the behavior from side-side frames to top-bottom frames?

Thanks.

--Chris Ryan

__
ESS-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/ess-help


Re: [R] [effects] Wrong xlevels in effects plot for mixed effects model when multiline = TRUE

2020-11-09 Thread John Fox

Dear Gerrit,

This looks like a bug in plot.eff(), which I haven't yet tracked down, 
but the following should give you what you want:


eff <- Effect(c("gProt", "Age"), m, xlevels = list(gProt = 1:6 * 30, 
Age=60:100))

plot(eff, lines=list(multiline=TRUE))

or

eff <- predictorEffect("Age", m, xlevels = list(gProt = 1:6 * 30))
plot(eff, lines=list(multiline=TRUE))

A couple of comments on your code, unrelated to the bug in plot.eff():

You don't need allEffects() because there's only one high-order fixed 
effect in the model, I(gProt/10 - 6.2):I(Age/10 - 7.2) (i.e., the 
interaction of gProt with Age).


x.var isn't intended as an argument for plot() with allEffects() because 
there generally isn't a common horizontal axis for all of the high-order 
effect plots.


Finally, thank you for the bug report. Barring unforeseen difficulties, 
we'll fix the bug in due course.


I hope this helps,
 John

John Fox, Professor Emeritus
McMaster University
Hamilton, Ontario, Canada
web: https://socialsciences.mcmaster.ca/jfox/

On 2020-11-09 8:06 a.m., Gerrit Eichner wrote:

Dear list members,

I observe a strange/wrong graphical output when I set the xlevels
in (e. g.) allEffects for an lmer model and plot the effects with
multiline = TRUE. I have compiled a reprex for which you need the
lmer model and the environment in which the model was fitted. They
are contained in the zip file at
https://jlubox.uni-giessen.de/dl/fiSzTCc3bW8z2npZvPpqG1xr/m-and-G1.zip
After unpacking the following should work:

m <- readRDS("m.rds")   # The lmer-model.
G1 <- readRDS("G1.rds") # Environment in which the model
  # was fitted; needed by alaEffects.
summary(m) # Just to see the model.

library(effects)
aE <- allEffects(m, xlevels = list(gProt = 1:6 * 30))
  # Non-default values for xlevels.

plot(aE)  # Fine.
plot(aE, x.var = "Age")   # Fine.
plot(aE, lines = list(multiline = TRUE))  # Fine.

plot(aE, lines = list(multiline = TRUE),
   x.var = "Age")    # Nonsense.


Anybody any idea about the reason, my mistake, or a
workaround? Thx for any hint!

   Regards  --  Gerrit


PS:
  > sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

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.2-0 carData_3.0-4

loaded via a namespace (and not attached):
   [1] Rcpp_1.0.5   lattice_0.20-41  MASS_7.3-53  grid_4.0.2 
DBI_1.1.0
   [6] nlme_3.1-149 survey_4.0   estimability_1.3 minqa_1.2.4 
nloptr_1.2.2.2
[11] Matrix_1.2-18    boot_1.3-25  splines_4.0.2    statmod_1.4.34 
lme4_1.1-23
[16] tools_4.0.2  survival_3.2-3   yaml_2.2.1   compiler_4.0.2 
colorspace_1.4-1

[21] mitools_2.4  insight_0.9.5    nnet_7.3-14

-
Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@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@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@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.


Re: [R] analyzing results from Tuesday's US elections

2020-11-09 Thread Marc Roos
 
Publish the results/graphs please, like to see what your are doing.



-Original Message-
From: Matthew McCormack [mailto:mccorm...@molbio.mgh.harvard.edu] 
Sent: Monday, November 09, 2020 6:14 PM
To: r-help@r-project.org
Subject: Re: [R] analyzing results from Tuesday's US elections


Benford Analysis for Data Validation and Forensic Analytics

Provides tools that make it easier to validate data using Benford's Law.

https://www.rdocumentation.org/packages/benford.analysis/versions/0.1.5


Matthew

On 11/9/20 9:23 AM, Alexandra Thorn wrote:
>  External Email - Use Caution
>
> This thread strikes me as pretty far off-topic for a forum dedicated 
> to software support on R.
>
> https://secure-web.cisco.com/15MzwKoUQfDzeGBDx9gweXKgiYtAPv1UlnW2dg9Cu
> DtSNWgxy3ffTf_uuPizbjoJnovoOD6lrPDluOgGvIUTEF1d_rOTfaF3nUKLvNiZa3fHZ_I
> HD-SjKotr4lurHjmNPlSrljLipPsrDk2aoo63-GLwvaw64By_MnLST7lt4FgA2pYXgE3x1
> 5Xn-kRZ85m29f0BxhHJMVfilvVUoUEBPrw/https%3A%2F%2Fwww.r-project.org%2Fm
> ail.html%23instructions "The main R mailing list, for discussion 
> about problems and solutions using R, announcements (not covered by 
> R-announce or R-packages, see above), about the availability 
of 
> new functionality for R and documentation of R, comparison and 
> compatibility with S-plus, and for the posting of nice examples and 
> benchmarks. Do read the posting guide before sending anything!"
>
> https://secure-web.cisco.com/1V05G8mWSPHU-YvLbL-UQMy49XX7n7-EivE-gTOlh
> 2nZ3P0oxp6DGUUZQ_Q5VIkE3J0qmhrrSXxJaqZjv-Tllghba8lQrbkazuAHTcltsfo3I-C
> -SMqhb-CDdFbeEgIsr7py_gKW9BqumTZacywhHVnzhGGR2s1A-2akqQLYSYpYeX5EcVJAY
> vX1KPCs9kJbOEveOr5yYjetokaZpLTzdMA/https%3A%2F%2Fwww.r-project.org%2Fp
> osting-guide.html "The R mailing lists are primarily intended for 
> questions and discussion about the R software. However, questions 
> about statistical methodology are sometimes posted. If the question is 

> well-asked and of interest to someone on the list, it may elicit an 
> informative up-to-date answer. See also the Usenet groups 
> sci.stat.consult (applied statistics and consulting) and sci.stat.math 

> (mathematical stat and probability)."
>
> On Mon, 9 Nov 2020 00:53:46 -0500
> Matthew McCormack  wrote:
>
>> You can try here: 
>> https://secure-web.cisco.com/17WRivozTB0Frts23cTlTBd3SYWzVXQsLa_jDRN8
>> SldAl35F0SYXRMZczzIXrQFTzbfRV4YfPOVhMSwopcdTU9Sva396s3bX3-KM7-51KjSnY
>> 0aXxlADYaHdvs4y4YXrUfk1GT2801rVL26MCEEn2E1azdQ8ECllu1roS_Z8MIj8d6kyCt
>> UYVdOYN1i9DuWBSXPlEi-iOtrQsBp6ELRXNFw/https%3A%2F%2Fdecisiondeskhq.co
>> m%2F
>>
>> I think they have what you are looking for. From their website:
>>
>> "Create a FREE account to access up to the minute election results 
>> and insights on all U.S. Federal elections. Decision Desk HQ & 
>> Øptimus provide live election night coverage, race-specific results 
>> including county-level returns, and exclusive race probabilities for 
>> key battleground races."
>>
>>      Also, this article provides a little, emphasis on little, of 
>> statistical analysis of election results, but it may be a place to 
>> start.
>>
>> https://secure-web.cisco.com/1JA34S9tw27K78g7scwo2aGe4lPpV7HThBE81hhJ
>> jb4Ban7fxqbnOZqx7HxfcyqKrcB5BX7oJFHhMPumrxjm6aQJ0trW1Jgk0h9s2mNhZg4T_
>> gTUls8y4l0KZ-AstUtw0eC0TtR9mHblU7KWid-7OO4mg0TfsxWyNpcqkA8MBuGftOEgUF
>> 7WtakShYgmCNYJkEfQJHK5_vjwK0taJeUheVw/https%3A%2F%2Fwww.theepochtimes
>> .com%2Fstatistical-anomalies-in-biden-votes-analyses-indicate_3570518
>> .html%3Futm_source%3Dnewsnoe%26utm_medium%3Demail%26utm_campaign%3Dbr
>> eaking-2020-11-08-5
>>
>> Matthew
>>
>> On 11/8/20 11:25 PM, Bert Gunter wrote:
>>>   External Email - Use Caution
>>>
>>> NYT  had interactive maps that reported  votes by county. So try 
>>> contacting them.
>>>
>>>
>>> Bert
>>>
>>> On Sun, Nov 8, 2020, 8:10 PM Abby Spurdle 
>>> wrote:
> such a repository already exists -- the NY Times, AP, CNN, etc.
> etc.
 already have interactive web pages that did this

 I've been looking for presidential election results, by 
 ***county***. I've found historic results, including results for 
 2016.

 However, I can't find such a dataset, for 2020.
 (Even though this seems like an obvious thing to publish).

 I suspect that the NY Times has the data, but I haven't been able 
 to work where the data is on their website, or how to access it.

 More ***specific*** suggestions would be appreciated...?
   
>>> [[alternative HTML version deleted]]
>>>
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 
>>> https://secure-web.cisco.com/1C8m4dUQtDXEQdbAFTH153ehiJcvHuL_FkvDGeJ
>>> BHhMRYZauAp6gdevfmLIh2MLpRjBx7LXAG9QpagRV63oMY5AyQF6uOkNa7JGw-0zGZKI
>>> FHoSuZtjpcIokATDMxqoJlVfCiktqIYXEiJcrovbnxo-DAgLEiREocQrn0yMbLc2A-gw
>>> R3CN9XurWkU21TUD1CLJ-3gpiCLKKe9BdHWdaeEA/https%3A%2F%2Fstat.ethz.ch%
>>> 2Fmailman%2Flistinfo%2Fr-help
>>> PLEASE do read the posting guide
>>> 

Re: [R] analyzing results from Tuesday's US elections

2020-11-09 Thread Matthew McCormack


Benford Analysis for Data Validation and Forensic Analytics

Provides tools that make it easier to validate data using Benford's Law.

https://www.rdocumentation.org/packages/benford.analysis/versions/0.1.5


Matthew

On 11/9/20 9:23 AM, Alexandra Thorn wrote:
>  External Email - Use Caution
>
> This thread strikes me as pretty far off-topic for a forum dedicated to
> software support on R.
>
> https://secure-web.cisco.com/15MzwKoUQfDzeGBDx9gweXKgiYtAPv1UlnW2dg9CuDtSNWgxy3ffTf_uuPizbjoJnovoOD6lrPDluOgGvIUTEF1d_rOTfaF3nUKLvNiZa3fHZ_IHD-SjKotr4lurHjmNPlSrljLipPsrDk2aoo63-GLwvaw64By_MnLST7lt4FgA2pYXgE3x15Xn-kRZ85m29f0BxhHJMVfilvVUoUEBPrw/https%3A%2F%2Fwww.r-project.org%2Fmail.html%23instructions
> "The ‘main’ R mailing list, for discussion about problems and solutions
> using R, announcements (not covered by ‘R-announce’ or ‘R-packages’,
> see above), about the availability of new functionality for R and
> documentation of R, comparison and compatibility with S-plus, and for
> the posting of nice examples and benchmarks. Do read the posting guide
> before sending anything!"
>
> https://secure-web.cisco.com/1V05G8mWSPHU-YvLbL-UQMy49XX7n7-EivE-gTOlh2nZ3P0oxp6DGUUZQ_Q5VIkE3J0qmhrrSXxJaqZjv-Tllghba8lQrbkazuAHTcltsfo3I-C-SMqhb-CDdFbeEgIsr7py_gKW9BqumTZacywhHVnzhGGR2s1A-2akqQLYSYpYeX5EcVJAYvX1KPCs9kJbOEveOr5yYjetokaZpLTzdMA/https%3A%2F%2Fwww.r-project.org%2Fposting-guide.html
> "The R mailing lists are primarily intended for questions and
> discussion about the R software. However, questions about statistical
> methodology are sometimes posted. If the question is well-asked and of
> interest to someone on the list, it may elicit an informative
> up-to-date answer. See also the Usenet groups sci.stat.consult (applied
> statistics and consulting) and sci.stat.math (mathematical stat and
> probability)."
>
> On Mon, 9 Nov 2020 00:53:46 -0500
> Matthew McCormack  wrote:
>
>> You can try here: 
>> https://secure-web.cisco.com/17WRivozTB0Frts23cTlTBd3SYWzVXQsLa_jDRN8SldAl35F0SYXRMZczzIXrQFTzbfRV4YfPOVhMSwopcdTU9Sva396s3bX3-KM7-51KjSnY0aXxlADYaHdvs4y4YXrUfk1GT2801rVL26MCEEn2E1azdQ8ECllu1roS_Z8MIj8d6kyCtUYVdOYN1i9DuWBSXPlEi-iOtrQsBp6ELRXNFw/https%3A%2F%2Fdecisiondeskhq.com%2F
>>
>> I think they have what you are looking for. From their website:
>>
>> "Create a FREE account to access up to the minute election results
>> and insights on all U.S. Federal elections. Decision Desk HQ &
>> Øptimus provide live election night coverage, race-specific results
>> including county-level returns, and exclusive race probabilities for
>> key battleground races."
>>
>>      Also, this article provides a little, emphasis on little, of
>> statistical analysis of election results, but it may be a place to
>> start.
>>
>> https://secure-web.cisco.com/1JA34S9tw27K78g7scwo2aGe4lPpV7HThBE81hhJjb4Ban7fxqbnOZqx7HxfcyqKrcB5BX7oJFHhMPumrxjm6aQJ0trW1Jgk0h9s2mNhZg4T_gTUls8y4l0KZ-AstUtw0eC0TtR9mHblU7KWid-7OO4mg0TfsxWyNpcqkA8MBuGftOEgUF7WtakShYgmCNYJkEfQJHK5_vjwK0taJeUheVw/https%3A%2F%2Fwww.theepochtimes.com%2Fstatistical-anomalies-in-biden-votes-analyses-indicate_3570518.html%3Futm_source%3Dnewsnoe%26utm_medium%3Demail%26utm_campaign%3Dbreaking-2020-11-08-5
>>
>> Matthew
>>
>> On 11/8/20 11:25 PM, Bert Gunter wrote:
>>>   External Email - Use Caution
>>>
>>> NYT  had interactive maps that reported  votes by county. So try
>>> contacting them.
>>>
>>>
>>> Bert
>>>
>>> On Sun, Nov 8, 2020, 8:10 PM Abby Spurdle 
>>> wrote:
> such a repository already exists -- the NY Times, AP, CNN, etc.
> etc.
 already have interactive web pages that did this

 I've been looking for presidential election results, by
 ***county***. I've found historic results, including results for
 2016.

 However, I can't find such a dataset, for 2020.
 (Even though this seems like an obvious thing to publish).

 I suspect that the NY Times has the data, but I haven't been able
 to work where the data is on their website, or how to access it.

 More ***specific*** suggestions would be appreciated...?
   
>>> [[alternative HTML version deleted]]
>>>
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://secure-web.cisco.com/1C8m4dUQtDXEQdbAFTH153ehiJcvHuL_FkvDGeJBHhMRYZauAp6gdevfmLIh2MLpRjBx7LXAG9QpagRV63oMY5AyQF6uOkNa7JGw-0zGZKIFHoSuZtjpcIokATDMxqoJlVfCiktqIYXEiJcrovbnxo-DAgLEiREocQrn0yMbLc2A-gwR3CN9XurWkU21TUD1CLJ-3gpiCLKKe9BdHWdaeEA/https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help
>>> PLEASE do read the posting guide
>>> http://secure-web.cisco.com/1ppZyk8SO6U25PKNDKtGQ-VIADLxXgKvnHc8QlV3cUMNPzLQvS8E0i9cg05EyzUyHnFjj2QWDjvAjyuduvE1P8Nr0TogQweiuBysM9a1rXjQn1EOaypHdqwa2_inODK1icu0Ff33AZDB00N4x-nYxZ2e16nArVuaMEddaLXBhtBYMn2LAcPYJ8s2wGN10heiFWywn-r8--Hw77GJx1hkTgg/http%3A%2F%2Fwww.R-project.org%2Fposting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>  [[alternative HTML 

Re: [R] analyzing results from Tuesday's US elections

2020-11-09 Thread Alexandra Thorn
This thread strikes me as pretty far off-topic for a forum dedicated to
software support on R.

https://www.r-project.org/mail.html#instructions
"The ‘main’ R mailing list, for discussion about problems and solutions
using R, announcements (not covered by ‘R-announce’ or ‘R-packages’,
see above), about the availability of new functionality for R and
documentation of R, comparison and compatibility with S-plus, and for
the posting of nice examples and benchmarks. Do read the posting guide
before sending anything!"

https://www.r-project.org/posting-guide.html
"The R mailing lists are primarily intended for questions and
discussion about the R software. However, questions about statistical
methodology are sometimes posted. If the question is well-asked and of
interest to someone on the list, it may elicit an informative
up-to-date answer. See also the Usenet groups sci.stat.consult (applied
statistics and consulting) and sci.stat.math (mathematical stat and
probability)."

On Mon, 9 Nov 2020 00:53:46 -0500
Matthew McCormack  wrote:

> You can try here: https://decisiondeskhq.com/
> 
> I think they have what you are looking for. From their website:
> 
> "Create a FREE account to access up to the minute election results
> and insights on all U.S. Federal elections. Decision Desk HQ &
> Øptimus provide live election night coverage, race-specific results
> including county-level returns, and exclusive race probabilities for
> key battleground races."
> 
>     Also, this article provides a little, emphasis on little, of 
> statistical analysis of election results, but it may be a place to
> start.
> 
> https://www.theepochtimes.com/statistical-anomalies-in-biden-votes-analyses-indicate_3570518.html?utm_source=newsnoe_medium=email_campaign=breaking-2020-11-08-5
> 
> Matthew
> 
> On 11/8/20 11:25 PM, Bert Gunter wrote:
> >  External Email - Use Caution
> >
> > NYT  had interactive maps that reported  votes by county. So try
> > contacting them.
> >
> >
> > Bert
> >
> > On Sun, Nov 8, 2020, 8:10 PM Abby Spurdle 
> > wrote: 
> >>> such a repository already exists -- the NY Times, AP, CNN, etc.
> >>> etc.  
> >> already have interactive web pages that did this
> >>
> >> I've been looking for presidential election results, by
> >> ***county***. I've found historic results, including results for
> >> 2016.
> >>
> >> However, I can't find such a dataset, for 2020.
> >> (Even though this seems like an obvious thing to publish).
> >>
> >> I suspect that the NY Times has the data, but I haven't been able
> >> to work where the data is on their website, or how to access it.
> >>
> >> More ***specific*** suggestions would be appreciated...?
> >>  
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://secure-web.cisco.com/1C8m4dUQtDXEQdbAFTH153ehiJcvHuL_FkvDGeJBHhMRYZauAp6gdevfmLIh2MLpRjBx7LXAG9QpagRV63oMY5AyQF6uOkNa7JGw-0zGZKIFHoSuZtjpcIokATDMxqoJlVfCiktqIYXEiJcrovbnxo-DAgLEiREocQrn0yMbLc2A-gwR3CN9XurWkU21TUD1CLJ-3gpiCLKKe9BdHWdaeEA/https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help
> > PLEASE do read the posting guide
> > http://secure-web.cisco.com/1ppZyk8SO6U25PKNDKtGQ-VIADLxXgKvnHc8QlV3cUMNPzLQvS8E0i9cg05EyzUyHnFjj2QWDjvAjyuduvE1P8Nr0TogQweiuBysM9a1rXjQn1EOaypHdqwa2_inODK1icu0Ff33AZDB00N4x-nYxZ2e16nArVuaMEddaLXBhtBYMn2LAcPYJ8s2wGN10heiFWywn-r8--Hw77GJx1hkTgg/http%3A%2F%2Fwww.R-project.org%2Fposting-guide.html
> > and provide commented, minimal, self-contained, reproducible code. 
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@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@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] [R-pkgs] sbo: N-gram Stupid Back-Off models in R

2020-11-09 Thread Valerio Gherardi

Dear all,

I would like to introduce
sbo: Utilities for building and evaluating text prediction functions 
based on Stupid Back-off N-gram models.


v0.3.0 is now on CRAN: 
https://cran.r-project.org/web/packages/sbo/index.html

website: https://vgherard.github.io/sbo/
For bugs/issues: https://github.com/vgherard/sbo

Feedback of any kind is welcome.

Sincerely,
Valerio Gherardi.

___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages

__
R-help@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] [effects] Wrong xlevels in effects plot for mixed effects model when multiline = TRUE

2020-11-09 Thread Gerrit Eichner

Dear list members,

I observe a strange/wrong graphical output when I set the xlevels
in (e. g.) allEffects for an lmer model and plot the effects with
multiline = TRUE. I have compiled a reprex for which you need the
lmer model and the environment in which the model was fitted. They
are contained in the zip file at
https://jlubox.uni-giessen.de/dl/fiSzTCc3bW8z2npZvPpqG1xr/m-and-G1.zip
After unpacking the following should work:

m <- readRDS("m.rds")   # The lmer-model.
G1 <- readRDS("G1.rds") # Environment in which the model
 # was fitted; needed by alaEffects.
summary(m) # Just to see the model.

library(effects)
aE <- allEffects(m, xlevels = list(gProt = 1:6 * 30))
 # Non-default values for xlevels.

plot(aE)  # Fine.
plot(aE, x.var = "Age")   # Fine.
plot(aE, lines = list(multiline = TRUE))  # Fine.

plot(aE, lines = list(multiline = TRUE),
  x.var = "Age")# Nonsense.


Anybody any idea about the reason, my mistake, or a
workaround? Thx for any hint!

  Regards  --  Gerrit


PS:
 > sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

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.2-0 carData_3.0-4

loaded via a namespace (and not attached):
  [1] Rcpp_1.0.5   lattice_0.20-41  MASS_7.3-53  grid_4.0.2 
DBI_1.1.0
  [6] nlme_3.1-149 survey_4.0   estimability_1.3 minqa_1.2.4 
nloptr_1.2.2.2
[11] Matrix_1.2-18boot_1.3-25  splines_4.0.2statmod_1.4.34 
lme4_1.1-23
[16] tools_4.0.2  survival_3.2-3   yaml_2.2.1   compiler_4.0.2 
colorspace_1.4-1

[21] mitools_2.4  insight_0.9.5nnet_7.3-14

-
Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@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@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.


Re: [R] paste() turns list element character vector into deparsed expression. Why?

2020-11-09 Thread Boris Steipe
Thanks Ege -

That narrows it down, ... but it's still weird.

My issue is that I don't consider "c(\"xyz\", \"uvw\")" to be a valid character 
representation of a list. c() is a function, so "c(\"xyz\", \"uvw\")" is a 
string representation of a function call that could be  eval(parse(...))'ed 
into a two-element vector ... but considering this a coercion seems really 
weird.

What do I think your example should return? An object of the same general 
structure as the input, with non-character components coerced to character. And 
if that's not possible because there is no good character representation (e.g. 
if its a closure) than it should return an error. 


Cheers,
Boris

 


> On 2020-11-09, at 22:24, Ege Rubak  wrote:
> 
> EXTERNAL EMAIL:  Treat content with extra caution.
> 
> I think `paste()` just calls `as.character()` on each input argument
> and then collapses things afterwards. Calling `as.character()` on the
> first input argument generates exactly the output you show (and didn't
> expect) and there is nothing to collapse. So changing `collapse = ""`
> to anything else doesn't change behaviour.
> 
> The question is reduced to how `as.character()` should handle a list as
> input. It seems to me that this input is so generic that it is hard to
> handle graciously without all kinds of special cases. So you expect the
> length one list
> 
> as.character(list(s = c("xyz", "uvw"))
> 
> to return the length 2 character vector `c("xyz", "uvw")`? What should
> 
> as.character(list(s = c("xyz", "uvw"), t = c("a", "b", "c"))
> 
> return?
> 
> Kind regards,
> Ege
> 
> On Mon, 2020-11-09 at 11:38 +, Boris Steipe wrote:
>> I was just surprised by very un-intuitive behaviour of paste(), which
>> appears to collapse a one-column data frame or one-element list into
>> a deparsed expression, rather than producing the expected string. Can
>> someone kindly explain what's going on here?
>> 
>> 
>> reprex:
>> ===
>> 
>> list(s = c("xyz", "uvw"))
>> # s
>> # 1 xyz
>> # 2 uvw
>> 
>> paste(list(s = c("xyz", "uvw")), collapse = "")
>> # [1] "c(\"xyz\", \"uvw\")"   # This is unexpected!
>> 
>> I would have expected:
>> # [1] "xyzuvw"
>> 
>> ... which I do get with e.g.
>> paste(list(s = c("xyz", "uvw"))$s, collapse = "")
>> 
>> But what logic is there in returning a deparsed expression?
>> 
>> 
>> 
>> Thanks!
>> Boris
>> __
>> R-help@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@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.


Re: [R] paste() turns list element character vector into deparsed expression. Why?

2020-11-09 Thread Ege Rubak
I think `paste()` just calls `as.character()` on each input argument
and then collapses things afterwards. Calling `as.character()` on the
first input argument generates exactly the output you show (and didn't
expect) and there is nothing to collapse. So changing `collapse = ""`
to anything else doesn't change behaviour.

The question is reduced to how `as.character()` should handle a list as
input. It seems to me that this input is so generic that it is hard to
handle graciously without all kinds of special cases. So you expect the
length one list

as.character(list(s = c("xyz", "uvw"))

to return the length 2 character vector `c("xyz", "uvw")`? What should

as.character(list(s = c("xyz", "uvw"), t = c("a", "b", "c"))

return?

Kind regards,
Ege

On Mon, 2020-11-09 at 11:38 +, Boris Steipe wrote:
> I was just surprised by very un-intuitive behaviour of paste(), which
> appears to collapse a one-column data frame or one-element list into
> a deparsed expression, rather than producing the expected string. Can
> someone kindly explain what's going on here?
> 
> 
> reprex:
> ===
> 
> list(s = c("xyz", "uvw"))
> # s
> # 1 xyz
> # 2 uvw
> 
> paste(list(s = c("xyz", "uvw")), collapse = "")
> # [1] "c(\"xyz\", \"uvw\")"   # This is unexpected!
> 
> I would have expected:
> # [1] "xyzuvw"
>  
> ... which I do get with e.g.
> paste(list(s = c("xyz", "uvw"))$s, collapse = "")
> 
> But what logic is there in returning a deparsed expression?
> 
> 
> 
> Thanks!
> Boris
> __
> R-help@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@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] paste() turns list element character vector into deparsed expression. Why?

2020-11-09 Thread Boris Steipe
I was just surprised by very un-intuitive behaviour of paste(), which appears 
to collapse a one-column data frame or one-element list into a deparsed 
expression, rather than producing the expected string. Can someone kindly 
explain what's going on here?


reprex:
===

list(s = c("xyz", "uvw"))
# s
# 1 xyz
# 2 uvw

paste(list(s = c("xyz", "uvw")), collapse = "")
# [1] "c(\"xyz\", \"uvw\")"   # This is unexpected!

I would have expected:
# [1] "xyzuvw"
 
... which I do get with e.g.
paste(list(s = c("xyz", "uvw"))$s, collapse = "")

But what logic is there in returning a deparsed expression?



Thanks!
Boris
__
R-help@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.