【发布时间】:2019-05-20 10:25:09
【问题描述】:
我整天都在忙。 在 R 方面,我的水平相当低于平均水平,所以我还没有达到编写自己的脚本/函数的水平(但正在尝试......但失败了)
我有年销售额、收入、商品价格、收入中位数和人口的数据。
使用 glm,我消除了一些变量(自相关、无意义等)。
这是我正在使用的数据框的输入:
dput(df)
structure(list(Year = 2008:2018, Sales = c(50681L, 53016L, 53981L,
56204L, 55564L, 56916L, 61328L, 59686L, 59412L, 57298L, 57569L
), Population = c(9250000L, 9380000L, 9570000L, 9660000L, 9760000L,
9850000L, 9940000L, 10040000L, 10160000L, 10270000L, 10454860L
), Income = c(52941L, 53127L, 50020L, 48816L, 47969L, 48294L,
48385L, 48253L, 49489L, 51672L, 51752L), Price_up = c(15, 15.57,
15.50772, 15.75584352, 16.26003051, 16.60149115, 20, 20.32, 20.34032,
20.60474416, 21.03744379), Price = c(16.60149115, 16.26003051,
15.75584352, 15.50772, 15.57, 15, 21.03744379, 20.60474416, 20.34032,
20.32, 20), ad_revenue = c(1293145, 1270159.59, 1297991.2, 1362019.86,
1330311.32, 1423933.04, 1499699.64, 1983487.176, 2034322.84,
2010148.6, 2008107.84)), class = "data.frame", row.names = c(NA,
11L))
#Run Models#
m1 <- glm(formula = Sales ~ Price, data = df)
m2 <- update(m1, . ~ . + Income)
m3 <- update(m2, . ~ . + ad_revenue)
m4 <- update(m3, . ~ . + Population)
library(memisc)
library(car)
#m3 is best#
mtable(m1, m2, m3, m4)
#No autocorrelation#
durbinWatsonTest(m3)
#Calculate Price Elasticity#
PEm3 <- as.numeric(m3$coefficients['Price'] * mean(df$Price)/mean(df$Sales))
那么,我如何确定最优价格?是否可以使用 ggplot 绘制曲线来指示在销售额下降之前可以收取最高价格的位置?
价格弹性值为1>x>-1,表示相对缺乏弹性。
请帮我展示一条钟形曲线,表示销售暴跌前的最高价格点。它看起来像这里的图片:
不同之处在于,y 轴上的收入不是总销售额。
谢谢
【问题讨论】:
-
您的代码似乎需要加载
memisc和car库。 -
是的,我忘记添加了。