plotting log regression

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

plotting log regression

mrkooper
I want to plot the regression line of a log regression into a plot with my normal, nonlog, data.

for example

x <- (1,2,3,4,5)
y <- (6,7,8,9,10)

plot (x,y)

I tried a log-regression by

a <- glm (log(y) ~ log(x))

and then i tried to insert the answer to my graph, where the standard values are shown:
abline (a, col="red")

unfortunately it does not work....
Reply | Threaded
Open this post in threaded view
|

Re: plotting log regression

Rui Barradas
Hello,

How can you expect to see the fit line if you are ploting x and y
values, not their logarithms?
And your definitions of x and y are wrong, they should use c().

x <- c(1,2,3,4,5)
y <- c(6,7,8,9,10)

plot(log(x), log(y))

fit <- lm(log(y) ~ log(x))  # Same as glm
abline(fit)


Please read R-intro, in the doc folder of your installation of R.

Hope this helps,

Rui Barradas
Em 14-12-2012 13:58, mrkooper escreveu:

> I want to plot the regression line of a log regression into a plot with my
> normal, nonlog, data.
>
> for example
>
> x <- (1,2,3,4,5)
> y <- (6,7,8,9,10)
>
> plot (x,y)
>
> I tried a log-regression by
>
> a <- glm (log(y) ~ log(x))
>
> and then i tried to insert the answer to my graph, where the standard values
> are shown:
> abline (a, col="red")
>
> unfortunately it does not work....
>
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/plotting-log-regression-tp4653087.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: plotting log regression

mrkooper
Thank you for your help!

i'm still wondering if it's possible to transfer the results of the log regression into a plot with the nonlog values.  

Reply | Threaded
Open this post in threaded view
|

Re: plotting log regression

Andrews, Chris
In reply to this post by Rui Barradas
Your example seems strange because a line fits on the x-y scale; not on the log(x)-log(y) scale.  Anyway, here is my example.  You can build on it for more general data.

x <- exp(1:10)
y <- exp(10:1 + rnorm(10))


logmod <- lm(log(y)~log(x))
logypred <- predict(logmod)


plot(y~x)
lines(exp(logypred)~x, col=2)


plot(y~x, log="xy")
lines(exp(logypred)~x, col=2)

Chris


-----Original Message-----
From: Rui Barradas [mailto:[hidden email]]
Sent: Friday, December 14, 2012 12:06 PM
To: mrkooper
Cc: [hidden email]
Subject: Re: [R] plotting log regression

Hello,

How can you expect to see the fit line if you are ploting x and y values, not their logarithms?
And your definitions of x and y are wrong, they should use c().

x <- c(1,2,3,4,5)
y <- c(6,7,8,9,10)

plot(log(x), log(y))

fit <- lm(log(y) ~ log(x))  # Same as glm
abline(fit)


Please read R-intro, in the doc folder of your installation of R.

Hope this helps,

Rui Barradas
Em 14-12-2012 13:58, mrkooper escreveu:

> I want to plot the regression line of a log regression into a plot
> with my normal, nonlog, data.
>
> for example
>
> x <- (1,2,3,4,5)
> y <- (6,7,8,9,10)
>
> plot (x,y)
>
> I tried a log-regression by
>
> a <- glm (log(y) ~ log(x))
>
> and then i tried to insert the answer to my graph, where the standard
> values are shown:
> abline (a, col="red")
>
> unfortunately it does not work....
>
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/plotting-log-regression-tp4653087.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


**********************************************************
Electronic Mail is not secure, may not be read every day, and should not be used for urgent or sensitive issues

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.