rm(list=ls())gc()options(scipen = 200)#读取数据集# haven包读取sav格式文件library(haven)data <- read_sav("C:/pic/data/BESExpertSurveyData.sav")#数据探索summary(data)names(data)#####提取自变量和因变量# 因变量是leftrightcon 自变量femalequalitycon和gayequalitycondata1 <- data[,c(4,84,92)]summary(data1)######将缺失值na替换0#data1[is.na(data1)] <- 0##############femalequalitycon和gayequalitycon 共缺失14个。###删除具有缺失值的行data2 <- data1[complete.cases(data1),] #######直方图hist(data2$leftrightCon03)hist(data2$femaleequalityCon03)hist(data2$gayequalityCon03)######相关性探索# install.packages("psych")library(psych)pairs.panels(data2[c("leftrightCon03","femaleequalityCon03","gayequalityCon03")])#######进行多元线性回归##########ins_model <- lm(leftrightCon03~femaleequalityCon03+gayequalityCon03,data=data2)######查看模型表达式ins_model# 评估模型的性能summary(ins_model)