polynomials

Export fitted regression splines (constructed by 'bs' or 'ns') as piecewise polynomials

余生长醉 提交于 2019-11-26 21:27:56
问题 Take for instance the following one-knot, degree two, spline: library(splines) library(ISLR) fit.spline <- lm(wage~bs(age, knots=c(42), degree=2), data=Wage) summary(fit.spline) I see estimates that I don't expect. Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 57.349 3.950 14.518 < 2e-16 *** bs(age, knots = c(42), degree = 2)1 59.511 5.786 10.285 < 2e-16 *** bs(age, knots = c(42), degree = 2)2 65.722 4.076 16.122 < 2e-16 *** bs(age, knots = c(42), degree = 2)3 37.170 9.722 3

In R formulas, why do I have to use the I() function on power terms, like y ~ I(x^3)

若如初见. 提交于 2019-11-26 15:24:10
问题 I'm trying to get my head around the use of the tilde operator, and associated functions. My 1st question is why does I() need to be used to specify arithmetic operators? For example, these 2 plots generate different results (the former having a straight line, and the latter the expected curve) x <- c(1:100) y <- seq(0.1,10,0.1) plot(y~x^3) plot(y~I(x^3)) further, both of the following plots also generate the expected result plot(x^3, y) plot(I(x^3), y) My second question is, perhaps the