:ext QuasiQuotes
import qualified H.Prelude as H
H.initialize H.defaultConfig
[r| require("ggplot2")
require("pracma")|]
Testing R Globals .. Must use <<- for assignment
[r| lm_eqn <<- function(df){
m <- lm(actualA ~ predictionA, df);
eq <- substitute(italic(y) == a + b %.% italic(x)*","~~italic(r)^2~"="~r2,
list(a = format(unname(coef(m)[1]), digits = 2),
b = format(unname(coef(m)[2]), digits = 2),
r2 = format(summary(m)$r.squared, digits = 3)))
as.character(as.expression(eq));
} |]
[r|
ggplotRegression <<- function(the.title, dat, xvar, yvar){
require(ggplot2)
fit <- lm(yvar~xvar, dat)
ggplot(fit$model, aes_string(x = names(fit$model)[2], y = names(fit$model)[1])) +
geom_point(size=2, shape=21) +
ggtitle(the.title) +
theme(plot.title = element_text(hjust = 0.5)) +
theme(plot.caption = element_text(hjust = 0.5)) +
theme(text=element_text(family="Ariel", size=12)) +
stat_smooth(method = "lm", col = "red", se=FALSE) +
labs( caption = paste("RSq = ",signif(summary(fit)$r.squared, 5),
"Intercept =",signif(fit$coef[[1]],5 ),
" Slope =",signif(fit$coef[[2]], 5),
" P =",signif(summary(fit)$coef[2,4], 5)))
} |]
$ A = \cfrac{\theta}{\sqrt{2 - 2 \cdot cos(\theta)}} $
[r|
fjay <<- function (theta) {
return ( theta / sqrt(2 - 2*cos (theta)))
} |]
[rgraph|
curve(expr=fjay, from = 0.0, to = 3.14, family = "arial")
|]
[rprint|jaydata <<- read.table ("fromjay02.csv", header=TRUE, sep=",");
|]
Extract function exemplars into two vectors ..
[r|
jay_theta <<- jaydata$Theta
jay_A <<- jaydata$A |]
[r|
f_ec <<- function(A) {
theta = (2*(5*A**8 + 2*A**3 - A**2 -5))/(5*A**7)
return (theta)
}|]
[r| ai_pred <<- unlist(lapply (jay_A,f_ec)) |]
[rgraph|
newFrame <<- data.frame (jay_theta, ai_pred)
ggplotRegression("Actual vs Predicted for Theta", newFrame, jay_theta, ai_pred) |]
${MSE} = 0.62$
I'll try to add some transindental functions ..