R : Copyright 2001, The R Development Core Team Version 1.3.1 (2001-08-31) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type `license()' or `licence()' for distribution details. R is a collaborative project with many contributors. Type `contributors()' for more information. Type `demo()' for some demos, `help()' for on-line help, or `help.start()' for a HTML browser interface to help. Type `q()' to quit R. > data <- read.table("data.dat",header=F) > attach(data) > Y <- as.matrix(data[,1]) > X <- as.matrix(cbind(1, data[,2:ncol(data)])) > XTX <- t(X) %*% X > XTXINV <- solve(XTX) > XTY <- t(X) %*% Y > betahat <- XTXINV %*% XTY > Xbetahat <- X %*% betahat > sigsq <- as.vector(t(Y - Xbetahat) %*% (Y - Xbetahat) / (nrow(X) - ncol(X))) > VCOV <- sigsq * XTXINV > J <- 2 > R <- matrix(0:0, J, ncol(X)) > r <- matrix(0:0,J,1) > R[1,2] <- 1 > R[2,3] <- 1 > Rbetahat <- R %*% betahat > F <- t(Rbetahat - r) %*% solve(R %*% XTXINV %*% t(R)) %*% (Rbetahat - r) / (J * sigsq) > F [,1] [1,] 23.74727 > # Compare with the lm() command (linear regression model) > fitlm <- lm(Y ~ X[,2:ncol(X)]) > fitreslm <- lm(Y ~ X[,4:ncol(X)]) > anova(fitlm, fitreslm) Analysis of Variance Table Model 1: Y ~ X[, 2:ncol(X)] Model 2: Y ~ X[, 4:ncol(X)] Res.Df RSS Df Sum of Sq F Pr(>F) 1 96 99.845 2 98 149.241 -2 -49.397 23.747 4.178e-09 *** --- Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1 >