Skip to content
Back to formatted view

Raw Message

Message-ID: <1393103212.42547.YahooMailNeo@web142603.mail.bf1.yahoo.com>
Date: 2014-02-22T21:06:52Z
From: arun
Subject: how to plot a logarithmic regression line

HI,
Try ?curve

fit <- lm(Mean_Percent_of_Range~log(No.ofPoints))
?coef(fit)
?# ?? (Intercept) log(No.ofPoints) 
? # ??? -74.52645???????? 46.14392 



?plot(Mean_Percent_of_Range ~ No.ofPoints) 
curve(coef(fit)[[1]]+coef(fit)[[2]]*log(x),add=TRUE,col=2)


A.K.



I realize this is a stupid question, and I have honestly tried to find 
the answer online, but nothing I have tried has worked. I have two 
vectors of data: 

"Mean_percent_of_range" 
10.90000 ?17.50000 ?21.86667 ?25.00000 ?25.40000 ?26.76667 ?29.53333
 ?32.36667 ?43.13333 ?41.80000 50.56667 ?49.26667 ?50.36667 ?51.93333 
?59.70000 ?63.96667 ?62.53333 ?60.80000 ?64.23333 ?66.00000 74.03333 
?70.40000 ?77.06667 ?76.46667 ?78.13333 ?89.46667 ?88.90000 ?90.03333 
?91.60000 ?94.30000 95.50000 ?96.20000 ?96.50000 ?91.40000 ?98.20000 
?96.60000 ?97.40000 ?99.00000 100.00000 

and 
"No.ofPoints" 
5 ?6 ?7 ?8 ?9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 
39 40 41 42 43 

When I plot these, I get a logarithmic curve (as I should for this type of data) 
> plot(Mean_Percent_of_Range ~ No.ofPoints) 

All that I want to do is plot best fit regression line for that 
curve. From what I have read online, it seems like the code to do that 
should be 
> abline(lm(log(Mean_Percent_of_Range) ~ log(No.ofPoints))) 
but that gives me a straight line that isn't even close to fitting the data 

How do I plot the line and get the equation of that line and a correlation coefficient? 
Thanks