Skip to content

Commit 9824de4

Browse files
committed
Merge branch 'master' of https://github.com/tbates/umx
2 parents e28a935 + adad762 commit 9824de4

23 files changed

+1056
-929
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export(deg2rad)
6464
export(dl_from_dropbox)
6565
export(fin_JustifiedPE)
6666
export(fin_NI)
67+
export(fin_expected)
6768
export(fin_interest)
6869
export(fin_percent)
6970
export(fin_ticker)

R/financial functions.R

Lines changed: 561 additions & 0 deletions
Large diffs are not rendered by default.

R/fit_and_reporting.R

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,18 @@ umxPlot <- function(x, y= NULL, data, xlab= x, ylab = y, title = paste0(y, " as
9090
# p + annotate("text", 3, 30, label = expression(R^2 == beta + 1 ~ hello), family="Optima")
9191
}
9292

93-
#' `umxPlotPredict` takes a model and plots the y value against predicted(y)
93+
94+
#' `umxPlotPredict` Take a model and plot the y against predicted(y)
95+
#' @description
96+
#' `umxPlotPredict` is a function which
9497
#' @param model lm or other model that understands predict()
9598
#' @param xlab X-axis label (default x).
9699
#' @param ylab Y-axis label (default y).
97100
#' @param r2x x location for the fit summary.
98101
#' @param r2y y location for the fit summary.
99102
#' @param font_size Default 13
100103
#' @param font Default "Times"
104+
#' @param rsq R^2 or r (defaults to FALSE = r)
101105
#' @return - plot you can edit.
102106
#' @export
103107
#' @family Plotting functions
@@ -107,13 +111,19 @@ umxPlot <- function(x, y= NULL, data, xlab= x, ylab = y, title = paste0(y, " as
107111
#' data(mtcars)
108112
#' tmp = lm(mpg ~ wt, data = mtcars)
109113
#' umxPlotPredict(tmp, r2x = 2, r2y = 10)
110-
umxPlotPredict <- function(model, xlab= "Predicted Y", ylab= "Observed Y", r2x= 1.5, r2y= 4.5, font_size = 13, font= "Times") {
111-
r2 = paste0("r = ", round(summary(model)$adj.r.squared^.5, 2))
114+
umxPlotPredict <- function(model, xlab= "Predicted Y", ylab= "Observed Y", r2x= 1.5, r2y= 4.5, font_size = 13, rsq = FALSE, font= "Times") {
115+
if(rsq){
116+
# lab = paste0("R\u00B2 = ", round(summary(model)$adj.r.squared, 2))
117+
lab = paste0("italic(R) ^ 2 == ", round(summary(model)$adj.r.squared, 2))
118+
} else {
119+
lab = paste0("italic(r) == ", round(summary(model)$adj.r.squared^.5, 2))
120+
}
112121
y_var = model.frame(model)[, 1]
113122
p = ggplot() + geom_point(aes(x = predict(model), y = y_var))
114123
p = p + geom_smooth(aes(x = predict(model), y = y_var), method = "lm", se = TRUE, color = "blue")
115124
p = p + labs(x= xlab, y= ylab)
116-
p = p + cowplot::draw_label(r2, x = r2x, y = r2y, fontfamily = font, size = (font_size+1))
125+
p = p + annotate("text", x = r2x, y = r2y, label = lab, parse = TRUE, family = font, size = (font_size/2))
126+
# p = p + cowplot::draw_label(lab, x = r2x, y = r2y, fontfamily = font, size = (font_size+1))
117127
p + theme_minimal(base_size = font_size, base_family= font)
118128
}
119129

0 commit comments

Comments
 (0)