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.
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)
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)
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)
Comments
Post a Comment