Created
March 7, 2013 20:01
-
-
Save IronistM/5111280 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#TV now coincides with winter. Carry over is dec, theta is dim, beta is ad_p, | |
tv_grps<-rep(0,5*52) | |
tv_grps[40:45]<-c(390,250,100,80,120,60) | |
tv_grps[92:97]<-c(390,250,100,80,120,60) | |
tv_grps[144:149]<-c(390,250,100,80,120,60) | |
tv_grps[196:201]<-c(390,250,100,80,120,60) | |
tv_grps[248:253]<-c(390,250,100,80,120,60) | |
if (adstock_form==2){adstock<-adstock_calc_2(tv_grps, dec, dim)} | |
else {adstock<-adstock_calc_1(tv_grps, dec, dim)} | |
TV<-ad_p*adstock | |
# Accompanying radio campaigns | |
radio_spend<-rep(0,5*52) | |
radio_spend[40:44]<-c(100, 100, 80, 80) | |
radio_spend[92:95]<-c(100, 100, 80, 80) | |
radio_spend[144:147]<-c(100, 100, 80) | |
radio_spend[196:200]<-c(100, 100, 80, 80) | |
radio_spend[248:253]<-c(100, 100, 80, 80, 80) | |
radio<-radio_p*radio_spend | |
> cor(test[,c(2,4:6)]) | |
# temp radio_spend week adstock | |
#temp 1.0000000 -0.41545174 -0.15593463 -0.47491671 | |
#radio_spend -0.4154517 1.00000000 0.09096521 0.90415219 | |
#week -0.1559346 0.09096521 1.00000000 0.08048096 | |
#adstock -0.4749167 0.90415219 0.08048096 1.00000000 | |
coefs<-NA | |
for (i in 1:10000){ | |
sim<-create_test_sets(base_p=1000, | |
trend_p=0.8, | |
season_p=4, | |
ad_p=30, | |
dim=100, | |
dec=0.3, | |
adstock_form=1, | |
radio_p=0.1, | |
error_std=5) | |
lm_std<-lm(sales~week+temp+adstock+radio_spend, data=sim) | |
coefs<-rbind(coefs,coef(lm_std)) | |
} | |
col_means<-colMeans(coefs[-1,]) | |
for_div<-matrix(rep(col_means,10000), nrow=10000, byrow=TRUE) | |
mean_div<-coefs[-1,]/for_div | |
m_coefs<-melt(mean_div) | |
ggplot(data=m_coefs, aes(x=value))+geom_density()+facet_wrap(~X2, scales="free_y") + scale_x_continuous('Scaled as % of Mean') | |
library(MASS) | |
for (i in 1:1000){ | |
sim<-create_test_sets(base_p=1000, | |
trend_p=0.8, | |
season_p=4, | |
ad_p=30, | |
dim=100, | |
dec=0.3, | |
adstock_form=1, | |
radio_p=0.1, | |
error_std=5) | |
lm_rg<-lm.ridge(sales~week+temp+adstock+radio_spend, data=sim, lambda = seq(0,20,0.5)) | |
if (i==1){coefs_rg<-coef(lm_rg)} | |
else {coefs_rg<-rbind(coefs_rg,coef(lm_rg))} | |
} | |
colnames(coefs_rg)[1]<-"intercept" | |
m_coefs_rg<-melt(coefs_rg) | |
names(m_coefs_rg)<-c("lambda", "variable", "value") | |
ggplot(data=m_coefs_rg, aes(x=value, y=lambda))+geom_density2d()+facet_wrap(~variable, scales="free") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment