SHARE
TWEET

Regresión

fabimatho Sep 9th, 2019 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. n = 100;
  2. x1 =  1:n;
  3. x2 = round(runif(n,0,1),2);
  4. x3 = round(rnorm(n),2);
  5. x4 = round(runif(n,10,20),2);
  6. x5 = 0.2*x1+0.7*x2+0.1*x4;
  7. er = round(rnorm(n,0,2),2);
  8.  
  9. y = 10+0.8*x1 -12*x2 + 6 *x3 + er;
  10.  
  11. par(mfrow=c(1,3));
  12. plot(x1,y);
  13. plot(x2,y);
  14. plot(x3,y);
  15.  
  16. X=cbind(1,x1,x2,x3);
  17. bet=round(solve(t(X) %*% X) %*% t(X) %*% y,2);
  18. ya=X%*%bet;
  19. ee=y-ya;
  20. s2 = t(ee)%*% ee/(n-3-1);
  21.  
  22. dat=cbind(y,x1,x2,x3);
  23. cor(dat);
  24.  
  25. reg1 = lm(y~x1 + x2 +x3 + x4 + x5);
  26. summary(reg1);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top