[英]Multiple Imputation in R(Error in solve.default(xtx + diag(pen)) : system is computationally singular: reciprocal condition number =)
I want to analyze data about Covid-19.我想分析有关 Covid-19 的数据。 I have done some part of the data cleaning and I have end up with this dataset (160260 rows and 34 columns).
我已经完成了部分数据清理工作,最终得到了这个数据集(160260 行和 34 列)。 I have converted the variables continent,location,tests_units into factors.
我已将变量continent、location、tests_units 转换为因子。 I wanted to check about missing values so I calculated the percentages of missing values and the results were:
我想检查缺失值,所以我计算了缺失值的百分比,结果是:
> (colMeans(is.na(dataset1)))*100
continent location date total_cases
0.0000000 0.0000000 0.0000000 1.9699239
new_cases total_deaths new_deaths reproduction_rate
2.0366904 8.0094846 8.1130663 14.0078622
icu_patients hosp_patients weekly_icu_admissions weekly_hosp_admissions
84.7747410 83.7021091 96.2386123 92.5851741
total_tests new_tests positive_rate tests_per_case
54.4465244 56.6966180 43.9292400 44.7154624
tests_units people_fully_vaccinated new_vaccinations stringency_index
38.0974666 73.6390865 76.2298765 15.7138400
population population_density median_age aged_70_older
0.0000000 4.3073755 10.5291401 11.0077374
gdp_per_capita extreme_poverty cardiovasc_death_rate diabetes_prevalence
11.9381006 42.0897292 11.0077374 6.7003619
female_smokers male_smokers handwashing_facilities life_expectancy
32.9963809 33.9535754 55.9690503 0.4785973
human_development_index excess_mortality
13.3738924 96.1225509
I didn't want to analyze a dataset with missing values and as a result I searched a lot in order to find a way to fill these NAs.I found that I can use mice function in order to fill these NAs.My goals are:我不想分析缺失值的数据集,因此我进行了很多搜索以找到填充这些 NA 的方法。我发现我可以使用鼠标 function 来填充这些 NA。我的目标是:
I followed every step from this link and I run this code:我遵循此链接的每一步并运行此代码:
library(mice)
init = mice(dataset1,maxit = 0)
meth = init$method
predM = init$predictorMatrix
predM[, c("date")] = 0 #goal number 1
meth[c("continent","location","date","population")] = "" #goal number 2
meth[c("total_cases","new_cases","total_deaths","new_deaths","reproduction_rate",
"icu_patients","hosp_patients","weekly_icu_admissions",
"weekly_hosp_admissions","total_tests","new_tests","positive_rate",
"tests_per_case","people_fully_vaccinated",
"new_vaccinations","stringency_index","population_density","median_age",
"aged_70_older","gdp_per_capita","extreme_poverty",
"cardiovasc_death_rate","diabetes_prevalence","female_smokers",
"male_smokers","handwashing_facilities","life_expectancy",
"human_development_index","excess_mortality")]="pmm" #goal number 3
meth[c("tests_units")] = "polyreg" #goal number 4
set.seed(103)
imputed = mice(dataset1, method=meth, predictorMatrix=predM, m=5)
The result I got was我得到的结果是
> library(mice)
> init = mice(dataset1,maxit = 0)
Warning message:
Number of logged events: 1
> meth = init$method
> predM = init$predictorMatrix
> predM[, c("date")] = 0
> meth[c("continent","location","date","population")] = ""
> meth[c("total_cases","new_cases","total_deaths","new_deaths","reproduction_rate",
+ "icu_patients","hosp_patients","weekly_icu_admissions",
+ "weekly_hosp_admissions","total_tests","new_tests","positive_rate",
+ "tests_per_case","people_fully_vaccinated",
+ "new_vaccinations","stringency_index","population_density","median_age",
+ "aged_70_older","gdp_per_capita","extreme_poverty",
+ "cardiovasc_death_rate","diabetes_prevalence","female_smokers",
+ "male_smokers","handwashing_facilities","life_expectancy",
+ "human_development_index","excess_mortality")]="pmm"
> meth[c("tests_units")] = "polyreg"
>
> set.seed(103)
> imputed = mice(dataset1, method=meth, predictorMatrix=predM, m=5)
iter imp variable
1 1 total_casesError in solve.default(xtx + diag(pen)) :
system is computationally singular: reciprocal condition number = 2.80783e-24
which was not very pleasant.这不是很愉快。 What should I change or which code should I run?
我应该更改什么或应该运行哪些代码?
Thanks in advance!提前致谢!
have you checked your logged events:您是否检查过记录的事件:
view(init$loggedEvents)
Maybe it's because of some imputationmethods you used ("polyreg").也许是因为您使用了一些插补方法(“polyreg”)。 Have you tried to use more robust one's only (pmm)
您是否尝试过仅使用更强大的(pmm)
Peace, M.和平,M.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.