Visreg Plotting log-log as log-level

65 views Asked by At

I want to run a regression of money spent on links clicked using a data set where I notice link clicks level off after a certain amount of money spent. I want to use a log transformation to better fit this leveling-off data.

My data set looks like this:

link.clicks
[1]  34  60  54  49  63 100

MoneySpent
[1]  10.97  21.81  20.64  21.42  48.03 127.30

I want to predict the % change in link.clicks from a $1 increase in MoneySpent. My regression model is:

regClicksLogLevel <- lm(log(link.clicks) ~ (MoneySpent), data = TwtrData)
summary(regClicksLogLevel)
visreg(regClicksLogLevel)

However, The graph visreg generates looks like this: [1]: https://i.stack.imgur.com/eZqVG.png

When I change my regression to:

regClicksLogLog <- lm(log(link.clicks) ~ log(MoneySpent), data = TwtrData)
summary(regClicksLogLog)
visreg(regClicksLogLog)

I actually get the fitted line I'm looking for: [2]: https://i.stack.imgur.com/MexwC.png

I'm confused because I'm not trying to predict a % change in link.clicks from a % change in MoneySpent.

I'm trying to predict a % change in link.clicks from a $ unit change in MoneySpent.

Why can't I generate the 2nd graph using the my first regression, regClicksLogLevel?

1

There are 1 answers

0
Marek Fiołka On

I guess that's what you are looking for

library(tidyverse)

TwtrData = tibble(
  link.clicks = c(34,60,54,49,63,100),
  MoneySpent = c(10.97,21.81,20.64,21.42,48.03,127.30)
) %>% mutate(
  perc.link.clicks = lag(link.clicks, default = 0)/link.clicks,
  perc.MoneySpent = lag(MoneySpent, default = 0)/MoneySpent
)

regClicksLogLevel <- lm(perc.link.clicks ~ perc.MoneySpent, data = TwtrData)
summary(regClicksLogLevel)

output

Call:
lm(formula = perc.link.clicks ~ perc.MoneySpent, data = TwtrData)

Residuals:
         1          2          3          4          5          6 
-0.1422261 -0.0766939 -0.0839233 -0.0002346  0.1912170  0.1118608 

Coefficients:
                Estimate Std. Error t value Pr(>|t|)   
(Intercept)       0.1422     0.1082   1.315  0.25890   
perc.MoneySpent   0.9963     0.1631   6.109  0.00363 **
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.1434 on 4 degrees of freedom
Multiple R-squared:  0.9032,    Adjusted R-squared:  0.879 
F-statistic: 37.32 on 1 and 4 DF,  p-value: 0.003635

And here is the graph

TwtrData %>% ggplot(aes(perc.MoneySpent, perc.link.clicks))+
  geom_line()+
  geom_smooth(method='lm',formula= y~x)+
  scale_y_continuous(labels = scales::percent)+
  scale_x_continuous(labels = scales::percent)

enter image description here