Skip to content

Commit

Permalink
fix no pi or N case
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanWilli committed Nov 19, 2022
1 parent 9b8c0db commit 76df243
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion R/kin_time_variant.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ kin_time_variant <- function(U = NULL, f = NULL, N = NULL, pi = NULL,
if(is.null(N)){
# create pi and fill it during the loop
message("Stable assumption was made for calculating pi on each year because no input data.")
pi_N_null_flag <- TRUE
pi <- matrix(0, nrow=ages, ncol=n_years_data)
}else{
pi_N_null_flag <-FALSE
pi <- rbind(t(t(N * f)/colSums(N * f)), matrix(0,ages,length(years_data)))
}
}
Expand Down Expand Up @@ -72,7 +74,7 @@ kin_time_variant <- function(U = NULL, f = NULL, N = NULL, pi = NULL,
# print(iyear)
Ut <- as.matrix(U[[iyear]])
ft <- as.matrix(f[[iyear]])
if(is.null(pi)){
if(pi_N_null_flag){
A <- Ut[1:ages,1:ages] + ft[1:ages,1:ages]
A_decomp = eigen(A)
w <- as.double(A_decomp$vectors[,1])/sum(as.double(A_decomp$vectors[,1]))
Expand Down

0 comments on commit 76df243

Please sign in to comment.