前提
重回帰分析をやるにあたって、モデルの推定を行いたいです。
被説明変数に対数を取った映画の興行収入(単位は週です)、説明変数にTwitterデータ(いいね数、リツイート数、ツイート数)、Twitterアカウントが1作品のみについて紹介しているものか、それとも複数なのかダミー、映画のジャンルダミーなどなどです。以下の写真(csvファイル)がそれらをまとめたパネルデータとなっています。
これにて3つのモデル(poolingモデル、固定効果モデル、変量効果モデル)の内どれが幸せな結果か得られるかを知るためにF検定をしました。
Windows11
統計解析R
実現したいこと
F検定するにあたって、Rにて「model = pooling」「model = within」「model = random」で指定しました。
しかし変量効果モデルである「model = random」でエラーが出ました。このエラーの解決方法が分かりません。
発生している問題・エラーメッセージ
Error in swar_Between_check(estm[[2L]], method) : model not estimable: 67 coefficient(s) (incl. intercept) to be estimated but only 25 individual(s) in data for the between model necessary for Swamy-Arora random-effect model estimation
model = "random", random.method = "walhus", random.dfcor = 3
このようにmodel 以外にも指定してあげるとエラーは消え実行できますが、random.methodとrandom.dfcorは何を指定すればいいか分かりません。
こちらはエラーを解決しようと検索したところ以下のURLを見つけたのでそちらから参照したものです。
参照URL
https://cran.r-project.org/web/packages/plm/vignettes/B_plmFunction.html
気づいたこと(追記)
エラーに対しての解決法を調べると英語文ばかりなので正確かは分かりませんが、もしかしたらモデルrandomを使用する場合は、重複している値があってはいけないような気がしました。しかしダミー変数などを入れる場合は0と1なので必ず重複してしまいます。
仮に変量効果モデルでは「model = "random", random.method = "walhus"」とやってどうにかエラーが出ずに実行はできましたが、次は警告が出てきました。
これもまた重複のことを言っているような気がしますが、解決方法が分かりません。
Warning in pdata.frame(data, index) : duplicate couples (id-time) in resulting pdata.frame to find out which, use, e.g., table(index(your_pdataframe), useNA = "ifany")
該当のソースコード
こちらの検定のコードを作成した時に参考にしたサイトです
https://qiita.com/ykawakubo/items/a7e470ff0fb243ca9e8d
コード内容は、まず先ほど挙げた写真のようなcsvファイルを読み込み、空値に対して0を代入しています。その次に各週の興行収入を対数変換しています。そして3つのモデルを推定しています。
どのようにすれば変量効果モデルを推定できるようになるでしょうか。どうか知恵をお貸しください。よろしくお願いいたします。
R
1library(tidyverse) 2library(estimatr) 3library(dplyr) 4library(plm) 5 6#4year.csvが先に上げた写真のような内容になっている(パネルデータ) 7allyear <- read.csv("4year.csv", fileEncoding="UTF-8-BOM") 8 9#ラグとジャンルダミーのNAを0に変換 10allyear <- mutate_at(allyear, c('lag1.favorite', 'lag1.retweet', 'lag1.tweet', 11 'lag2.favorite', 'lag2.retweet', 'lag2.tweet', 12 'lag3.favorite', 'lag3.retweet', 'lag3.tweet', 13 'lag4.favorite', 'lag4.retweet', 'lag4.tweet', 14 'lag5.favorite', 'lag5.retweet', 'lag5.tweet', 15 'lag6.favorite', 'lag6.retweet', 'lag6.tweet', 16 'lag7.favorite', 'lag7.retweet', 'lag7.tweet', 17 'lag8.favorite', 'lag8.retweet', 'lag8.tweet', 18 'lag9.favorite', 'lag9.retweet', 'lag9.tweet', 19 'lag10.favorite', 'lag10.retweet', 'lag10.tweet', 20 'Anime', 'Action', 'Adventure', 'Drama', 'Romance', 'Horror', 'War', 'Music', 'Musical', 21 'Sport', 'SF', 'Youth', 'Comedy', 'Crime', 'Violence', 'Yakuza.Ninkyo', 'Suspense', 'Mystery', 22 'Panic', 'Thriller', 'Family', 'Fantasy', 'Documentary', 'History', 'Western', 'Historical', 23 'Biography', 'Omnibus','mojo.genre' 24 25 ), ~replace(., is.na(.), 0)) 26 27#興行収入を対数変換 28allyear$Weekend_Gross.log <- log10(allyear$Weekend_Gross) 29 30 31#Infを0に変換 32allyear[which(allyear == -Inf, TRUE)] <- 0 33 34 35# pooling 36pooling <- plm(Weekend_Gross.log ~ lag1.favorite + lag2.favorite + lag3.favorite + lag4.favorite + lag5.favorite 37 + lag6.favorite + lag7.favorite + lag8.favorite + lag9.favorite + lag10.favorite 38 39 + lag1.retweet + lag2.retweet + lag3.retweet + lag4.retweet + lag5.retweet 40 + lag6.retweet + lag7.retweet + lag8.retweet + lag9.retweet + lag10.retweet 41 42 + lag1.tweet + lag2.tweet + lag3.tweet + lag4.tweet + lag5.tweet 43 + lag6.tweet + lag7.tweet + lag8.tweet + lag9.tweet + lag10.tweet 44 45 + num_week + eiga.account + sougou.account + zokuhen + mojo.genre 46 47 #+ year.2016 48 + year.2017 + year.2018 + year.2019 + mojo.genre 49 50 + Anime + Action + Adventure + Drama + Romance + Horror + War + Music + Musical + Sport 51 + SF + Youth + Comedy + Crime + Violence + Yakuza.Ninkyo + Suspense + Mystery + Panic 52 + Thriller + Family + Fantasy + Documentary + History + Western + Historical + Biography + Omnibus 53 54 , data = allyear, model = "pooling") 55 56 57# within 58within <- plm(Weekend_Gross.log ~ lag1.favorite + lag2.favorite + lag3.favorite + lag4.favorite + lag5.favorite 59 + lag6.favorite + lag7.favorite + lag8.favorite + lag9.favorite + lag10.favorite 60 61 + lag1.retweet + lag2.retweet + lag3.retweet + lag4.retweet + lag5.retweet 62 + lag6.retweet + lag7.retweet + lag8.retweet + lag9.retweet + lag10.retweet 63 64 + lag1.tweet + lag2.tweet + lag3.tweet + lag4.tweet + lag5.tweet 65 + lag6.tweet + lag7.tweet + lag8.tweet + lag9.tweet + lag10.tweet 66 67 + num_week + eiga.account + sougou.account + zokuhen + mojo.genre 68 69 #+ year.2016 70 + year.2017 + year.2018 + year.2019 + mojo.genre 71 72 + Anime + Action + Adventure + Drama + Romance + Horror + War + Music + Musical + Sport 73 + SF + Youth + Comedy + Crime + Violence + Yakuza.Ninkyo + Suspense + Mystery + Panic 74 + Thriller + Family + Fantasy + Documentary + History + Western + Historical + Biography + Omnibus 75 76 , data = allyear, model = "within") 77 78# random 79#この変量効果モデルにてエラーが発生 80random <- plm(Weekend_Gross.log ~ lag1.favorite + lag2.favorite + lag3.favorite + lag4.favorite + lag5.favorite 81 + lag6.favorite + lag7.favorite + lag8.favorite + lag9.favorite + lag10.favorite 82 83 + lag1.retweet + lag2.retweet + lag3.retweet + lag4.retweet + lag5.retweet 84 + lag6.retweet + lag7.retweet + lag8.retweet + lag9.retweet + lag10.retweet 85 86 + lag1.tweet + lag2.tweet + lag3.tweet + lag4.tweet + lag5.tweet 87 + lag6.tweet + lag7.tweet + lag8.tweet + lag9.tweet + lag10.tweet 88 89 + num_week + eiga.account + sougou.account + zokuhen + mojo.genre 90 91 #+ year.2016 92 + year.2017 + year.2018 + year.2019 + mojo.genre 93 94 + Anime + Action + Adventure + Drama + Romance + Horror + War + Music + Musical + Sport 95 + SF + Youth + Comedy + Crime + Violence + Yakuza.Ninkyo + Suspense + Mystery + Panic 96 + Thriller + Family + Fantasy + Documentary + History + Western + Historical + Biography + Omnibus 97 98 , data = allyear, model = "random") 99 100 101summary(pooling) 102summary(within) 103summary(random) 104

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。