### Simple likelihood ###
p = 0.1
q = 1 - p
afr = c("1" = p, "2" = q)
# Singleton
s = singleton() |> addMarker(geno = "1/2", afreq = afr)
stopifnot(all.equal(likelihood(s), 2*p*q))
# Trio
trio = nuclearPed() |>
addMarker(geno = c("1/1", "1/2", "1/1"), afreq = afr)
stopifnot(all.equal(likelihood(trio), p^2 * 2*p*q * 0.5))
### Example of calculation with inbred founders ###
### Case 1: Trio with inbred father
x = cousinPed(0, child = TRUE)
x = addSon(x, 5)
x = relabel(x, old = 5:7, new = c("father", "mother", "child"))
# Add equifrequent SNP; father homozygous, child heterozygous
x = addMarker(x, father = "1/1", child = "1/2")
# Plot with genotypes
plot(x, marker = 1)
# Compute the likelihood
lik1 = likelihood(x, markers = 1)
### Case 2: Using founder inbreeding
# Remove ancestry of father
y = subset(x, c("father", "mother", "child"))
# Indicate that the father has inbreeding coefficient 1/4
founderInbreeding(y, "father") = 1/4
# Plot (notice the inbreeding coefficient)
plot(y, marker = 1)
# Likelihood should be the same as above
lik2 = likelihood(y, markers = 1)
stopifnot(all.equal(lik1, lik2))
Run the code above in your browser using DataLab