hamilthj - 11 months ago 61

R Question

I'm trying to make a simple body size/weight regression graph with log axes but I can't seem to fit a straight regression line to the graph.

I've tried using the untf function but no line is being generated.

Here's a simplified sample of what I'm trying:

`plot(Average.BL~Wet.weight, log="xy")`

reg=lm(log(Average.BL)~log(Wet.weight))

abline(reg, untf=FALSE)

I've looked at previous questions about the same problem but can't get any solutions to work for me.

Example of graph generated

Answer Source

I have found that if I generate a linear regression of the log transformed data as follows:

```
plot(logWet.weight~logAverageBL, data=mtrosslog)
reg<-lm(logWet.weight~logAverageBL, data=mtrosslog)
Call:
lm(formula = logWet.weight ~ logAverageBL, data = mtrosslog)
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -3.73798 0.11997 -31.16 <2e-16 ***
logAverageBL 2.86705 0.09002 31.85 <2e-16 ***
```

And then generating a plot with log-log axes, I can fit the regression generated from the log transformed data (reg) to this plot of untransformed data:

```
plot(Wet.weight~Average.BL, data = mtross, log = 'xy')
ablineclip(reg)
```