Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code fix to address plotting problems in ffm and tsfm objects #82

Merged
merged 4 commits into from
Mar 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}