Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6539191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:49:42+00:00 2026-05-25T10:49:42+00:00

I want to calculate a linear regression using the lm() function in R. Additionally

  • 0

I want to calculate a linear regression using the lm() function in R. Additionally I want to get the slope of a regression, where I explicitly give the intercept to lm().

I found an example on the internet and I tried to read the R-help “?lm” (unfortunately I’m not able to understand it), but I did not succeed. Can anyone tell me where my mistake is?

lin <- data.frame(x = c(0:6), y = c(0.3, 0.1, 0.9, 3.1, 5, 4.9, 6.2))
plot (lin$x, lin$y)

regImp = lm(formula = lin$x ~ lin$y)
abline(regImp, col="blue")

# Does not work:
# Use 1 as intercept
explicitIntercept = rep(1, length(lin$x))
regExp = lm(formula = lin$x ~ lin$y + explicitIntercept)
abline(regExp, col="green")

Thanls for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:49:43+00:00Added an answer on May 25, 2026 at 10:49 am

    You could subtract the explicit intercept from the regressand and then fit the intercept-free model:

    > intercept <- 1.0
    > fit <- lm(I(x - intercept) ~ 0 + y, lin)
    > summary(fit)
    

    The 0 + suppresses the fitting of the intercept by lm.

    edit To plot the fit, use

    > abline(intercept, coef(fit))
    

    P.S. The variables in your model look the wrong way round: it’s usually y ~ x, not x ~ y (i.e. the regressand should go on the left and the regressor(s) on the right).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I want to calculate a hash of a data structure, using a
I want to calculate the difference between two date/time in java using Date and
i want to calculate the NPV ( Net Present Value ) using PHP. Below
I want to calculate the average of a set of circular data. For example,
I want to calculate covariance matrix using Java. Is there any free library to
I want to carry out a linear regression in R for data in a
I want to calculate distance using 2 cellID (i am getting cell id from
I want to calculate the time span between 2 times which I saved in
I want to calculate what is $x percentage of a $total. $x could be
I want to calculate the age of a person given the date of birth

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.