hamilthj hamilthj - 1 year ago 79
R Question

Fitting a regression line to graph with log axes in R

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")
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)

lm(formula = logWet.weight ~ logAverageBL, data = mtrosslog)

             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')

Regression line generated from log transformed data plotted on graph of untransformed data with log-log axes

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download