1

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?

4

2 回答 2

4

我忽略的简单解决方案。我知道斜率和截距,所以我可以直接将它们传递给 abline:

abline(0.22483, -0.07115)
于 2013-07-01T16:05:29.760 回答
0

根据您的评论,您可以以编程方式执行此操作,而无需手动输入值。这是来自两个相似数据帧的示例数据的示例:

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
于 2013-07-01T17:33:20.003 回答