Tricks for lm

There are couple of ways where you can perform the same task. Sometimes in this book, I may do it more efficiently and sometimes not. There are mainly two reasons that will prevent me from trying a more efficient way:

  1. I want to display a more step-wise approach so that newcomers won't feel discouraged
  2. I am not that smart

There is always room for improvement. I encourage the reader to look for it every single time. It's okay if you don't succeed or if you find people with more skills than you. Next, you can see the code that I would have pulled if it weren't for reason#1:

# set.seed(5)# n <- sample(dim(dt)[1], size = 40)reg <- lm(infantMortality ~ log(ppgdp), data = dt[-n,])out <- predict(reg, newdata = dt[n,])

Instead of creating ...

Get Hands-On Data Science with R now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.