1

我想使用一个数据集对花费在点击链接上的资金进行回归,我注意到在花费一定数量的资金后链接点击趋于平稳。我想使用对数转换来更好地拟合这个平衡数据。

我的数据集如下所示:

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

MoneySpent
[1]  10.97  21.81  20.64  21.42  48.03 127.30

我想预测link.clicks1 美元增加的百分比变化MoneySpent。我的回归模型是:

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

但是,该图visreg生成如下所示:[1]:https ://i.stack.imgur.com/eZqVG.png

当我将回归更改为:

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

我实际上得到了我正在寻找的拟合线:[2]:https ://i.stack.imgur.com/MexwC.png

我很困惑,因为我不想link.clicks从 % 变化中预测 % 变化MoneySpent

我试图link.clicks从 $ 单位变化中预测 % 变化MoneySpent

为什么我不能使用我的第一个回归生成第二张图regClicksLogLevel

4

1 回答 1

0

我想这就是你要找的

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)

输出

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

这是图表

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)

在此处输入图像描述

于 2021-10-09T18:28:30.503 回答