私のデータ(パッケージ 'ecm')の時系列エラー修正モデルを推定しています。以下のコードでは、xeqとxtrを使って短期変数と長期変数を指定しています。回帰回帰推定(ECMモデル)の場合
これらの変数は独立変数であり、従属変数の推定値です。
この場合、プールされたモデルですが、このモデル単位を単位(各ブランドごとに別々に)で見積もりたいと思います。私のデータセットはむしろ大きく、それぞれ3つのブランド(ブランド2、ブランド3、ブランド4)を持つ360の製品カテゴリーで構成されています。
xeq <- DatasetThesisSynergyClean[c('lnPrice', 'lnAdvertising', 'lnDisplay', 'IntrayearCycles', 'lnCompetitorPrices', 'lnCompADV', 'lnCompDISP' , 'ADVxDISP', 'ADVxCYC', 'DISPxCYC', 'ADVxDISPxCYC')]
xtr <- DatasetThesisSynergyClean[c('lnPrice', 'lnAdvertising', 'lnDisplay', 'IntrayearCycles', 'lnCompetitorPrices', 'lnCompADV', 'lnCompDISP', 'ADVxDISP', 'ADVxCYC', 'DISPxCYC', 'ADVxDISPxCYC')]
model11 <- ecm(DatasetThesisSynergyClean$lnSales, xeq, xtr, includeIntercept=TRUE)
summary(model11)
私が望むのは、すべてのカテゴリのすべてのブランドの出力を生成することです。私のデータを垣間見るあなたを与えるために、このコードを実行してください:あなたが見ることができるように
structure(list(Week = 7:17, Category = c("2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2"), Brand = c("3", "3", "3",
"3", "3", "3", "3", "3", "3", "3", "3"), Display = c(0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0), Sales = c(0, 0, 0, 0, 13.440948, 40.097397,
32.01384, 382.169189, 2830.748779, 4524.460938, 1053.590576),
Price = c(0, 0, 0, 0, 5.949999, 5.95, 5.950003, 4.87759,
3.787015, 3.205987, 4.898724), Distribution = c(0, 0, 0,
0, 1.394019, 1.386989, 1.621416, 8.209759, 8.552915, 9.692097,
9.445554), Advertising = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0), lnSales = c(11.4945151554497, 11.633214247508, 11.5862944141137,
11.5412559646132, 11.4811122484454, 11.4775106999991, 11.6333660772506,
11.4859819773102, 11.5232680456161, 11.5572670584292, 11.5303686934256
), IntrayearCycles = c(4.15446534315765, 3.62757053512638,
2.92387946552647, 2.14946414386239, 1.40455011205262, 0.768856938870769,
0.291497141953598, -0.0131078404184544, -0.162984144025091,
-0.200882782749248, -0.182877633924882), `Competitor Advertising` = c(10584.87063,
224846.3243, 90657.72553, 0, 0, 0, 2396.54212, 0, 0, 0, 40343.49444
), `Competitor Display` = c(0.385629, 2.108133, 2.515806,
4.918288, 3.81749, 3.035847, 2.463194, 3.242594, 1.850399,
1.751096, 1.337943), `Competitor Prices` = c(5.30989, 5.372752,
5.3717245, 5.3295525, 5.298393, 5.319466, 5.1958415, 5.2941095,
5.296757, 5.294059, 5.273578), ZeroSales = c(1, 1, 1, 1,
0, 0, 0, 0, 0, 0, 0)), .Names = c("Week", "Category", "Brand",
"Display", "Sales", "Price", "Distribution", "Advertising", "lnSales",
"IntrayearCycles", "Competitor Advertising", "Competitor Display",
"Competitor Prices", "ZeroSales"), row.names = 1255:1265, class = "data.frame")
、私は列に格納されているすべてのカテゴリやブランドを持っています。すべての単一のブランドについての見積もりを得るには、forループを作成したいが、この出力を別々に保存するには、正しいカテゴリとブランドを指定する方法がわからない。
最終的に係数を保存したい、std。エラー、t値およびp値を4つの別々のデータフレームのすべてのブランドに適用します。しかし、まず出力を得る必要があります。皆さんが私を助けてくれますか?
あります'dplyr'、' 'purr''パッケージを使って各ブランドのモデルを構築する別の方法です。線形回帰モデルと関係がある多くの記事がオンラインにあります。あなたはあなたのケースにそれを調整することができるはずです。いくつかの情報はhttps://www.r-bloggers.com/running-a-model-on-separate-groups/こちらをご覧ください。https://stackoverflow.com/questions/38621556/advice-on-usage-of- dplyr-do-vs-purrr-map-tidynest-for-predictions – AntoniosK