Skip to content

Commit

Permalink
Merge pull request #82 from kecoli/master
Browse files Browse the repository at this point in the history
Code fix to address plotting problems in ffm and tsfm objects. Also, see issue #41 and #58
  • Loading branch information
JustinMShea authored Mar 26, 2022
2 parents 74051bc + 3431e26 commit cf1af74
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .project
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.statet.docmlet.resourceProjects.WikitextBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>de.walware.statet.base.StatetNature</nature>
<nature>de.walware.statet.r.RNature</nature>
<nature>org.eclipse.statet.ide.resourceProjects.Statet</nature>
<nature>org.eclipse.statet.r.resourceProjects.R</nature>
<nature>org.eclipse.statet.docmlet.resourceProjects.Tex</nature>
<nature>org.eclipse.statet.docmlet.resourceProjects.Wikitext</nature>
</natures>
</projectDescription>
31 changes: 29 additions & 2 deletions R/fmCov.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,32 @@ fmCov.sfm <- function(object, use="pairwise.complete.obs", ...) {
fmCov.ffm <- function(object, use="pairwise.complete.obs", ...) {

# already computed via fitFfm function
return(object$return.cov)
}

# get parameters and factors from factor model
beta <- as.matrix(object$beta)
# convert NAs to 0 to enable matrix multiplication
beta[is.na(beta)] <- 0
sig2.e = object$resid.var
factor <- as.matrix(object$data[, object$factor.names])
factor.cov = object$factor.cov
# factor covariance matrix
if (is.null(factor.cov)) {
factor.cov = cov(factor, use=use, ...)
} else {
identical(dim(factor.cov), as.integer(c(ncol(factor), ncol(factor))))
}

# residual covariance matrix D
if (length(sig2.e) > 1) {
D.e = diag(sig2.e)
} else {
D.e = as.vector(sig2.e)
}

cov.fm = beta %*% factor.cov %*% t(beta) + D.e

if (any(diag(chol(cov.fm))==0)) {
warning("Covariance matrix is not positive definite!")
}

return(cov.fm)}
2 changes: 0 additions & 2 deletions R/tsPlotMP.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,3 @@ tsPlotMP = function (ret, add.grid = FALSE, layout = NULL, type = "l", yname = "
panel = panel)
print(pl)
}


0 comments on commit cf1af74

Please sign in to comment.