Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set.seed(1)
- x = runif(100, 0, 5)
- y = ifelse(x<1, 0, ifelse(x<2, 1, ifelse(x<3,0, ifelse(x<4,1,0))))
- plot(x,y, pch=20)
- LM = lm(y~x)
- summary(LM) ## Output simplified
- Residuals:
- Min 1Q Median 3Q Max
- -0.5214 -0.5106 0.4829 0.4921 0.4963
- Residual standard error: 0.5049 on 98 degrees of freedom
- Multiple R-squared: 0.0001441, Adjusted R-squared: -0.01006
- F-statistic: 0.01413 on 1 and 98 DF, p-value: 0.9056
- LM2 = lm(y~poly(x,2))
- summary(LM2) ## Output simplified
- Residuals:
- Min 1Q Median 3Q Max
- -0.7255 -0.3478 0.3062 0.4062 0.5495
- Residual standard error: 0.4659 on 97 degrees of freedom
- Multiple R-squared: 0.1576, Adjusted R-squared: 0.1402
- F-statistic: 9.07 on 2 and 97 DF, p-value: 0.0002448
- library(rpart)
- RP = rpart(y ~ x)
- summary(predict(RP) - y)
- Min. 1st Qu. Median Mean 3rd Qu. Max.
- 0 0 0 0 0 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement