Samuel Tan
Samuel Tan

Reputation: 1750

`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. Using lm() the syntax would be like:

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. How do I do this when using 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.

Here is a link to a csv file

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!

Upvotes: 3

Views: 1190

Answers (1)

Roland
Roland

Reputation: 132706

rms::ols uses rms:::Design instead of 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. I assume there is a good reason for this, but you can try changing ols using trace.

Upvotes: 2

Related Questions