简体   繁体   中英

r: variable was fitted with type "numeric" but type "character" was supplied by using cmest() function in R

I try to fit following cmest () function in R

exp3 <- cmest(data = m.mediation.pbmi, model = "rb", full = TRUE, outcome = "over", 
          exposure = "parent_prim_bin", mediator = "pbmi", basec = c("migr_all", "age"), 
          EMint = FALSE, mreg = list("linear"), yreg = "logistic", 
          astar = 0, a = 1, mval = list("M1_0"), estimation = "imputation", 
          inference = "bootstrap",  nboot = 10, boot.ci.type = "bca")

The data a provided by a SPSS file and in the data description for the variable pbmi is provided that this is a numerical variable with attr(*, "format.spss")=chr.

Any ideas to solve this problem?

I am also experiencing this issue. It might be helpful to contact the author and inform them about the problem. I have already notified them and provided a link to this discussion in the hopes that they can provide a response.

In my case the code looks

cmest(data = Contemporary, model = "rb", outcome = "gov.effective", 
      basec= c("ln_avg_gold_pop","ln_avg_oil_pop","ln_avg_all_diamonds_pop","islam","legor_fr"),
      exposure = "ln_export_area", mediator = c("ethnic_fractionalization","lngdppc"),
      EMint = FALSE, mreg = list("linear","linear"), yreg = "linear", 
      astar = 0, a = 1, mval = list(0, "lngdppc_0"), estimation = "imputation", 
      inference = "boot")

The error comes as: "Error: variable 'lngdppc' was fitted with type "numeric" but type "character" was supplied"

When verifying, it is numerical summary(lngdppc) Min. 1st Qu.Median Mean 3rd Qu. Max. 5.561 6.620 7.086 7.265 7.914 9.584

is.numeric(lngdppc)

[1] TRUE

I have tried solving it in different ways to no avail, and interestingly, it seems that whichever variable occupies the second position triggers the error message.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM