This is an RMarkdown notebook created with RStudio to test Homework 4 of BIOSTAT625.


Preambles

Install the package and the benchmarking package for efficiency check

install.packages('C:/Users/evely/Desktop/lmcpp.tar.gz',repos=NULL)
install.packages("microbenchmark")

Load the package.

library(lmcpp)
library("microbenchmark")

Check the help files

help(lmcpp)
help(summary.lmcpp)

load test input data1

data(cars)

create a simple linear model and summarize the regression output

fit1 = lmcpp(dist ~ speed, data = cars, prt = TRUE)
summ1 = summary.lmcpp(fit1, correlation = TRUE, prt = TRUE)

load test input data2

data(mtcars)

create a multiple linear model and summarize the regression output

fit2 = lmcpp(mpg ~ cyl + hp, data = mtcars, prt = TRUE)
summ2 = summary.lmcpp(fit2, correlation = TRUE, prt = TRUE)

test of correctness of lmcpp/summary.lmcpp comparing to the original function (lm/summary.lm)

fit.lm1 = lm(dist ~ speed, data = cars)
fit.lm2 = lm(mpg ~ cyl + hp, data = mtcars)
fit.summ1 = summary(fit.lm1, correlation = TRUE)
fit.summ2 = summary(fit.lm2, correlation = TRUE) 
for ( i in c("coefficients","df.residual","fitted.values","residuals") ) {
  print( all.equal(fit1[[i]], fit.lm1[[i]]) )
  print( all.equal(fit2[[i]], fit.lm2[[i]]) )
}
for ( j in c("adj.r.squared", "coefficients", "correlation", "cov.unscaled", "fstatistic", "r.squared", "residuals", "sigma") ) {
  print( all.equal(summ1[[j]],fit.summ1[[j]]))
  print( all.equal(summ2[[j]],fit.summ2[[j]]))
}

test of efficiency of lmcpp/summary.lmcpp comparing to the original function (lm/summary.lm)

microbenchmark(lmcpp(dist ~ speed, data = cars),lm(dist ~ speed, data = cars))
microbenchmark(lmcpp(mpg ~ cyl + hp, data = mtcars),lm(mpg ~ cyl + hp, data = mtcars))


strongbeamsprout/lmcpp documentation built on Nov. 27, 2019, 12:29 a.m.