[R] how to calculate multiple meta p values

Michael Dewey ||@t@ @end|ng |rom dewey@myzen@co@uk
Sun Oct 27 15:49:40 CET 2019


Dear Ana

There must be several ways of doing this but see below for an idea with 
comments in-line.

On 26/10/2019 00:31, Ana Marija wrote:
> Hello,
> 
> I would like to use this package metap
> to calculate multiple o values
> 
> I have my data frame with 3 p values
>> head(tt)
>            RS            G           E          B
> 1: rs2089177   0.9986   0.7153   0.604716
> 2: rs4360974   0.9738   0.7838   0.430228
> 3: rs6502526   0.9744   0.7839   0.429160
> 4: rs8069906   0.7184   0.4918   0.521452
> 5: rs9905280   0.7205   0.4861   0.465758
> 6: rs4313843   0.9804   0.8522   0.474313
> 
> and data frame with corresponding weights for each of the p values
> from the tt data frame
> 
>> head(df)
>         wg       we             wb                RS
> 1 40.6325 35.39774 580.6436 rs2089177
> 2 40.6325 35.39774 580.6436 rs4360974
> 3 40.6325 35.39774 580.6436 rs6502526
> 4 40.6325 35.39774 580.6436 rs8069906
> 5 40.6325 35.39774 580.6436 rs9905280
> 6 40.6325 35.39774 580.6436 rs4313843
> 
> RS column is the same in df and tt
> 

So you can create a new data-frame with merge()

newdata <- merge(tt, df)

which will use RS as the key to merge them on.

The write a function of one argument, a seven element vector, which 
picks out the p-values and the weights and feeds them to sumz(). 
Something like

helper <- function(x) {
  p <- sumz(x[2:4], weights = x[5:7])$p
  p
}
Note you need to check that 2:4 and 5:7 are actually where they are in 
the row of newdat.

Then use apply() to apply that to the rows of newdat.

I have not tested any of this but the general idea should be OK even if 
the details are wrong.

Michael


> How to use this sunz() function to create a new data frame which would
> look the same as tt only it would have additional column, say named
> "META" which has calculated meta p values for each row
> 
> This i s example of how much would be p value in the first row:
> 
>> sumz(c(0.9986,0.7153,0.604716), weights = c(40.6325,35.39774,580.6436), na.action = na.fail)
> p =  0.6940048
> 
> Thanks
> Ana
> 
> ______________________________________________
> 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.
> 

-- 
Michael
http://www.dewey.myzen.co.uk/home.html



More information about the R-help mailing list