问题描述
每当我尝试通过函数 ceresPlots() 绘制图形时,它都会显示类似这样的错误。
> ceresPlots(fit_2)
Error in ceresPlots.default(fit_2) : No plots specified
In addition: Warning message:
In ceresPlots.default(fit_2) : Factors skipped in drawing CERES plots.
我不知道为什么会这样。我在下面附上我的代码。请帮帮我。
#### Importing the main required libraries ####
#### 1. Activate Libraries ####
library(Hmisc)
library(car)
library(readxl)
library(magrittr)
library(broom)
library(ggplot2)
#### Manipulating Data ####
#### 1. Setting a working directory ####
setwd("C:/Users/acer/Desktop/Important/M.SC/STATISTICS THIRD SEMESTER/4. PROJECT/PROJECT")
#### 2. Reading the cancer data set and eliminating the values ####
cancer<-read_excel("Main spreadsheet.xlsx",na="---")
summary(cancer)
View(cancer)
cancer$`% Ctry Some College 18_24`<-as.numeric(impute(cancer$`% Ctry Some College 18_24`,mean))
cancer$`% Ctry Employed 16_Over`<-as.numeric(impute(cancer$`% Ctry Employed 16_Over`,mean))
cancer$`% Ctry Private H Coverage Alone`<-as.numeric(impute(cancer$`% Ctry Private H Coverage Alone`,mean))
summary(cancer)
View(cancer)
#### To check if there is a relationship between the response variable and the predictors ####
#### 1. Making a set of variables for regression modelling ####
cancer.sub<-subset(cancer,select=c(`Avg Deaths per year`,`Avg Ann Count`,`Incidence Rate`,`Median Income`,`Popu Est 2015`,`Poverty Percent`,`Study per Capita`,`Binned Income`,`Median Age`,`Median Age Male`,`Median Age Female`,`Percent Married`,`% Ctry No LHS 18-24`,`% Ctry No HSD 18-24`,`% Ctry Some College 18_24`,`% Ctry Bach Deg 18_24`,`% Ctry No HSD 25_Over`,`% Ctry Bach Deg 25_Over`,`% Ctry Employed 16_Over`,`% Ctry Unemployed 16_Over`,`% Ctry Private H Coverage`,`% Ctry Private H Coverage Alone`,`% Ctry Emp Priv H Coverage`,`% Ctry Public H Coverage`,`% Ctry Public H Coverage Alone`,`% Ctry Res White`,`% Ctry Res Black`,`% Ctry Res Asian`,`% Ctry Other Race`,`% Ctry Married Households`,`Birth Rate`,`Target Death Rate`))
fit<-lm(formula = `Target Death Rate`~.,data = cancer.sub)
summary(fit)
#### To check which variables have a strong relation to Target Death Rate ####
#### 1. Linear regression using the features with significant p-values only ####
fit_1<-lm(`Target Death Rate` ~ `Avg Deaths per year` + `Avg Ann Count` + `Incidence Rate` + `Median Income` + `Popu Est 2015` +
`Binned Income` + `Median Age Male` + `Percent Married` + `% Ctry No LHS 18-24` + `% Ctry No HSD 18-24` + `% Ctry Bach Deg 18_24` +
`% Ctry No HSD 25_Over` + `% Ctry Bach Deg 25_Over` + `% Ctry Employed 16_Over` + `% Ctry Private H Coverage` + `% Ctry Emp Priv H Coverage` +
`% Ctry Public H Coverage` + `% Ctry Public H Coverage Alone` + `% Ctry Res White` + `% Ctry Res Black` + `% Ctry Other Race` +
`% Ctry Married Households` + `Birth Rate`,data = cancer.sub)
#### 2. Linear regression using mixed selection ####
fit_step<-MASS::stepAIC(fit,direction = "both",trace = FALSE)
#### 3. Comparison of the two above models ####
fit_step$call
fit_1$call
#### To check the presence of multicollinearity in the model ####
#### 1. Checking multicollinearity in fit_step model ####
vif(fit_step) %>% knitr::kable()
#### 2. Removing all the multicollinear variables ####
fit_2<-lm(`Target Death Rate` ~ `Incidence Rate` + `Median Income` + `Popu Est 2015` +
`Median Age Male` + `% Ctry No LHS 18-24` + `% Ctry No HSD 18-24` + `% Ctry Bach Deg 18_24` +
`% Ctry No HSD 25_Over` + `% Ctry Employed 16_Over` + `% Ctry Emp Priv H Coverage` +
`% Ctry Public H Coverage Alone` + `% Ctry Res Black` + `% Ctry Other Race` +
`% Ctry Married Households` + `Birth Rate`,data = cancer.sub)
summary(fit_2)
#### 3. Checking multicollinearity of the refitted model ####
vif(fit_2) %>% knitr::kable()
#### To check if there is any linear relationship between the predictors and the outcome ####
#### 1. The residual plot of fitted values versus the residuals ####
residualPlot(fit_2,type = "rstandard")
#### 2. Exploring non-linearity by looking at Component Residual plots(CR plots)
ceresPlots(fit_2)
我已经尝试了这个函数的每一种形式,但没有任何效果。我真的不知道自己哪里出错了。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)