2
$\begingroup$

I am implementing a linear model in R, where I use "y ~ 0+x" to fit a model without intercept. When I use then "abline(0, 2.08193)" the line does not go through the origin - why is that and how can it be corrected?

x <- c(2.9, 6.7, 8.0, 3.1, 2.0, 4.1, 2.2, 8.9, 8.1, 7.9, 5.7, 1.6, 6.6, 3.0, 6.3)
y <- c(5.118289 17.168719 14.489016  7.340286  8.422882  7.994184  4.455667 17.529257 16.628453 17.076216 14.855261 2.596441 12.039215  6.684931 11.456480)

mod0 <- lm(formula = y ~ 0+x)
plot(x,y, xlab="x ", ylab="y ")

summary(mod0)
abline(0, 2.08193)

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ plot(x,y, xlab="x ", ylab="y ",xlim=c(0,max(x)),ylim=c(0,max(y))) ; abline(mod0) $\endgroup$
    – StupidWolf
    Commented Apr 12, 2020 at 0:43

1 Answer 1

3
$\begingroup$

Here:

x <- c(2.9, 6.7, 8.0, 3.1, 2.0, 4.1, 2.2, 8.9, 8.1, 7.9, 5.7, 1.6, 6.6, 3.0, 6.3)
y <- c(5.118289, 17.168719, 14.489016,  7.340286,  8.422882,  7.994184,  
       4.455667, 17.529257, 16.628453, 17.076216, 14.855261, 2.596441, 
       12.039215,  6.684931, 11.456480)

mod0 <- lm(formula = y ~ 0+x)
plot(x,y, xlab="x ", ylab="y ", xaxs="i", yaxs="i", xlim = c(0,10), ylim = c(0,20), )
abline(mod0)

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.