-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpve.R
32 lines (31 loc) · 835 Bytes
/
pve.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 14-11-2020 JHZ
require(gap)
t <- read.delim("INF1.tbl",as.is=TRUE)
tbl <- within(t, {
prot <- sapply(strsplit(Chromosome,":"),"[",1)
Chromosome <- sapply(strsplit(Chromosome,":"),"[",2)
})
## to obtain variance explained
tbl <- within(tbl,
{
x2 <- (Effect/StdErr)^2
r2 <- x2 / (N - 2 + x2)
v <- 1 / (N - 1)
# r
# r <- sqrt(r2)
# vr <- (1 - r2)^2/ N
# Taylor expansion
# v2 <- 2 * r2^2 * (1 + 1/ (N + 1)^2)
})
s <- with(tbl, aggregate(r2,list(prot),sum))
names(s) <- c("prot", "pve")
se2 <- with(tbl, aggregate(v,list(prot),sum))
names(se2) <- c("p1","v")
m <- with(tbl, aggregate(r2,list(prot),length))
names(m) <- c("p2","m")
pve <- cbind(s,se2,m)
ord <- with(pve, order(pve))
sink("pve.dat")
print(pve[ord, c("prot","pve","v","m")], row.names=FALSE)
sink()
write.csv(tbl,file="INF1.csv",quote=FALSE,row.names=FALSE)