简体   繁体   English

R数据帧上的反向重新缩放

[英]Inversed rescaling on R dataframe

I am currently using R to assign mutation significance values to proteins in yeast.我目前正在使用 R 为酵母中的蛋白质分配突变显着性值。

I have a data frame that looks like this:我有一个看起来像这样的数据框:

             Genes q_values
1             HNT1 4.836462e-01
2            EMP47 6.792469e-01
3             QDR2 6.357284e-01
4             TMS1 9.781394e-01
5             TMS1 8.672664e-01
...

However, on occasion there will be a q_value significantly lower than the others:但是,有时 q_value 会显着低于其他值:

...
35            HHF1 5.565396e-01
36            RGA2 2.323061e-12
37           CDC24 8.174687e-01
...

# Notice how value for row 36 is very low

I want to rescale these q_values onto a 1-10000 scale.我想将这些 q_values 重新缩放到 1-10000 的比例。 However, I need the highest original q_value (ie ~9.85e-01) to be the lowest on the new scale (ei a value of 1).但是,我需要最高的原始 q_value (即 ~9.85e-01)在新的尺度上是最低的(ei 值为 1)。 Inversely, the lowest original q_value (ie ~1.36e-13) needs to be the highest on the new scale (ei a value of 10000).相反,最低的原始 q_value(即~1.36e-13)需要在新尺度上是最高的(ei 值为 10000)。

I have tried making a variation of the equation proposed here: https://stats.stackexchange.com/questions/25894/changing-the-scale-of-a-variable-to-0-100 .我尝试对此处提出的方程式进行变体: https ://stats.stackexchange.com/questions/25894/changeing-the-scale-of-a-variable-to-0-100。 However I did not manage to get the results I am looking far.但是,我没有设法得到我期待的结果。

What would be the best way to go about doing this?这样做的最佳方法是什么?

Maybe you can try the code below for rescaling the q values也许您可以尝试下面的代码来重新调整 q 值

within(df, rescaled_q_values <- 1e5*(max(new_q_values)-new_q_values)/diff(range(new_q_values)))

which gives这使

   new_yeast_genes new_q_values rescaled_q_values
1             HNT1 4.836462e-01          50554.47
2            EMP47 6.792469e-01          30557.25
3             QDR2 6.357284e-01          35006.36
4             TMS1 9.781394e-01              0.00
5             TMS1 8.672664e-01          11335.09
35            HHF1 5.565396e-01          43102.22
36            RGA2 2.323061e-12         100000.00
37           CDC24 8.174687e-01          16426.16

Data数据

df <- structure(list(new_yeast_genes = c("HNT1", "EMP47", "QDR2", "TMS1",
"TMS1", "HHF1", "RGA2", "CDC24"), new_q_values = c(0.4836462, 
0.6792469, 0.6357284, 0.9781394, 0.8672664, 0.5565396, 2.323061e-12,
0.8174687)), class = "data.frame", row.names = c("1", "2", "3",
"4", "5", "35", "36", "37"))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM