Thanks for the reply though I don't think your suggestion worked. I have found a way to get the correct line though it is not convenient. Here is a better example:
x <- 1:100 y <- 1:100 plot(y ~ x, log="x") #The only way I can get the correct line is to drop the log(): abline(lm(y ~ x), untf=T, lwd=2) #or lines(x, predict(lm(y ~ x)), col=2) #Neither of these work abline(lm(y ~ log10(x))) #or abline(lm(y ~ log10(x)), untf=T) What I really would like to do is plot fitted lines and 95% confidence intervals using predict.lm, as in shown in the example, but when the predictor is log transformed and log="x". I can't figure out how to do this without removing the log() from the response part of the formula and this isn't helpful because I'm generally trying to give predict() a fitted object rather than a lm() formula. I still think I'm probably missing something simple but are there any other suggestions? Thanks. Richard Quoting Peter Dalgaard <[EMAIL PROTECTED]>: > Richard Chandler <[EMAIL PROTECTED]> writes: > > > Hello, > > > > I'm trying to plot a fitted lm() line on a plot when the one > > explanatory variable is log transformed and log="x". I get > different > > lines using abline and predict.lm(). > > > > #Example > > x <- 1:100 > > y <- rnorm(100) > > plot(y ~ x, log="x") > > abline(lm(y ~ log(x))) > > lines(x, predict(lm(y ~ log(x))), lwd=2) > > > > I'm sure I'm missing something but could someone tell me which > line is > > correct? Thanks. > > Base 10 is what you're missing. > > The latter form is agnostic with respect to base, the former is > not > (since the fitted values are the same, but regression coefficients > differ). So you need to know to use abline(lm(y ~ log10(x))). > > You don't really notice which kind of log is being used until you > look > at par(usr) for a plot with logged axes. > > -- > 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 > ~~~~~~~~~~ - ([EMAIL PROTECTED]) FAX: (+45) > 35327907 > -- Richard Chandler, M.S. candidate Department of Natural Resources Conservation UMass Amherst (413)545-1237 ----- End forwarded message ----- -- Richard Chandler, M.S. candidate Department of Natural Resources Conservation UMass Amherst (413)545-1237 ______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
