I have a power law plot in log-log scale using plot(x,y,log="xy") but I can't get the regression line to plot correctly. abline(lm(log(y)~log(x))) plots a straight line that looks promising but the intercept with the y-axis seems to be way off. summary(lm(log(y)~log(x))) gives the values but i cant really make any sense out of it. fitted(..) just confirms the values that seem to be incorrect. any help is appreciated. thanks! martin
abline in log-log power law plot
3 messages · martin klein, Hadley Wickham, Peter Dalgaard
On Fri, Feb 22, 2008 at 2:38 PM, martin klein <mklein at cs.odu.edu> wrote:
I have a power law plot in log-log scale using plot(x,y,log="xy") but I can't get the regression line to plot correctly. abline(lm(log(y)~log(x))) plots a straight line that looks promising but the intercept with the y-axis seems to be way off. summary(lm(log(y)~log(x))) gives the values but i cant really make any sense out of it. fitted(..) just confirms the values that seem to be incorrect. any help is appreciated. thanks!
You might try using ggplot2 instead:
install.packages("ggplot2")
library(ggplot2)
qplot(x, y, log="xy") + geom_smooth(method = lm)
Hadley
hadley wickham wrote:
On Fri, Feb 22, 2008 at 2:38 PM, martin klein <mklein at cs.odu.edu> wrote:
I have a power law plot in log-log scale using plot(x,y,log="xy") but I
can't get the regression line to plot correctly.
abline(lm(log(y)~log(x))) plots a straight line that looks promising but
the intercept with the y-axis seems to be way off.
summary(lm(log(y)~log(x))) gives the values but i cant really make any
sense out of it.
fitted(..) just confirms the values that seem to be incorrect.
any help is appreciated.
thanks!
You might try using ggplot2 instead:
install.packages("ggplot2")
library(ggplot2)
qplot(x, y, log="xy") + geom_smooth(method = lm)
Hadley
Or just switch to base-10 logarithms: abline(lm(log10(y)~log10(x)))
O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907