[英]`rms::ols()`: how to fit a model without intercept
I'd like to use the ols()
(ordinary least squares) function from the rms
package to do a multivariate linear regression, but I would not like it to calculate the intercept. 我想使用
rms
包中的ols()
(普通最小二乘)函数进行多元线性回归,但我不希望它计算截距。 Using lm()
the syntax would be like: 使用
lm()
语法如下:
model <- lm(formula = z ~ 0 + x + y, data = myData)
where the 0
stops it from calculating an intercept, and only two coefficients are returned, on for x
and the other for y
. 其中
0
阻止它计算截距,并且仅返回两个系数,对于x
而另一个为y
。 How do I do this when using ols()
? 使用
ols()
时该怎么做? Trying 试
model <- ols(formula = z ~ 0 + x + y, data = myData)
did not work, it still returns an intercept and a coefficient each for x
and y
. 没有工作,它仍然为
x
和y
返回一个截距和一个系数。
Here is a link to a csv file 这是一个csv文件的链接
It has five columns. 它有五列。 For this example, can only use the first three columns:
对于此示例,只能使用前三列:
model <- ols(formula = CorrEn ~ intEn_anti_ncp + intEn_par_ncp, data = ccd)
Thanks! 谢谢!
rms::ols
uses rms:::Design
instead of model.frame.default
. rms::ols
使用rms:::Design
而不是model.frame.default
。 Design
is called with the default of intercept = 1
, so there is no (obvious) way to specify that there is no intercept. 使用默认的
intercept = 1
调用Design
,因此没有(明显的)方法来指定没有拦截。 I assume there is a good reason for this, but you can try changing ols
using trace
. 我认为有一个很好的理由,但您可以尝试使用
trace
更改ols
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.