7.12.2011

Find the Least Squares Fit - Function : LSFIT

r_lsfit r_lsfit

r_lsfit r_lsfit

Function : LSFIT - Find the Least Squares Fit
    Description :
      The least squares estimate of b in the model y = X b + e is found.
    Usage :
      lsfit(x, y, wt = NULL, intercept = TRUE, tolerance = 1e-07, yname = NULL)
    Arguments :
      x : a matrix whose rows correspond to cases and whose columns correspond to variables.
      y : the responses, possibly a matrix if you want to fit multiple left hand sides.
      wt : an optional vector of weights for performing weighted least squares.
Example:
    x <- c(70, 72, 62, 64, 71, 76, 60, 65, 74, 72)
    y <- c(70, 74, 65, 68, 72, 74, 61, 66, 76, 75)
    z <- lsfit(x, y)
    print(z)
    plot(x,y-z$residual,xlim=c(min(x),max(x)),ylim=c(min(y),max(y)),type="l")
    par(new=T)
    plot(x,y,xlim=c(min(x),max(x)),ylim=c(min(y),max(y)))
    
    Fit Coefficients of a Polynomial

r_lsfit r_lsfit

r_lsfit r_lsfit