Learn R Programming

HelpersMG (version 6.2)

RectangleRegression: Return parameters of rectangle regression

Description

Fit a line using least rectangle method.

Usage

RectangleRegression(
  x1,
  x2,
  replicate = 1000,
  x1new = seq(from = min(x1), to = max(x1), length.out = 100)
)

Value

A list with parameters of rectangle regression

Arguments

x1

The first series of data

x2

The second series of data

replicate

Number of replicates for bootstrap

x1new

Values for x1 to generate x2

Author

Marc Girondot marc.girondot@gmail.com

Details

RectangleRegression performs rectangle regression

Examples

Run this code
x1 <- runif(100, min=10, max=20)
x2 <- runif(100, min=10, max=20)+x1

rectreg <- RectangleRegression(x1, x2)

plot(x=x1, y=x2, bty="n", las=1, xlim=c(10, 20), ylim=c(20, 40))
abline(a=rectreg$par["Intercept"], b=rectreg$par["Slope"], lwd=2)
par(xpd=FALSE)
lines(rectreg$x2new["x1new", ], rectreg$x2new["50%", ])
lines(rectreg$x2new["x1new", ], rectreg$x2new["2.5%", ], lty=2)
lines(rectreg$x2new["x1new", ], rectreg$x2new["97.5%", ], lty=2)

abline(a=rectreg$Intercept[1], b=rectreg$Slope[3], col="red")
abline(a=rectreg$Intercept[3], b=rectreg$Slope[1], col="red")

Run the code above in your browser using DataLab