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)] <- 033 34 35# pooling36pooling <- 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.201648 + 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# within58within <- 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.201670 + 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# random79#この変量効果モデルにてエラーが発生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.201692 + 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
0 コメント