## clear data & close graphs--------
rm(list=ls())
graphics.off()
#install.packages("dplyr")
#install.packages("pastecs")
#install.packages("haven")
library("dplyr")
library("pastecs")
#设置当前工作空间-----------
getwd()
#setwd("D:/ⅡR+Stata/R语言代码2021/R语言包 CGSS/媒介使用 vs 幸福-1")
#--------import data---------
library(haven)
data <- read.csv("3 data.csv")
data<-as.data.frame(data)
class(data)
newdata <-data
###加载Bootstrap中介效应程序:
library(bruceR)
library(progress)
#查看是否有缺失值
is.na(data)
data[!complete.cases(data),] #列出有缺失值的行
nrow(data[!complete.cases(data),]) #计算有缺失值的样本量,12582(原因是有些注释变量)
#对青年群体样本数据newdata进行数据预处理:
##1.因变量
table(newdata$like)
table(newdata$comment)
table(newdata$transmit)
##2.自变量
##(1)传播主体1
table(newdata$accounts_nature) #1-4
newdata$publisher <- as.numeric(newdata$accounts_nature==1)
newdata$company <- as.numeric(newdata$accounts_nature==2)
newdata$author <- as.numeric(newdata$accounts_nature==3)
newdata$blogger <- as.numeric(newdata$accounts_nature==4)
table(newdata$blogger)
#company+author+blogger
##(2)传播主体2
table(newdata$accounts_field)
newdata$zonghe <- as.numeric(newdata$accounts_field==1)
newdata$chuizhi <- as.numeric(newdata$accounts_field==2)
table(newdata$chuizhi)
##(3)标题句式(此分类不显著,拟删除)
newdata<-newdata[newdata$title1>0,] ##筛选数据
table(newdata$title1) #1-3
newdata$chenshu <- as.numeric(newdata$title1==1)
newdata$gantan <- as.numeric(newdata$title1==2)
newdata$yiwen <- as.numeric(newdata$title1==3)
table(newdata$yiwen)
#gantan+yiwen
##(4)标题2(一句还是)
table(newdata$title2) #1-3
newdata$one <- as.numeric(newdata$title2==1)
newdata$two <- as.numeric(newdata$title2==2)
newdata$three <- as.numeric(newdata$title2==3)
table(newdata$three)
##(5)封面(纯文字为参照)
table(newdata$cover_type) #0-4
newdata<-newdata[newdata$cover_type>0,] ##筛选数据
newdata$chunwenzi <- as.numeric(newdata$cover_type==1)
newdata$shipinjietu <- as.numeric(newdata$cover_type==2)
newdata$tupian_wenzi <- as.numeric(newdata$cover_type==3)
newdata$shipin_wenzi <- as.numeric(newdata$cover_type==4)
table(newdata$shipin_wenzi)
#shipinjietu+tupian_wenzi+shipin_wenzi
##(6)内容
table(newdata$content_type) #1-10
newdata$shudan <- as.numeric(newdata$content_type==1|newdata$content_type==7)
newdata$gushi <- as.numeric(newdata$content_type==2)
newdata$zhishi <- as.numeric(newdata$content_type==3|newdata$content_type==5)
newdata$gerenganwu <- as.numeric(newdata$content_type==4)
newdata$wenanjinju <- as.numeric(newdata$content_type==6)
newdata$zuozhe <- as.numeric(newdata$content_type==8)
newdata$chanpintuijian <- as.numeric(newdata$content_type==9)
newdata$hudonglei <- as.numeric(newdata$content_type==10)
table(newdata$zhishi)
#shudan+gushi+zhishi+gerenganwu+wenanjinju+zuozhe+hudonglei
##(7)视频
table(newdata$video_type) #1-9
newdata$tuwen <- as.numeric(newdata$video_type==1)
newdata$dognhua <- as.numeric(newdata$video_type==2)
newdata$zhenren <- as.numeric(newdata$video_type==3)
newdata$lieju <- as.numeric(newdata$video_type==4)
newdata$qignjingju <- as.numeric(newdata$video_type==5)
newdata$paishe <- as.numeric(newdata$video_type==6)
newdata$gongkaike <- as.numeric(newdata$video_type==7)
newdata$hunhe <- as.numeric(newdata$video_type==8)
newdata$xunirenwu <- as.numeric(newdata$video_type==9)
table(newdata$xunirenwu)
#dognhua+zhenren+lieju+qignjingju+paishe+gongkaike+hunhe+xunirenwu+
##(7)字幕
table(newdata$subtitle) #0-1
newdata$nosubtitle <- as.numeric(newdata$subtitle==0)
newdata$havesubtitle <- as.numeric(newdata$subtitle==1)
##(8)叙事风格
table(newdata$narrative_style) #1-6
newdata$qingsong <- as.numeric(newdata$narrative_style==1)
newdata$ganxing <- as.numeric(newdata$narrative_style==2)
newdata$jiqing <- as.numeric(newdata$narrative_style==3)
newdata$shanggan <- as.numeric(newdata$narrative_style==4)
newdata$lixing <- as.numeric(newdata$narrative_style==5)
newdata$gaoxiaoyoumo <- as.numeric(newdata$narrative_style==6)
#ganxing+jiqing+shanggan+lixing+gaoxiaoyoumo+
##(9)音乐
table(newdata$music) # 0-7
newdata$shuhuan <- as.numeric(newdata$music==1)
newdata$huobo <- as.numeric(newdata$music==2)
newdata$zhuangyan <- as.numeric(newdata$music==3)
newdata$beishangning <- as.numeric(newdata$music==4)
newdata$jiqignpengpai <- as.numeric(newdata$music==5)
newdata$gufengwanzhuan <- as.numeric(newdata$music==6)
newdata$guiyi <- as.numeric(newdata$music==7)
#huobo+zhuangyan+beishangning+jiqignpengpai+gufengwanzhuan+guiyi+
##(10)时长
table(newdata$video_length) # 1-3
##(一)基准模型
attach(newdata)
#install.packages("ggplot2")
require(foreign)
require(ggplot2)
require(MASS)
#install.packages("Hmisc")
require(Hmisc)
#install.packages("reshape2")
require(reshape2)
#attach(newdata)
dim(newdata) #899样本
#summary(newdata)
#mode(newdata)
#使用剔除异常值的样本进行建模
##1.OLS模型(like+comment+transmit)
fit1<-lm(comment~shudan+gushi+zhishi+gerenganwu+wenanjinju+zuozhe+hudonglei,data = newdata)
summary(fit1)
fit2<-lm(like~ganxing+jiqing+shanggan+lixing+gaoxiaoyoumo,data = newdata)
summary(fit2)
fit3<-lm(like~company+author+blogger+two+three+
shipinjietu+tupian_wenzi+shipin_wenzi+
shudan+gushi+zhishi+gerenganwu+wenanjinju+zuozhe+hudonglei+
# dognhua+zhenren+lieju+qignjingju+paishe+gongkaike+hunhe+xunirenwu+
ganxing+jiqing+shanggan+lixing+gaoxiaoyoumo+
# huobo+zhuangyan+beishangning+jiqignpengpai+gufengwanzhuan+guiyi+
video_length,data = newdata) #OLS (2)
summary(fit3)
视频分析代码douyin
最新推荐文章于 2024-08-18 12:57:05 发布