Skip to content

Instantly share code, notes, and snippets.

@aammd
Last active December 16, 2016 12:22
Show Gist options
  • Save aammd/591e382edc470fca650eb051fd3ecaba to your computer and use it in GitHub Desktop.
Save aammd/591e382edc470fca650eb051fd3ecaba to your computer and use it in GitHub Desktop.
microbenchmark::microbenchmark({lm(ys~xs, data = testdf)$residuals},
{fastLm(ys~xs, data = testdf)$residuals},
{homemade_residuals(indeps, deps)}, times = 500)
identical(homemade_residuals(indeps, deps), homemade_residuals2(indeps, deps))
# all.equal()
testdf <- data_frame(xs = runif(200, 0, 15),
ys = xs * 5 + 15 + rnorm(200, sd = 3))
profvis::profvis({homemade_residuals(testdf)})
@vanderleidebastiani
Copy link

	pro.residuals1.1<-function(Y,X){
		X<-sweep(X,2,colMeans(X,na.rm=TRUE),check.margin = FALSE)
		Y<-sweep(Y,2,colMeans(Y,na.rm=TRUE),check.margin = FALSE)
		Yfit<-X%*%solve(t(X)%*%X)%*%(t(X))%*%Y
		Yres<-Y-Yfit
	return(Yres)
	}

@aammd
Copy link
Author

aammd commented Dec 15, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment