Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. set.seed(1)
  2. x = runif(100, 0, 5)
  3. y = ifelse(x<1, 0, ifelse(x<2, 1, ifelse(x<3,0, ifelse(x<4,1,0))))
  4. plot(x,y, pch=20)
  5.  
  6. LM = lm(y~x)
  7. summary(LM) ## Output simplified
  8.  
  9. Residuals:
  10. Min 1Q Median 3Q Max
  11. -0.5214 -0.5106 0.4829 0.4921 0.4963
  12.  
  13. Residual standard error: 0.5049 on 98 degrees of freedom
  14. Multiple R-squared: 0.0001441, Adjusted R-squared: -0.01006
  15. F-statistic: 0.01413 on 1 and 98 DF, p-value: 0.9056
  16.  
  17. LM2 = lm(y~poly(x,2))
  18. summary(LM2) ## Output simplified
  19.  
  20. Residuals:
  21. Min 1Q Median 3Q Max
  22. -0.7255 -0.3478 0.3062 0.4062 0.5495
  23.  
  24. Residual standard error: 0.4659 on 97 degrees of freedom
  25. Multiple R-squared: 0.1576, Adjusted R-squared: 0.1402
  26. F-statistic: 9.07 on 2 and 97 DF, p-value: 0.0002448
  27.  
  28. library(rpart)
  29. RP = rpart(y ~ x)
  30. summary(predict(RP) - y)
  31. Min. 1st Qu. Median Mean 3rd Qu. Max.
  32. 0 0 0 0 0 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement