Re: [R] please help with "could not find function "ComBat.mc" "

2020-11-12 Thread Yuan Chun Ding
Hi Jim,

Thank you for the message!  Yes, you are right, I contacted Dr. Xu Zongli,  he 
said he removed the ComBat.mc function from the new version.

Ding

From: Jim Lemon [mailto:drjimle...@gmail.com]
Sent: Wednesday, November 11, 2020 5:36 PM
To: Yuan Chun Ding 
Cc: r-help@r-project.org
Subject: Re: [R] please help with "could not find function "ComBat.mc" "

Hi Yuan,
The package named "Enmix" is maintained on Bioconductor. It seems to be 
specific to particular lab equipment and so all I can advise is:

1) Try your question on the Bioconductor help list
2) If no help there contact Zongli Xu (the maintainer)

Jim

On Thu, Nov 12, 2020 at 11:40 AM Yuan Chun Ding 
mailto:ycd...@coh.org>> wrote:

Hi All,

I am very sorry to bother you.

This week, I updated my R from 3.5.3  to 4.0.3, reinstalled all required R 
packages  and reran the following R code;  then got the following error: could 
not find function "ComBat.mc".

> #' firstly Removing chip-well batch effects using ComBat from the sva package
> # First we convert from beta-values to M-values
> Mvals1 <- log2(betas.rcp)-log2(1-betas.rcp)
> #' ComBat eBayes adjustment using a known variable of interest (here we use 
> row)
> Mvals.ComBat1 <- ComBat.mc(Mvals1, batch = pData(WB.noob)$Array,nCores = 
> detectCores()-1)
Error in ComBat.mc(Mvals1, batch = pData(WB.noob)$Array, nCores = detectCores() 
-  :
  could not find function "ComBat.mc"

I have successfully run the same R code with same data sets several times since 
2017.  Google searching tells me that this ComBat.mc function is from an R 
package "Enmix".  When typing library(Enmix), no error message, so the Enmix 
library is installed.  Can you tell me why I got this error after updating to 
new R version?

Thank you,

Yuan Chun Ding

--

-SECURITY/CONFIDENTIALITY WARNING-

This message and any attachments are intended solely for the individual or 
entity to which they are addressed. This communication may contain information 
that is privileged, confidential, or exempt from disclosure under applicable 
law (e.g., personal health information, research data, financial information). 
Because this e-mail has been sent without encryption, individuals other than 
the intended recipient may be able to view the information, forward it to 
others or tamper with the information without the knowledge or consent of the 
sender. If you are not the intended recipient, or the employee or person 
responsible for delivering the message to the intended recipient, any 
dissemination, distribution or copying of the communication is strictly 
prohibited. If you received the communication in error, please notify the 
sender immediately by replying to this message and deleting the message and any 
accompanying files from your system. If, due to the security risks, you do not 
wish to rec
 eive further communications via e-mail, please reply to this message and 
inform the sender that you do not wish to receive further e-mail from the 
sender. (LCP301)

__
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.

[[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] Data transformation problem

2020-11-12 Thread phil

Thank you so much for this elegant solution, Jeff.

Philip

On 2020-11-12 02:20, Jeff Newmiller wrote:

I am not a data.table afficiando, but here is how I would do it with
dplyr/tidyr:

library(dplyr)
library(tidyr)

do_per_REL <- function( DF ) {
  rng <- range( DF$REF1 ) # watch out for missing months?
  DF <- (   data.frame( REF1 = seq( rng[ 1 ], rng[ 2 ], by = "month" ) 
)

%>% left_join( DF, by = "REF1" )
%>% arrange( REF1 )
)
  with( DF
  , data.frame( REF2 = REF1[ -1 ]
  , VAL2 = 100 * diff( VAL1 ) / VAL1[ -length( VAL1 ) ]
  )
  )
}

df2a <- (   df1
%>% mutate( REF1 = as.Date( REF1 )
  , REL1 = as.Date( REL1 )
  )
%>% nest( data = -REL1 )
%>% rename( REL2 = REL1 )
%>% rowwise()
%>% mutate( data = list( do_per_REL( data ) ) )
%>% ungroup()
%>% unnest( cols = "data" )
%>% select( REF2, REL2, VAL2 )
%>% arrange( REF2, desc( REL2 ), VAL2 )
)
df2a

On Wed, 11 Nov 2020, p...@philipsmith.ca wrote:

I am stuck on a data transformation problem. I have a data frame, df1 
in my example, with some original "levels" data. The data pertain to 
some variable, such as GDP, in various reference periods, REF, as 
estimated and released in various release periods, REL. The release 
periods follow after the reference periods by two months or more, 
sometimes by several years. I want to build a second data frame, 
called df2 in my example, with the month-to-month growth rates that 
existed in each reference period, revealing the revisions to those 
growth rates in subsequent periods.


REF1 <- 
c("2017-01-01","2017-01-01","2017-01-01","2017-01-01","2017-01-01",

 "2017-02-01","2017-02-01","2017-02-01","2017-02-01","2017-02-01",
 "2017-03-01","2017-03-01","2017-03-01","2017-03-01","2017-03-01")
REL1 <- 
c("2020-09-01","2020-08-01","2020-07-01","2020-06-01","2019-05-01",

 "2020-09-01","2020-08-01","2020-07-01","2020-06-01","2019-05-01",
 "2020-09-01","2020-08-01","2020-07-01","2020-06-01","2019-05-01")
VAL1 <- 
c(17974,14567,13425,NA,12900,17974,14000,14000,12999,13245,17197,11500,

 19900,18765,13467)
df1 <- data.frame(REF1,REL1,VAL1)
REF2 <- 
c("2017-02-01","2017-02-01","2017-02-01","2017-02-01","2017-02-01",

 "2017-03-01","2017-03-01","2017-03-01","2017-03-01","2017-03-01")
REL2 <- 
c("2020-09-01","2020-08-01","2020-07-01","2020-06-01","2019-05-01",

 "2020-09-01","2020-08-01","2020-07-01","2020-06-01","2019-05-01")
VAL2 <- c(0.0,-3.9,4.3,NA,2.3,-4.3,-17.9,42.1,44.4,1.7)
df2 <- data.frame(REF2,REL2,VAL2)

In my example I have provided some sample data pertaining to three 
reference months, 2017-01-01 through 2017-03-01, and five release 
periods, "2020-09-01","2020-08-01","2020-07-01","2020-06-01" and 
"2019-05-01". In my actual problem I have millions of REF-REL 
combinations, so my data frame is quite large. I am using data.table 
for faster processing, though I am more familiar with the tidyverse. I 
am providing df2 as the target data frame for my example, so you can 
see what I am trying to achieve.


I have not been able to find an efficient way to do these 
calculations. I have tried "for" loops with "if" statements, without 
success so far, and anyway this approach would be too slow, I fear. 
Suggestions as to how I might proceed would be much appreciated.


Philip

__
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.



---
Jeff NewmillerThe .   .  Go 
Live...
DCN:Basics: ##.#.   ##.#.  Live 
Go...
  Live:   OO#.. Dead: OO#..  
Playing

Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  
rocks...1k

---


__
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.