#' Another mean function for EM
#'
#' Another mean function for EM
#' @param theta parameters to be estimated
#' @param n.mixt number of mixture.
#' @param p.sites the composition of each site.
#' @keywords mean function
#' @export
#' @examples
#' data("wq_analysis_week2")
#' SPTMData(wq.raw.obs, frequency = "quarter")
meanFunc2 = function(theta, n.mixt = 4, p.sites, season.lu, trend.lu){
cms = matrix(theta, ncol = n.mixt, byrow = T)
# Method 1
Fint = kronecker(diag(n.mixt),rep(1, nrow(season.lu)))
Fs = kronecker(diag(n.mixt),season.lu[,1])
Ft = kronecker(diag(n.mixt),trend.lu[,1])
idx.F = 1:nrow(season.lu)
for(i in 2:n.mixt){
idx.F = seq_len(nrow(season.lu)) + max(idx.F)
Fs[idx.F,i] = season.lu[,i]
Ft[idx.F,i] = trend.lu[,i]
}
mF = matrix(Fint %*% matrix(cms[1,], ncol=1), ncol = n.mixt)
tF = matrix(Ft %*% matrix(cms[2,], ncol=1), ncol = n.mixt)
sF = matrix(Fs %*% matrix(cms[3,], ncol=1), ncol = n.mixt)
F = cbind(Fint, Ft, Fs)
res = matrix(F %*% theta[1:(length(theta)-n.mixt)], ncol = n.mixt)
return(res)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.