Skip to content

Commit

Permalink
fix xmu_twin_print_means
Browse files Browse the repository at this point in the history
  • Loading branch information
tbates committed Jul 20, 2022
1 parent 5e3c0ae commit 9a647a2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
1 change: 0 additions & 1 deletion R/fit_and_reporting.R
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,6 @@ umxSummaryACE <- function(model, digits = 2, comparison = NULL, std = TRUE, show
xmu_show_fit_or_comparison(model, comparison = comparison, digits = digits)
selDVs = xmu_twin_get_var_names(model, trim= TRUE, twinOneOnly= TRUE)
nVar = length(selDVs)

# TODO umxSummaryACE these already exist if a_std exists..
# TODO replace all this with xmu_standardizeACE
# Calculate standardized variance components
Expand Down
46 changes: 26 additions & 20 deletions R/xmu.R
Original file line number Diff line number Diff line change
Expand Up @@ -301,40 +301,46 @@ xmu_safe_run_summary <- function(model1, model2 = NULL, autoRun = TRUE, tryHard
# xmu_twin_print_means(model, digits = digits, report = report)
xmu_twin_print_means <- function(model, digits = 3, report = c("markdown", "html")){
report = match.arg(report)
int = model$top$intercept$values
if(!is.null(int)){
# get intercept, e.g. mean T1, T2
interceptVals = model$top$intercept$values
meanVals = interceptVals
if(!is.null(interceptVals)){
# means and betas
caption = "Means and (raw) betas from model$top$intercept and model$top$meansBetas"
b = model$top$meansBetas$values
bcols = dim(b)[[2]]
bvals = b[,1:bcols, drop = FALSE]
interceptsPerSib = dim(int)[[2]]/bcols
if(interceptsPerSib==2){
int = rbind(int, cbind(bvals, bvals))
} else if(interceptsPerSib==3){
int = rbind(int, cbind(bvals, bvals, bvals))
# e.g.
# m1$top$meansBetas$values
# ht
# age -0.0005409507
# cohort -0.0045778153

bNtraits = dim(b)[[2]]
# force this to become a dataframe
bVals = b[ ,1:bNtraits, drop = FALSE]
nSib = dim(interceptVals)[[2]]/bNtraits
if(nSib==2){
widebVals = cbind(bVals, bVals)
} else if(nSib==3){
widebVals = cbind(bVals, bVals, bVals)
}else{
umx_msg("Polite note: email package maintainer as this number of means not expected")
}
row.names(int) = c("intercept", "beta")
meanVals = rbind(interceptVals, widebVals)
# row.names(meanVals) = c("intercept", paste0("beta", 1:bNtraits))
row.names(meanVals)[1] = "intercept"
} else {
int = model$top$expMean$values
if(!is.null(int)){
meanVals = model$top$expMean$values
if(!is.null(meanVals)){
# expMeans
caption = "Means (from model$top$expMean)"
row.names(int) = "intercept"
row.names(meanVals) = "intercept"
}else{
# no means
}
}

if(!is.null(int)){
umx_print(int, digits = digits, caption = caption, report=report, append = TRUE, sortableDF = TRUE)
# if(report == "html"){
# # depends on R2HTML::HTML
# R2HTML::HTML(int, file = "tmp.html", Border = 0, append = TRUE, sortableDF = TRUE);
# umx_open("tmp.html")
# }
if(!is.null(meanVals)){
umx_print(meanVals, digits = digits, caption = caption, report=report, append = TRUE, sortableDF = TRUE)
}
}

Expand Down

0 comments on commit 9a647a2

Please sign in to comment.