• Sign Up
• Login
• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Aug 14th, 2019 42 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. fam <- structure(list(ID = c(1L, 2L, 3L, 4L, 6L, 5L, 7L), dad = c(0L,
2.                                                                   0L, 1L, 1L, 1L, 3L, 5L), mum = c(0L, 0L, 0L, 2L, 4L, 4L, 6L),
3.                       GEN = c(1L, 1L, 2L, 2L, 3L, 3L, 4L)), class = "data.frame", row.names = c(NA,
4.                                                                                                 -7L))
5.
6. library(Matrix)
7.
8. hom = function(fam) {
9.   t1 <- min(which.max(fam\$dad > 0), which.max(fam\$mum > 0))
10.   t2 <- max(fam[["ID"]])
11.
12.   A<-Matrix(0, nrow=t2,ncol=t2, sparse=TRUE)
13.   diag(A) <- 2-0.5^(fam[["GEN"]]-1)
14.
15.   for (t in t1:t2) {
16.     A[t,t]<- sum(c(A[t,t],     0.5^(fam[t,"GEN"])*A[fam[t,"dad"],fam[t,"mum"]]))
17.     for(j in 1:(t-1))  {
18.       A[t,j]<- 0.5 * sum(c(A[j,fam[t,"dad"]],A[j,fam[t,"mum"]]))
19.       A <- tril(A) + t(tril(A, -1))
20.     }
21.   }
22.   A
23. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top