Fitting a regression line to graph with log axes in R -


i'm trying make simple body size/weight regression graph log axes can't seem fit straight regression line graph.

i've tried using untf function no line being generated.

here's simplified sample of 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 @ previous questions same problem can't solutions work me.

example of graph generated

plotting original variables in log scale different plotting (the fitted regression line with) log-transformed variables in original scale, should latter desired result (plot fitted regression line log-transformed variables in original scale), examples mtcars dataset:

plot(log(mtcars$mpg)~log(mtcars$wt)) # plot log-transformed variables, not in log-scale   reg=lm(log(mtcars$mpg)~log(mtcars$wt)) abline(reg, untf=f) 

enter image description here

another option plot in log scale fit regression line in original scale.

plot(mtcars$mpg~mtcars$wt, log="xy")  reg=lm(mtcars$mpg~mtcars$wt) abline(reg, untf=t) 

enter image description here

when want combine log-scale plot regression fit log-tranformed, intercept computed ols not in log-scale, guess need log transformation it, produces belowe plot, correct slope of line wrong offset.

plot(mtcars$mpg~mtcars$wt, log="xy")  reg=lm(log(mtcars$mpg)~log(mtcars$wt)) abline(log(reg$coefficients[1]), reg$coefficients[2], untf=f) 

enter image description here


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -