#探索的因子分析 #ドラマ特性 x <- read.delim("clipboard") install.packages(c("lavaan","semTools","semPlot")) library(lavaan) library(semTools) library(semPlot) factanal(x,factors=5,rotation="promax") #動機要因 #消費者特性 x <- read.delim("clipboard") install.packages(c("lavaan","semTools","semPlot")) library(lavaan) library(semTools) library(semPlot) factanal(x,factors=8,rotation="promax") #確認的因子分析 HS.model.cfa <- ' akogare=~akogare1+akogare2+akogare3 zenwakanketu=~zenwakanketu1+zenwakanketu2+zenwakanketu3 gensaku=~gensaku1+gensaku2+gensaku3 torikata=~torikata1+torikata2+torikata3' HS.model.cfa <- ' sukinahaiyu=~sukinahaiyu1+sukinahaiyu2+sukinahaiyu3 koukoku=~koukoku1+koukoku2+koukoku3 kutikomi=~kutikomi1+kutikomi2+kutikomi3 tyomei=~tyomei1+tyomei2+tyomei3 gisikiteki=~gisikiteki1+gisikiteki2+gisikiteki3 syudanteki=~syudanteki2+syudanteki3 zenkai=~zenkai1+zenkai2+zenkai3 nitiyou=~nitiyou1+nitiyou2+nitiyou3' HS.model.cfa <- ' syakousei=~syakousei1+syakousei2+syakousei3+syakousei4 ryukou=~ryukou1+ryukou2+ryukou3 syukanteki=~syukanteki1+syukanteki2+syukanteki3 jikokenji=~jikokenji1+jikokenji2+jikokenji4 kaigaidorama=~kaigaidorama1+kaigaidorama2+kaigaidorama3 yokanosukunasa=~yokanosukunasa1+yokanosukunasa2+yokanosukunasa3 mame=~mame1+mame2+mame3' fit <- lavaan(HS.model.cfa, data=x,  auto.var=TRUE, auto.fix.first=TRUE,auto.cov.lv.x=TRUE) summary(fit, fit.measures=TRUE,standardized=T,rsquare=T) modindices(fit,sort=T) #共分散構造分析 HS.model.sem <- ' sityouito=~sityouito1+sityouito2+sityouito3+sityouito4+sityouito5 sityouito ~akogare + zenwakanketu + gensaku + torikata akogare=~akogare1+akogare2+akogare3 zenwakanketu=~zenwakanketu1+zenwakanketu2+zenwakanketu3 gensaku=~gensaku1+gensaku2+gensaku3 torikata=~torikata1+torikata2+torikata3' HS.model.sem <- ' sityouito=~sityouito1+sityouito2+sityouito3+sityouito4+sityouito5 sityouito ~ sukinahaiyu+ koukoku + kutikomi + tyomei + gisikiteki + syudanteki + zenkai + nitiyou sukinahaiyu=~sukinahaiyu1+sukinahaiyu2+sukinahaiyu3 koukoku=~koukoku1+koukoku2+koukoku3 kutikomi=~kutikomi1+kutikomi2+kutikomi3 tyomei=~tyomei1+tyomei2+tyomei3 gisikiteki=~gisikiteki1+gisikiteki2+gisikiteki3 syudanteki=~syudanteki2+syudanteki3 zenkai=~zenkai1+zenkai2+zenkai3 nitiyou=~nitiyou1+nitiyou2+nitiyou3' HS.model.sem <- ' sityouito=~sityouito1+sityouito2+sityouito3+sityouito4+sityouito5 sityouito ~syakousei + ryukou + syukanteki + jikokenji + kaigaidorama + yokanosukunasa + mame syakousei=~syakousei1+syakousei2+syakousei3+syakousei4 ryukou=~ryukou1+ryukou2+ryukou3 syukanteki=~syukanteki1+syukanteki2+syukanteki3 jikokenji=~jikokenji1+jikokenji2+jikokenji4 kaigaidorama=~kaigaidorama1+kaigaidorama2+kaigaidorama3 yokanosukunasa=~yokanosukunasa1+yokanosukunasa2+yokanosukunasa3 mame=~mame1+mame2+mame3' fit.sem <- lavaan(HS.model.sem, data=x,  auto.var=TRUE, auto.fix.first=TRUE,auto.cov.lv.x=TRUE) summary(fit.sem, fit.measures=TRUE,standardized=T,rsquare=T) #追加分析 #共分散構造分析 HS.model.sem <- ' sityouito=~sityouito1+sityouito2+sityouito3+sityouito4+sityouito5 sityouito ~seibetu + club+ doubleschool + arubaito+ keiji+ renai+ comedy+ history+ iryou+ action+ mistery+ gakuen+ family+ sf+ sonota' fit.sem <- lavaan(HS.model.sem, data=x, auto.var=TRUE, auto.fix.first=TRUE,auto.cov.lv.x=TRUE) summary(fit.sem, fit.measures=TRUE,standardized=T,rsquare=T) #二項ロジット分析 x <- read.delim("clipboard") install.packages(c("lavaan","semTools","semPlot")) library(lavaan) library(semTools) library(semPlot) res1<-glm(sityouhindo1~tvweek+tvday+tvdoramayear,data=x) summary(res1) res1<-glm(sityouhindo1+sityouhindo2+sityouhindo3~sityouhonsuu+ seibetu + club+ doubleschool + arubaito+ keiji+ renai+ comedy+ history+ iryou+ action+ mistery+ gakuen+ family+ sf+ sonota,data=x) summary(res1) #二項ロジット分析の相関係数 x <- read.delim("clipboard") quant1<-cbind(x[,1:3]) quant2<-cbind(tvweek,tvday,tvdoramayear) round(cor(quant1),3) #クラスター分析 install.packages("dplyr") x<- read.csv("a.csv", header=T) kmeans_result<-kmeans(x[,1:11],8) kmeans_result clustered_data <- data.frame(x,kmeans_result$cluster) #平均求める library(dplyr) cluster_summary <- clustered_data %>% + group_by(kmeans_result.cluster) %>% + summarise( + sex_mean = mean(sex), + tvweek_mean = mean(tvweek), + tvday_mean = mean(tvday), + tvdoramayear_mean = min(tvdoramayear) + ) %>% + as.data.frame cluster_summary