ilikemath
R中帮助文件中有一个这样的例子:
Usage
ols(formula, data, weights, subset, na.action=na.delete,
method="qr", model=FALSE,
x=FALSE, y=FALSE, se.fit=FALSE, linear.predictors=TRUE,
penalty=0, penalty.matrix, tol=1e-7, sigma,
var.penalty=c('simple','sandwich'), ...)
# Fit a complex model and approximate it with a simple one
x1 <- runif(200)
x2 <- runif(200)
x3 <- runif(200)
x4 <- runif(200)
y <- x1 + x2 + rnorm(200)
f <- ols(y ~ rcs(x1,4) + x2 + x3 + x4)
请问一下, rcs(x1,4)是什么意思?看过rcs的说明也不懂.
另外,如果对一个更复杂的模型,比如说:
x1,x2,x3,z都是n维列向量
y<-sin(pi*(x1*alpha1+x2*alpha2+x3*alpha3-A)/(B-A))+beta*z+ipsilon
应该怎么写公式呢?试过照上面的写,在nls中没问题,但在ols中就有问题了.
rtist
[quote]引用第0楼ilikemath于2007-08-27 05:08发表的“OLS中的公式”:
x1,x2,x3,z都是n维列向量
y<-sin(pi*(x1*alpha1+x2*alpha2+x3*alpha3-A)/(B-A))+beta*z+ipsilon
.......[/quote]
this model is not linear in parameters, and I believe it should not be fitted with ols.
the spline model you mentioned is not linear in predictors, but still linear in parameters, and is essentially a linear model. So it can be fit with ols.