简体   繁体   English

R中的多重插补(solve.default中的错误(xtx + diag(pen)):系统在计算上是奇异的:倒数条件数=)

[英]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。我的目标是:

  1. Use the mice function in a way that the variable date is not used as a predictor.使用鼠标 function 的方式是变量日期不用作预测变量。
  2. Not to impute values in the variables: continent,location,date,population because they don't have NAs.不要在变量中估算值:大陆、位置、日期、人口,因为它们没有 NA。
  3. To impute values in the variables: 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 with the method pmm (Predictive mean matching) because these variables are numeric. To impute values in the variables: 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(预测均值匹配),因为这些变量是数字的。
  4. To impute values in the variable tests_units with the method polyreg (Polytomous logistic regression) because this variable is a factor with 4 levels.使用 polyreg(多元逻辑回归)方法估算变量 tests_units 中的值,因为该变量是具有 4 个水平的因子。

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.

相关问题 R mlogit在solve.default(H,g [!fixed])中引发错误:系统在计算上是单数的:倒数条件数 - R mlogit throws Error in solve.default(H, g[!fixed]):system is computationally singular: reciprocal condition number resolve.default(vamos)中的错误:系统在计算上是单数:倒数条件数 - Error in solve.default(vamos): system is computationally singular: reciprocal condition number 如何解决 solve.default(H, g[:fixed]) 中的 mlogit 错误:系统在计算上是奇异的。 倒数条件数 = 3?03549e-18? - How to solve mlogit Error in solve.default(H, g[!fixed]) : system is computationally singular: reciprocal condition number = 3.03549e-18? mlogit中的错误:solve.default中的错误(H,g [!fixed]):系统是计算奇异的:倒数条件数= 3.4767e-18 - Error in mlogit: Error in solve.default(H, g[!fixed]) : system is computationally singular: reciprocal condition number = 3.4767e-18 系统在计算上是奇异的:R 中的倒数条件数 - System is computationally singular: reciprocal condition number in R 是否存在系统计算奇异的解决方案:R 中的倒数条件数 = ...? - Is there an solution for system is computationally singular: reciprocal condition number=… in R? 使用 plm package 时如何解决“系统在计算上是奇异的:倒数条件数 = 3.12737e-31”错误消息 - How to solve “system is computationally singular: reciprocal condition number = 3.12737e-31” error message when using plm package mlogit软件包中的错误:系统在计算上是单个的:倒数条件编号= 8.87901e-37 - Error in mlogit package: system is computationally singular: reciprocal condition number = 8.87901e-37 当鼠标返回“系统在计算上是奇异的”错误时,在 R 中进行插补 - Do imputation in R when mice returns error that “system is computationally singular” 系统是 R 中的计算奇异错误 - System is computationally singular error in R
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM