R Under development (unstable) (2025-09-02 r88773 ucrt) -- "Unsuffered Consequences" Copyright (C) 2025 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > > ## test pedigree from bioinformatics manuscript > ## try x-chrom kinship > ## also has inbreeding and twins, for quick check > require(kinship2) Loading required package: kinship2 Loading required package: Matrix Loading required package: quadprog Warning: kinship2 package is deprecated for R <= 4.5; switch functionality to Pedixplorer from BioConductor> ped2mat <- matrix(c(1,1,0,0,1, + 1,2,0,0,2, + 1,3,1,2,1, + 1,4,1,2,2, + 1,5,0,0,2, + 1,6,0,0,1, + 1,7,3,5,2, + 1,8,6,4,1, + 1,9,6,4,1, + 1,10,8,7,2),ncol=5,byrow=TRUE) > > ped2df <- as.data.frame(ped2mat) > names(ped2df) <- c("fam", "id", "dad", "mom", "sex") > ## 1 2 3 4 5 6 7 8 9 10,11,12,13,14,15,16 > ped2df$disease= c(NA,NA,1,0,0,0,0,1,1,1) > ped2df$smoker= c(0,NA,0,0,1,1,1,0,0,0) > ped2df$availstatus=c(0,0, 1,1,0,1,1,1,1,1) > ped2df$vitalstatus=c(1,1, 1,0,1,0,0,0,0,0) > > ped2 <- with(ped2df, pedigree(id, dad, mom, sex, status=vitalstatus, + affected=cbind(disease,smoker, availstatus), relation=matrix(c(8,9,1),ncol=3))) > > ## regular kinship matrix > kinship(ped2) 1 2 3 4 5 6 7 8 9 10 1 0.500 0.000 0.2500 0.2500 0.000 0.000 0.12500 0.12500 0.12500 0.12500 2 0.000 0.500 0.2500 0.2500 0.000 0.000 0.12500 0.12500 0.12500 0.12500 3 0.250 0.250 0.5000 0.2500 0.000 0.000 0.25000 0.12500 0.12500 0.18750 4 0.250 0.250 0.2500 0.5000 0.000 0.000 0.12500 0.25000 0.25000 0.18750 5 0.000 0.000 0.0000 0.0000 0.500 0.000 0.25000 0.00000 0.00000 0.12500 6 0.000 0.000 0.0000 0.0000 0.000 0.500 0.00000 0.25000 0.25000 0.12500 7 0.125 0.125 0.2500 0.1250 0.250 0.000 0.50000 0.06250 0.06250 0.28125 8 0.125 0.125 0.1250 0.2500 0.000 0.250 0.06250 0.50000 0.50000 0.28125 9 0.125 0.125 0.1250 0.2500 0.000 0.250 0.06250 0.50000 0.50000 0.28125 10 0.125 0.125 0.1875 0.1875 0.125 0.125 0.28125 0.28125 0.28125 0.53125 > > kinship(ped2, chr="X") 1 2 3 4 5 6 7 8 9 10 1 1.00 0.00 0.000 0.5000 0.000 0 0.0000 0.5000 0.5000 0.2500 2 0.00 0.50 0.500 0.2500 0.000 0 0.2500 0.2500 0.2500 0.2500 3 0.00 0.50 1.000 0.2500 0.000 0 0.5000 0.2500 0.2500 0.3750 4 0.50 0.25 0.250 0.5000 0.000 0 0.1250 0.5000 0.5000 0.3125 5 0.00 0.00 0.000 0.0000 0.500 0 0.2500 0.0000 0.0000 0.1250 6 0.00 0.00 0.000 0.0000 0.000 1 0.0000 0.0000 0.0000 0.0000 7 0.00 0.25 0.500 0.1250 0.250 0 0.5000 0.1250 0.1250 0.3125 8 0.50 0.25 0.250 0.5000 0.000 0 0.1250 1.0000 1.0000 0.5625 9 0.50 0.25 0.250 0.5000 0.000 0 0.1250 1.0000 1.0000 0.5625 10 0.25 0.25 0.375 0.3125 0.125 0 0.3125 0.5625 0.5625 0.5625 > > ped2$sex[9] <- "unknown" > > ## regular again, should be same as above > kinship(ped2) 1 2 3 4 5 6 7 8 9 10 1 0.500 0.000 0.2500 0.2500 0.000 0.000 0.12500 0.12500 0.12500 0.12500 2 0.000 0.500 0.2500 0.2500 0.000 0.000 0.12500 0.12500 0.12500 0.12500 3 0.250 0.250 0.5000 0.2500 0.000 0.000 0.25000 0.12500 0.12500 0.18750 4 0.250 0.250 0.2500 0.5000 0.000 0.000 0.12500 0.25000 0.25000 0.18750 5 0.000 0.000 0.0000 0.0000 0.500 0.000 0.25000 0.00000 0.00000 0.12500 6 0.000 0.000 0.0000 0.0000 0.000 0.500 0.00000 0.25000 0.25000 0.12500 7 0.125 0.125 0.2500 0.1250 0.250 0.000 0.50000 0.06250 0.06250 0.28125 8 0.125 0.125 0.1250 0.2500 0.000 0.250 0.06250 0.50000 0.50000 0.28125 9 0.125 0.125 0.1250 0.2500 0.000 0.250 0.06250 0.50000 0.50000 0.28125 10 0.125 0.125 0.1875 0.1875 0.125 0.125 0.28125 0.28125 0.28125 0.53125 > > ## now with unknown sex, gets NAs > kinship(ped2, chrtype="X") 1 2 3 4 5 6 7 8 9 10 1 1.00 0.00 0.000 0.5000 0.000 0 0.0000 0.5000 NA 0.2500 2 0.00 0.50 0.500 0.2500 0.000 0 0.2500 0.2500 NA 0.2500 3 0.00 0.50 1.000 0.2500 0.000 0 0.5000 0.2500 NA 0.3750 4 0.50 0.25 0.250 0.5000 0.000 0 0.1250 0.5000 NA 0.3125 5 0.00 0.00 0.000 0.0000 0.500 0 0.2500 0.0000 NA 0.1250 6 0.00 0.00 0.000 0.0000 0.000 1 0.0000 0.0000 NA 0.0000 7 0.00 0.25 0.500 0.1250 0.250 0 0.5000 0.1250 NA 0.3125 8 0.50 0.25 0.250 0.5000 0.000 0 0.1250 1.0000 1 0.5625 9 NA NA NA NA NA NA NA NA NA NA 10 0.25 0.25 0.375 0.3125 0.125 0 0.3125 0.5625 NA 0.5625 > > ped2$sex[9]="unknown" > kinship(ped2, chrtype="x") 1 2 3 4 5 6 7 8 9 10 1 1.00 0.00 0.000 0.5000 0.000 0 0.0000 0.5000 NA 0.2500 2 0.00 0.50 0.500 0.2500 0.000 0 0.2500 0.2500 NA 0.2500 3 0.00 0.50 1.000 0.2500 0.000 0 0.5000 0.2500 NA 0.3750 4 0.50 0.25 0.250 0.5000 0.000 0 0.1250 0.5000 NA 0.3125 5 0.00 0.00 0.000 0.0000 0.500 0 0.2500 0.0000 NA 0.1250 6 0.00 0.00 0.000 0.0000 0.000 1 0.0000 0.0000 NA 0.0000 7 0.00 0.25 0.500 0.1250 0.250 0 0.5000 0.1250 NA 0.3125 8 0.50 0.25 0.250 0.5000 0.000 0 0.1250 1.0000 1 0.5625 9 NA NA NA NA NA NA NA NA NA NA 10 0.25 0.25 0.375 0.3125 0.125 0 0.3125 0.5625 NA 0.5625 > > > # all descendants of sex=unknown to be NAs as well > ped2$sex[8]="unknown" > kinship(ped2, chr="X") 1 2 3 4 5 6 7 8 9 10 1 1.0 0.00 0.00 0.500 0.00 0 0.000 NA NA NA 2 0.0 0.50 0.50 0.250 0.00 0 0.250 NA NA NA 3 0.0 0.50 1.00 0.250 0.00 0 0.500 NA NA NA 4 0.5 0.25 0.25 0.500 0.00 0 0.125 NA NA NA 5 0.0 0.00 0.00 0.000 0.50 0 0.250 NA NA NA 6 0.0 0.00 0.00 0.000 0.00 1 0.000 NA NA NA 7 0.0 0.25 0.50 0.125 0.25 0 0.500 NA NA NA 8 NA NA NA NA NA NA NA NA NA NA 9 NA NA NA NA NA NA NA NA NA NA 10 NA NA NA NA NA NA NA NA NA NA > > > ## testing kinship2 on pedigreeList when only one subject in a family > peddf <- rbind(ped2df, c(2,1,0,0,1,1,0,1,0)) > > peds <- with(peddf, pedigree(id, dad, mom, sex, status=vitalstatus,fam=fam, + affected=cbind(disease,smoker, availstatus))) > > kinfam <- kinship(peds) > > kinfam 11 x 11 sparse Matrix of class "dsCMatrix" [[ suppressing 11 column names '1/1', '1/2', '1/3' ... ]] 1/1 0.500 . 0.2500 0.2500 . . 0.12500 0.12500 0.12500 0.12500 . 1/2 . 0.500 0.2500 0.2500 . . 0.12500 0.12500 0.12500 0.12500 . 1/3 0.250 0.250 0.5000 0.2500 . . 0.25000 0.12500 0.12500 0.18750 . 1/4 0.250 0.250 0.2500 0.5000 . . 0.12500 0.25000 0.25000 0.18750 . 1/5 . . . . 0.500 . 0.25000 . . 0.12500 . 1/6 . . . . . 0.500 . 0.25000 0.25000 0.12500 . 1/7 0.125 0.125 0.2500 0.1250 0.250 . 0.50000 0.06250 0.06250 0.28125 . 1/8 0.125 0.125 0.1250 0.2500 . 0.250 0.06250 0.50000 0.25000 0.28125 . 1/9 0.125 0.125 0.1250 0.2500 . 0.250 0.06250 0.25000 0.50000 0.15625 . 1/10 0.125 0.125 0.1875 0.1875 0.125 0.125 0.28125 0.28125 0.15625 0.53125 . 2/1 . . . . . . . . . . 0.5 > > ## now add two more for ped2, and check again > peddf <- rbind(peddf, c(2,2,0,0,2,1,0,1,0),c(2,3,1,2,1,1,0,1,0)) > > peds <- with(peddf, pedigree(id, dad, mom, sex, status=vitalstatus,fam=fam, + affected=cbind(disease,smoker, availstatus))) > > kin2fam <- kinship(peds) > > kin2fam 13 x 13 sparse Matrix of class "dsCMatrix" [[ suppressing 13 column names '1/1', '1/2', '1/3' ... ]] 1/1 0.500 . 0.2500 0.2500 . . 0.12500 0.12500 0.12500 0.12500 . 1/2 . 0.500 0.2500 0.2500 . . 0.12500 0.12500 0.12500 0.12500 . 1/3 0.250 0.250 0.5000 0.2500 . . 0.25000 0.12500 0.12500 0.18750 . 1/4 0.250 0.250 0.2500 0.5000 . . 0.12500 0.25000 0.25000 0.18750 . 1/5 . . . . 0.500 . 0.25000 . . 0.12500 . 1/6 . . . . . 0.500 . 0.25000 0.25000 0.12500 . 1/7 0.125 0.125 0.2500 0.1250 0.250 . 0.50000 0.06250 0.06250 0.28125 . 1/8 0.125 0.125 0.1250 0.2500 . 0.250 0.06250 0.50000 0.25000 0.28125 . 1/9 0.125 0.125 0.1250 0.2500 . 0.250 0.06250 0.25000 0.50000 0.15625 . 1/10 0.125 0.125 0.1875 0.1875 0.125 0.125 0.28125 0.28125 0.15625 0.53125 . 2/1 . . . . . . . . . . 0.50 2/2 . . . . . . . . . . . 2/3 . . . . . . . . . . 0.25 1/1 . . 1/2 . . 1/3 . . 1/4 . . 1/5 . . 1/6 . . 1/7 . . 1/8 . . 1/9 . . 1/10 . . 2/1 . 0.25 2/2 0.50 0.25 2/3 0.25 0.50 > > proc.time() user system elapsed 0.75 0.18 0.92