Skip to content

Add an intercept to the lm method - #25

Open
rcannood wants to merge 1 commit into
mainfrom
fix/lm-missing-intercept
Open

Add an intercept to the lm method#25
rcannood wants to merge 1 commit into
mainfrom
fix/lm-missing-intercept

Conversation

@rcannood

Copy link
Copy Markdown
Member

Describe your changes

RcppArmadillo::fastLm(X, y) takes X as the design matrix verbatim -- unlike the formula interface, it does not add an intercept -- and predict.fastLm() then computes newdata %*% coef(object). Since lmds returns mean-centred coordinates, the model was effectively forced through the origin and could never fit the mean expression level of a gene.

Quick illustration, y = 5 + 2*x1 + noise on centred predictors:

> f  <- RcppArmadillo::fastLm(X, y)             # X has an intercept column
> head(predict(f, X), 3)
3.408 5.001 3.009
> f2 <- RcppArmadillo::fastLm(X[,-1], y)        # no intercept
> head(predict(f2, X[,-1]), 3)
-1.602 -0.009 -2.001    # truth: 3.606 4.982 3.017

This inflates the method's rmse and mae and depresses its per-cell correlations. Per-gene Pearson/Spearman are location-invariant, so those numbers were fine.

Adding the intercept column once, outside the per-gene loop, rather than in the pblapply() body.

Part of a series of PRs coming out of a pre-run review of the benchmark.

Checklist before requesting a review

  • I have performed a self-review of my code

  • Check the correct box. Does this PR contain:

    • Breaking changes
    • New functionality
    • Major changes
    • Minor changes
    • Bug fixes
  • Proposed changes are described in the CHANGELOG.md

  • CI Tests succeed and look good!

RcppArmadillo::fastLm(X, y) takes X as the design matrix verbatim and
predict.fastLm() computes newdata %*% coef, so without an intercept
column the fit is forced through the origin. lmds coordinates are
mean-centred, so the model could never reach the mean expression level.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant