File: LeastSquares.R

package info (click to toggle)
r-cran-sparsem 1.84-2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,648 kB
  • sloc: fortran: 3,998; ansic: 75; makefile: 2
file content (20 lines) | stat: -rw-r--r-- 810 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# lsq.rra is real rectangular matrix stored in compressed sparse column for mat
lsqFile <- system.file("extdata", "lsq.rra", package = "SparseM", mustWork = TRUE)
read.matrix.hb(lsqFile) -> hb.o
X <- model.matrix(hb.o) #extract the design matrix
y <- model.response(hb.o) # extract the rhs
X1 <- as.matrix(X)
slm.time <- system.time(slm(y~X1-1) -> slm.o) # pretty fast
lm.time <- system.time(lm(y~X1-1) -> lm.o) # very slow
cat("slm time =",slm.time,"\n")
cat("lm time =",lm.time,"\n")
sum.slm <- summary(slm.o)
sum.slm$coef <- sum.slm$coef[1:5,]
sum.lm <- summary(lm.o)
sum.lm$coef <- sum.lm$coef[1:5,]
sum.slm
sum.lm
slm.fit.time <- system.time(slm.fit(X,y)) # very fast
lm.fit.time <- system.time(lm.fit(X1,y)) # still very slow
cat("slm.fit time =",slm.fit.time,"\n")
cat("lm.fit time =",lm.fit.time,"\n")