Skip to content

Commit

Permalink
Fix restype inconsistentcy within LCA in-sample values - lca.R
Browse files Browse the repository at this point in the history
See Issue robjhyndman#56
  • Loading branch information
HoxD authored Oct 10, 2023
1 parent 3f45c28 commit 3b6dbb7
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions R/lca.R
Original file line number Diff line number Diff line change
Expand Up @@ -234,22 +234,22 @@ lca <- function(data,series=names(data$rate)[1],years=data$year, ages=data$age,
# Omit breakpoints less than minperiod from end
bp <- bp[bp <= (m-minperiod)]
bestbreak <- max(bp)
return(lca(data,series,year[(bestbreak+1):m],ages=ages,max.age=max.age,
adjust=adjust,interpolate=interpolate,chooseperiod=FALSE,scale=scale))
return(lca(data,series,year[(bestbreak+1):m],ages=ages,max.age=max.age,adjust=adjust,chooseperiod=FALSE,
restype=restype,interpolate=interpolate,scale=scale))
}
else
{
RS <- devlin <- devadd <- numeric(m-2)
for(i in 1:(m-2))
{
tmp <- lca(data,series,year[i:m],ages=ages,max.age=max.age,adjust=adjust,chooseperiod=FALSE,interpolate=interpolate,scale=scale)
tmp <- lca(data,series,year[i:m],ages=ages,max.age=max.age,adjust=adjust,chooseperiod=FALSE,restype=restype,interpolate=interpolate,scale=scale)
devlin[i] <- tmp$mdev[2]
devadd[i] <- tmp$mdev[1]
RS[i] <- (tmp$mdev[2]/tmp$mdev[1])
}
bestbreak <- order(RS[1:(m-minperiod)])[1]-1
out <- lca(data,series,year[(bestbreak+1):m],ages=ages,max.age=max.age,
adjust=adjust,chooseperiod=FALSE,interpolate=interpolate,scale=scale)
out <- lca(data,series,year[(bestbreak+1):m],ages=ages,max.age=max.age,adjust=adjust,chooseperiod=FALSE,
restype=restype,interpolate=interpolate,scale=scale)
out$mdevs <- ts(cbind(devlin,devadd,RS),start=startyear,deltat=deltat)
dimnames(out$mdevs)[[2]] <- c("Mean deviance total","Mean deviance base","Mean deviance ratio")
return(out)
Expand Down

0 comments on commit 3b6dbb7

Please sign in to comment.