magnusdv / pedprobr

Pedigree probabilities in R
GNU General Public License v2.0
4 stars 0 forks source link

`likelihood` and no genotypes #11

Closed thoree closed 4 years ago

thoree commented 4 years ago

Here are some examples of likelihood behavour that appear strange

library(pedtools)
library(pedprobr)
x1 = singleton(1)
m = marker(x1,  name = "m", alleles = 1:2)
x1 = setMarkers(x1, m)
x2 = nuclearPed(1, father = "FA")
m  = marker(x2, FA = 1, name = "m", alleles = 1:2)
x2 = setMarkers(x2, m)
likelihood(x1,x2, marker = "m")
#> [1] 1
# But
likelihood(x1, marker = "m") *likelihood(x2, marker = "m")
#> [1] 0.25
# Note also
likelihood(x2,x1, marker = "m")
#> Error: $ operator is invalid for atomic vectors
# and
likelihood(x1,x2)
#> Error in UseMethod("afreq"): no applicable method for 'afreq' applied to an object of class "character"

Created on 2020-07-09 by the reprex package (v0.3.0)

magnusdv commented 4 years ago

Many thanks, I agree that these error messages are confusing. I have improved them, and included more input checks in a recent commit.

In case you are unaware, the reason for all of these errors is that x1 and x2 must be collected in a list. The following works as expected:

library(pedprobr)
#> Loading required package: pedtools
x1 = singleton(1)
x1 = setMarkers(x1, marker(x1, name = "m", alleles = 1:2))

x2 = nuclearPed(1, father = "FA")
x2 = setMarkers(x2, marker(x2, FA = 1, name = "m", alleles = 1:2))

# Together:
likelihood(list(x1, x2), marker = "m")
#> [1] 0.25

# Separate:
likelihood(x1, marker = "m") * likelihood(x2, marker = "m")
#> [1] 0.25

Created on 2020-07-09 by the reprex package (v0.3.0)

thoree commented 4 years ago

Fine - thanks! Thore

tor. 9. jul. 2020 kl. 21:48 skrev Magnus Dehli Vigeland < notifications@github.com>:

Many thanks, I agree that these error messages are confusing. I have improved them, and included more input checks in a recent commit.

In case you are unaware, the reason for all of these errors is that x1 and x2 must be collected in a list. The following works as expected:

library(pedprobr)#> Loading required package: pedtoolsx1 = singleton(1)x1 = setMarkers(x1, marker(x1, name = "m", alleles = 1:2)) x2 = nuclearPed(1, father = "FA")x2 = setMarkers(x2, marker(x2, FA = 1, name = "m", alleles = 1:2))

Together:

likelihood(list(x1, x2), marker = "m")#> [1] 0.25

Separate:

likelihood(x1, marker = "m") * likelihood(x2, marker = "m")#> [1] 0.25

Created on 2020-07-09 by the reprex package https://reprex.tidyverse.org (v0.3.0)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/magnusdv/pedprobr/issues/11#issuecomment-656317874, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACSUNB6I6MDGKMYJ23O26OTR2YNJRANCNFSM4OVZ5IYA .