Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. fo <- mpg ~ hp
  2. X <- model.matrix(fo, mtcars)
  3.  
  4. microbenchmark::microbenchmark(flm=lm <-
  5. lm(fo, mtcars[mtcars$am == 1, ],
  6. weights=rep(1, 13)),
  7. flmw=lmw <-
  8. lm.wfit(X[mtcars$am == 1, ], mtcars$mpg[mtcars$am == 1],
  9. w=rep(1, 13)))
  10. # Unit: microseconds
  11. # expr min lq mean median uq max neval cld
  12. # flm 935.328 951.2735 994.7719 957.2695 1006.128 1333.339 100 b
  13. # flmw 56.895 60.3400 66.2028 64.2940 66.463 186.250 100 a
  14. stopifnot(lm$coefficients == lmw$coefficients)
  15.  
  16. predict(lm, mtcars)
  17. # [...]
  18. predict(lmw, mtcars)
  19. # Error in UseMethod("predict") :
  20. # no applicable method for 'predict' applied to an object of class "list"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement