12.01.2013

Fitting Linear Models - Function : LM

r_lm r_lm

Function : LM - Fitting Linear Models

Description :

    lm is used to fit linear models. It can be used to carry out regression, single stratum analysis of variance and analysis of covariance

Usage :

    lm(formula, data, subset, weights, na.action, method = "qr", model = TRUE, x = FALSE, y = FALSE, qr = TRUE, singular.ok = TRUE, contrasts = NULL, offset, ...)
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)
    data <- data.frame(X=x, Y=y)
    result <- lm(y~x,data)
    coefficients(result)
    names(result)
    a <- result$coefficients
    xx <- seq(min(x),max(x),by=0.1)
    yy <- a[1]+a[2]*xx
    plot(xx,yy,xlim=c(min(x),max(x)),ylim=c(min(y),max(y)),type="l",xlab="",ylab="")
    par(new=T)
    plot(x,y,xlim=c(min(x),max(x)),ylim=c(min(y),max(y)))
    
    Fitting Linear Models

See Also ...

r_lm r_lm