[R] covar

Juliet Hannah juliet.hannah at gmail.com
Sun Feb 20 15:38:59 CET 2011


Relatedness if often defined in terms of the kinship matrix. It may be
helpful to search for this. Several packages in R use this matrix
including the kinship package.

On Wed, Feb 16, 2011 at 3:14 PM, Val <valkremk at gmail.com> wrote:
> Hi all,
>
> I want to construct relatedness among individuals and have a look at the
> following script.
>
> #########################
> rm(list=ls())
>
> N=5
> id   = c(1:N)
> dad = c(0,0,0,3,3)
> mom  = c(0,0,2,1,1)
> sex  = c(2,2,1,2,2) # 1= M and 2=F
>
>   A=diag(nrow = N)
>   for(i in 1:N)    {
>      for(j in i:N)      {
>         ss = dad[j]
>         dd = mom[j]
>         sx = sex[j]
>          if( ss > 0 && dd > 0 )
>            {
>              if(i == j)
>                   { A[i,i] = 1 + 0.5*A[ss,dd] }
>                 else
>                  { A[i,j] = A[i,ss] + 0.5*(A[i,dd])
>                    A[j,i] = A[i,j] }
>            }
>
>      } #inner for loop
>     } # outer for loop
>  A
>
> If the sex is male ( sex=1)  then I want to set A[i,i]=0.5*A[ss,dd]
> If it is female ( sex=2) then A[i,i] = 1 + 0.5*A[ss,dd]
>
>
> How do I do it ?
>
> I tried several cases but it did not work from me. Your assistance is
> highly  appreciated  in advance
>
> Thanks
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.
>



More information about the R-help mailing list