Skip to content

Commit

Permalink
zero branch lengths actually allowed, most of the time
Browse files Browse the repository at this point in the history
  • Loading branch information
pbastide committed Jul 6, 2022
1 parent 2b744d9 commit 0100906
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/traits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ end
function checkBranchLengths(net::HybridNetwork)
branches = [e.number for e in net.edge]
undefined = branches[[e.length == -1.0 for e in net.edge]]
negatives = branches[[e.length <= 0 for e in net.edge]]
negatives = branches[[e.length < 0 for e in net.edge]]
str = "The variance-covariance matrix of the network is not defined, and the phylogenetic regression cannot be done."
if (length(undefined) > 0)
error(string("Branches ", undefined, " have no length in the network. ", str))
Expand Down
20 changes: 12 additions & 8 deletions test/test_lm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -629,19 +629,23 @@ end
###############################################################################
@testset "Undefined branch length" begin
## No branch length
net = readTopology("(A,((B:1,#H1:1::0.1):1,(C:1,(D:1)#H1:1::0.9):1):0.5);");
net = readTopology("(A:2.5,((B,#H1:1::0.1):1,(C:1,(D:1)#H1:1::0.9):1):0.5);");
dfr = DataFrame(trait = [11.6,8.1,10.3,9.1], tipNames = ["A","B","C","D"]);
@test_throws ErrorException("Branches [1] have no length in the network. The variance-covariance matrix of the network is not defined, and the phylogenetic regression cannot be done.") phylolm(@formula(trait ~ 1), dfr, net);
@test_throws ErrorException("Branches [2] have no length in the network. The variance-covariance matrix of the network is not defined, and the phylogenetic regression cannot be done.") phylolm(@formula(trait ~ 1), dfr, net);
## Negative branch length
net.edge[1].length = -0.5;
@test_throws ErrorException("Branches [1] have a negative or zero length in the network. The variance-covariance matrix of the network is not defined, and the phylogenetic regression cannot be done.") phylolm(@formula(trait ~ 1), dfr, net);
net.edge[2].length = -0.5;
@test_throws ErrorException("Branches [2] have a negative or zero length in the network. The variance-covariance matrix of the network is not defined, and the phylogenetic regression cannot be done.") phylolm(@formula(trait ~ 1), dfr, net);
## Zero branch length
net.edge[1].length = 0.0;
@test_throws ErrorException("Branches [1] have a negative or zero length in the network. The variance-covariance matrix of the network is not defined, and the phylogenetic regression cannot be done.") phylolm(@formula(trait ~ 1), dfr, net);
net.edge[2].length = 0.0;
fit = phylolm(@formula(trait ~ 1), dfr, net);
@test loglikelihood(fit) -6.245746681512051
## Non zero branch length
net.edge[1].length = 0.1;
net.edge[2].length = 0.1;
fit = phylolm(@formula(trait ~ 1), dfr, net);
@test loglikelihood(fit) -6.522868090996417
@test loglikelihood(fit) -6.2197697662066815
## Illicit zero branch length
net.edge[1].length = 0.0;
@test_throws PosDefException phylolm(@formula(trait ~ 1), dfr, net);
end

############################
Expand Down

0 comments on commit 0100906

Please sign in to comment.