## Example of Model II linear regression for TFC
# Libraries
library(lmodel2)
library(ggplot2)
# Make some data
set.seed(10)
df <- data.frame(x = runif(n = 20, min = -5, max = 30))
df$y <- (0.5 * df$x + 5) * runif(n = 20)
# Plot data
ggplot(df, aes(x = x, y = y)) + geom_point()

# Linear models
# See http://cran.r-project.org/web/packages/lmodel2/vignettes/mod2user.pdf
# You'll want the MA for the δ–δ plots
# Model I
lm(y~x, data = df)
##
## Call:
## lm(formula = y ~ x, data = df)
##
## Coefficients:
## (Intercept) x
## 3.237 0.259
# Model II
# See how the OLS results are the same as the Model I results from above
# Compare the OLS slope with the MA slope
lmodel2(y~x, data = df)
## RMA was not requested: it will not be computed.
##
## No permutation test will be performed
##
## Model II regression
##
## Call: lmodel2(formula = y ~ x, data = df)
##
## n = 20 r = 0.61 r-square = 0.3722
## Parametric P-values: 2-tailed = 0.004288 1-tailed = 0.002144
## Angle between the two OLS regression lines = 20.32 degrees
##
## Regression results
## Method Intercept Slope Angle (degrees) P-perm (1-tailed)
## 1 OLS 3.237 0.2591 14.52 NA
## 2 MA 2.957 0.2896 16.15 NA
## 3 SMA 1.716 0.4247 23.01 NA
##
## Confidence intervals
## Method 2.5%-Intercept 97.5%-Intercept 2.5%-Slope 97.5%-Slope
## 1 OLS 1.2866 5.187 0.09244 0.4257
## 2 MA 1.1285 4.609 0.10960 0.4887
## 3 SMA -0.1032 2.957 0.28957 0.6228
##
## Eigenvalues: 59.59 5.839
##
## H statistic used for computing C.I. of MA: 0.02953