Reputation: 31
I have run regression in R, when trying to fit an abline
to the plot nothing happens, no error message appears.
I've had to log transform the data so I'm wondering if this is the issue? The data is not normally distributed however we have still been asked to perform regression.
Here is what I've tried so far:
alldata<-read.csv(file.choose(),header=T)
attach(alldata)
plot(weight.g,wingspan.mm,log="xy")
abline(lm(wingspan.mm~weight.g))
fit1<-lm(wingspan.mm~weight.g)
> summary(fit1)
fit2<-lm(log(wingspan.mm)~log(weight.g))
plot(fit2)
plot(weight.g,wingspan.mm,log="xy")
abline(fit2)
abline(lm(log(wingspan.mm)~log(weight.g)))
Can anyone spot where I am going wrong?
Thanks, Kate
Upvotes: 3
Views: 5036
Reputation: 51640
abline
won't plot a regression line over a log-transformed plot.
For instance this will only plot the points and not the regression line
plot(speed~dist, cars, log="xy")
abline(lm(speed~dist, cars))
To get around the problem use the untf
parameter
plot(speed~dist, cars, log="xy")
abline(lm(speed~dist, cars), untf=T)
From ?abline
:
If untf is true, and one or both axes are log-transformed, then a curve is drawn corresponding to a line in original coordinates, otherwise a line is drawn in the transformed coordinate system
Upvotes: 5