Question

Guided by the answer to this post:

Linear Regression with a known fixed intercept in R

I have fit an explicit intercept value to some data, but also an explicit slope, thus:

intercept <- 0.22483 
fit <- lm(I(Response1 - intercept) ~ 0 + offset(-0.07115*Continuous))

Where Response1 is my dependent variable and Continuous is my explanatory variable, both from this dataset.

I want to plot an abline for my relationship. When only the intercept has been specified the post above recommends:

abline(intercept, coef(fit))

However I have no coefficients in the model "fit" as I specified them all. Is there a way to plot the abline for the relationship I specified?

Was it helpful?

Solution

Simple solution that I overlooked. I know the slope and the intercept so I can just pass them to abline directly:

abline(0.22483, -0.07115)

OTHER TIPS

Based on your comment, you can do this programmatically, without having to manually put in values. Here's an example with sample data from two similar dataframes:

df1 <- data.frame(Response1=rnorm(100,0,1), Continuous=rnorm(100,0,1))
df2 <- data.frame(Response1=rnorm(100,0,1), Continuous=rnorm(100,0,1))
fit1 <- with(df1, lm(Response1 ~ Continuous))
with(df2, plot(Response1 ~ Continuous)) # plot df2 data
abline(coef(fit1)) # plot df1 model over it
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top