#' Update the seasons for LU
#'
#' Update the seasons for LU
#' @param season.sites the season calculated for each site.
#' @param p.sites the composition of each site.
#' @keywords updating season
#' @export
#' @examples
#' data("wq_analysis_week2")
#' SPTMData(wq.raw.obs, frequency = "quarter")
criteriaComp = function(SPTMresobj){
theta = SPTMresobj$Result$theta
p.sites = SPTMresobj$Result$latent
season.sites = SPTMresobj$seasonSites
trend.sites = SPTMresobj$trendSites
y.p = meanFunc(theta, n.mixt=ncol(p.sites), p.sites=p.sites, season.sites = season.sites)
idx.sigma = (length(theta) - ncol(p.sites) + 1):length(theta)
if(!is.null(SPTMresobj$GibbsOut)){
theta[idx.sigma] = log(sqrt(theta[idx.sigma]))
}
df = SPTMresobj$data$data
SiteID = unique(df$obs.data$ID)
n.sites = length(SiteID)
RSS = 0
RSE = 0
for(i in 1:n.sites){
obs = df$obs.data$obs[df$obs.data$ID %in% SiteID[i]]
idx.k = matrix(p.sites[i,], ncol=1)
pred= y.p %*% idx.k
RSS = RSS + sum((obs - pred)^2, na.rm=T)
RSE = RSE + sum((obs - mean(obs, na.rm=T))^2, na.rm=T)
}
return(list(RSS = RSS, R2 = 1 - RSS / RSE))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.