I'm having trouble figuring out how to replicate Stata's command "predict uhat, residuals" in R for creating residuals.
Do I have to generate a normal sampling to accomplish this?
Cross Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. It only takes a minute to sign up.Sign up to join this community
Not entirely sure about the "Do I have to generate a normal sampling to accomplish this?" but here are the parallel examples:
In Stata the
predict command will not work unless you have done some analysis before that. For example, linear regression using
sysuse auto reg price mpg predict uhat, residual
This will give you the residual called uhat.
In R, same idea. You'll need to have an object first. After the
lm() command, a set of residual will be saved in the model output. You'll need to use
$residual to get it. Again here is an example in linear regression:
x <- rnorm(1000) y <- x * 1.5 + rnorm(1000, 0, 250) m01 <- lm(y ~ x) uhat <- m01$residual hist(uhat)