Re: [R] Off topic --- underdispersed (pseudo) binomial data.

2021-03-24 Thread Rolf Turner
On Wed, 24 Mar 2021 18:45:01 -0700 wrote: > "X = {X_1, X_2, ..., X_N} where each X_i > is an integer between 0 and n (n known a priori)" > > That is a multinomial, not a binomial distribution. A binomial > distribution can have only two values, success or failure. > > What have I

[R] setting wd to parent directory ("..") of rmd file for all chunks of .Rmd

2021-03-24 Thread nevil amos
The Rmarkdown cookbook states that the working directory for r chunks in an Rmd file is usually the directory containing the file, however it can be reset using knitr::opts_knit$set(root.dir = see: https://bookdown.org/yihui/rmarkdown-cookbook/working-directory.html#working-directory I want to

Re: [R] Including a ggplot call with a conditional geom in a function

2021-03-24 Thread Avi Gross via R-help
This may not be the right place to ask about ggplot which is part of packages but are you aware how ggplot works additively? You can say something like: P <- ggplot(...) ... + ... Then later say: P <- p + geom_...() And so on. So if you set al the layers you want first into a variable like

[R] Including a ggplot call with a conditional geom in a function

2021-03-24 Thread phil
How can I write an R function that contains a call to ggplot within it, with one of the ggplot geom statements being conditional? In my reprex, I want the plot to contain a horizontal zero line if the y values are both positive and negative, and to exclude the horizontal line if all of the y

Re: [R] Converting POSIXct format date to Character format

2021-03-24 Thread Jim Lemon
Hi ma015k3113, I suspect that you are asking the wrong question. # create an example data frame with an extra field PLC<-read.table(text="YEAR_END_Date EPS junk 2010-09-10.10 A 2009-08-10.20 B", header=TRUE, stringsAsFactors=FALSE) # first, I think that you may already have

Re: [R] Converting POSIXct format date to Character format

2021-03-24 Thread Bert Gunter
What package is select() in? 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 Wed, Mar 24, 2021 at 4:42 PM Jeff Newmiller wrote: > Please don't reply to a

[R] Off topic --- underdispersed (pseudo) binomial data.

2021-03-24 Thread Rolf Turner
I would like a real-life example of a data set which one might think to model by a binomial distribution, but which is substantially underdispersed. I.e. a sample X = {X_1, X_2, ..., X_N} where each X_i is an integer between 0 and n (n known a priori) such that var(X) << mean(X)*(1 - mean(X)/n).

Re: [R] Converting POSIXct format date to Character format

2021-03-24 Thread Jeff Newmiller
Please don't reply to a thread to start a new question... create a new email to avoid linking your question with the one you replied to. On March 24, 2021 12:11:07 PM PDT, e-mail ma015k3113 via R-help wrote: >I have a data frame "PLC" which has two variables Year_END_Date EPS >

Re: [R] Calculating column differences

2021-03-24 Thread Jeff Reichman
Bill I ended up taking a different approach miDat <- miDat %>% mutate(new_cases = cases - lag(cases, default = 0)) - or - df <- df %>% mutate(diff = Score - lag(Score, default = 0)) Jeff -Original Message- From: William Michels Sent: Wednesday, March 24, 2021 1:41 PM To:

[R] Help for storing value in the matrix

2021-03-24 Thread Ablaye Ngalaba
Hello, I need help with my R programming code. I just have a problem storing the matrix calculate Gsigma[m] in sigma. Seeing what I have coded I find NA value which doesn't generate me errors. library(MASS) # Creation of the linear kernel function #Function N°1 Kernellin<-function(X,Y){

Re: [R] Converting POSIXct format date to Character format

2021-03-24 Thread Rui Barradas
Hello, R is case sensitive, the column name is YEAR_END_Date, neither of Year_END_Date YEAR_END_DATE matches that name. Try select(PLC, format(YEAR_END_Date,format = "%B %d, %Y"), EPS) Hope this helps, Rui Barradas Às 19:11 de 24/03/21, e-mail ma015k3113 via R-help escreveu: I have a

[R] Converting POSIXct format date to Character format

2021-03-24 Thread e-mail ma015k3113 via R-help
I have a data frame "PLC" which has two variables Year_END_Date EPS YEAR_END_Date EPS 2010-09-10.10 2009-08-10.20 When I tried to convert Year_END_Date to character format using select(PLC, format(Year_END_Date,format = "%B %d, %Y"), EPS) I get an error Error: Can't

Re: [R] Calculating column differences

2021-03-24 Thread William Michels via R-help
More correctly, with an initial "NA" value in the "diff" column: > df <- data.frame(ID=1:5,Score=4*2:6) > df1 <- rbind(c(0,0), df) > cbind(df1, "diff"=c(NA, diff(df1$Score)) ) ID Score diff 1 0 0 NA 2 1 88 3 2124 4 3164 5 4204 6 5244 > HTH,

Re: [R] Calculating column differences

2021-03-24 Thread Jeff Reichman
Gerrit Changed my approach  df <- data.frame(ID=1:5,Score=4*2:6) df %>% mutate(score_diff = Score - lag(Score, default = 0)) Jeff -Original Message- From: R-help On Behalf Of Gerrit Eichner Sent: Wednesday, March 24, 2021 11:53 AM To: r-help@r-project.org Subject:

Re: [R] converting image formats

2021-03-24 Thread Vivek Sutradhara
Hi, I have made a few corrections to my previous message in the naming of my objects. I would like to have help in converting from one image format to another (between the packages EBImage, magick and imager). The magick package has functions for this. But the EBImage and imager packages do not

Re: [R] Calculating column differences

2021-03-24 Thread William Michels via R-help
Dear Jeff, Rather than diff-ing a linear vector you're trying to diff values from two different rows. Also you indicate that you want to place the diff-ed value in the 'lower' row of a new column. Try this (note insertion of an initial "zero" row): > df <- data.frame(ID=1:5,Score=4*2:6) > df1 <-

[R] converting image formats

2021-03-24 Thread Vivek Sutradhara
Hi, I would like to have help in converting from one image format to another (between the packages EBImage, magick and imager). The magick package has functions for this. But the EBImage and imager packages do not have in-built functions for the conversion. It is, of course, possible to save the

Re: [R] setRefClass in package

2021-03-24 Thread Jeremie Juste
Hello, Many thanks for the reply. Indeed there was no scoping issue here. I was sloppy. Best regards, Jeremie On Wednesday, 24 Mar 2021 at 11:34, Duncan Murdoch wrote: > On 24/03/2021 9:06 a.m., Jeremie Juste wrote: >> Hello, >> I was wondering how to call a function outside a setRefClass but

Re: [R] Calculating column differences

2021-03-24 Thread Gerrit Eichner
Dear Jeff, read diff's help page, and you'll find out what is wrong with your expectation. What do think diff(df$Score) should give for the first element in df$Score?? Hth -- Gerrit - Dr. Gerrit Eichner

[R] Calculating column differences

2021-03-24 Thread Jeff Reichman
r-help forum I'm trying to calculate the diff between two rows and them mutate the difference into a new column. I'm using the diff function but not giving me what I want. df <- data.frame(ID=1:5,Score=4*2:6) What a want where ID Score diff 1 1 8 8 2 212 4

Re: [R] setRefClass in package

2021-03-24 Thread Duncan Murdoch
On 24/03/2021 9:06 a.m., Jeremie Juste wrote: Hello, I was wondering how to call a function outside a setRefClass but inside the package without export it. Let me explain by means of an example. There are no scoping issues here: Your initialize method can see all local functions in the

Re: [R] setRefClass in package

2021-03-24 Thread Bert Gunter
I think this query fits better on r-package-devel rather than here. 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 Wed, Mar 24, 2021 at 6:07 AM Jeremie Juste

[R] setRefClass in package

2021-03-24 Thread Jeremie Juste
Hello, I was wondering how to call a function outside a setRefClass but inside the package without export it. Let me explain by means of an example. - in the file test-package/R/test.R ##' some description ##' ##' some details ##' @title test ##' @return sideeffect ##' @author Jeremie Juste ##'

[R] Probit model- endogeneity issue

2021-03-24 Thread hannelore nelissen
Dear all, I am having some issues with using the IV strategy for an endogeneity problem in terms of a probit model. In particular, I want to follow a two-stage procedure where I estimate a probit on the decision to peg the exchange rate, and then use the predicted values in the second stage