Description Usage Arguments Details Value Note Author(s) References See Also
View source: R/least.squares.R
This is a simple demonstration of the meaning of least squares in univariate linear regression.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18  least.squares(
x,
y,
n = 15,
ani.type = c("slope", "intercept"),
a,
b,
a.range,
b.range,
ab.col = c("gray", "black"),
est.pch = 19,
v.col = "red",
v.lty = 2,
rss.pch = 19,
rss.type = "o",
mfrow = c(1, 2),
...
)

x 
a numeric vector: the independent variable 
y 
a numeric vector: the dependent variable 
n 
the sample size: when x and y are missing, we use simulated values
of y ( 
ani.type 

a, b 
the fixed intercept and slope; depending on 
a.range, b.range 
a vector of length 2 to define the range of the intercept and the slope; only one of them need to be specified; see above 
ab.col 
the colors of two lines: the real regression line and the moving line with either intercept or slope changing 
est.pch 
the point character of the 'estimated' values given 
v.col, v.lty 
the color and line type of the vetical lines which demonstrate the residuals 
rss.pch, rss.type 
the point character and plot type of the residual plot 
mfrow 
defines the layout of the graph; see 
... 
other parameters passed to 
With either the intercept or the slope changing, the lines will be moving in the graph and corresponding residuals will be plotted. We can finally see the best estimate of the intercept and the slope from the residual plot.
The value returned depends on the animation type.
If it is a slope animation, the value will be a list containing
lmfit 
the estimates of the intercept and slope with

anifit 
the estimate of the slope in the animation 
If it is an intercept animation, the second component of the above list will be the estimate of the intercept.
Note the estimate will not be precise generally.
ani.options('nmax')
specifies the maximum number of steps for
the slope or intercept to move.
Yihui Xie
Examples at https://yihui.org/animation/example/leastsquares/
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.