0

EDIT: Just wanted to let you all know I figured out the issue-- the indirects function I was using indicated that the boot function should use the 6th regression coefficient in the linear regression model to do its things but it turns out I only had five coefficients in this particular model. Whoops, haha. Thank you to everyone who helped me troubleshoot this!

I know this issue has been addressed in past posts (here and here) but I have not been able to resolve it using the answers given there. The first post said that there was a NA in t but I didn't know what t was. The second post said to remove missing values from the variables you're using, but I've checked and none of my variables have missing values.

I know I need to give a "reproducible example" (meaning I would need to upload the data set, yes?) but I can't figure out how to upload data to a question. I have checked StackOverflow's help center, FAQ's, and advanced editing help page. I would really, really appreciate it if someone could explain to me how to upload R data in order to give a reproducible example.

The code I am using is:

indirects = function(data,indices) {
  return(lm(monin2$directharm~monin2$racismc*monin2$vig+monin2$manip)$coef[6] * 
           lm(monin2$hatecrime~monin2$racismc*monin2$vig+monin2$manip+monin2$directharm,data=data,subset=indices)$coef[6]) }

b = boot(data=monin2,statistic=indirects,R=5000)
ci = boot.ci(b,conf=.95,type="bca")
b 
ci 

The error it produces is

Error in if (const(t, min(1e-08, mean(t, na.rm = TRUE)/1e+06))) { : 
  missing value where TRUE/FALSE needed

I used the following code to check if any of my variables had missing values, and my interpretation of the output is that no missing values exist in any of them:

 which (is.na(monin2$hatecrime))
integer(0)
> which (is.na(monin2$directharm))
integer(0)
> which (is.na(monin2$vig))
integer(0)
> which (is.na(monin2$manip))
integer(0)
> which (is.na(monin2$racismc))
integer(0)
StupidWolf
  • 45,075
  • 17
  • 40
  • 72
Gina Roussos
  • 53
  • 1
  • 1
  • 5
  • Run `dput(monin2)` then copy & paste the output to your question – Tung Apr 06 '18 at 16:20
  • Are any values missing, and not just NA? If so, on import, you can convert them to NA. `df <- read.csv("foo.csv", header=T, na.strings=c("","NA"))` – Anonymous coward Apr 06 '18 at 17:12
  • Sorry, can you talk more about the difference between missing and NA? Are you saying that if there was a value missing in my original dataset in excel, it might not have been converted into NA but left blank? – Gina Roussos Apr 06 '18 at 17:36
  • Also I tried to copy-paste the output of 'dput(monin2)' but it made the post go over the 30,000 character limit, so it wouldn't let me do it. – Gina Roussos Apr 06 '18 at 17:41
  • @GinaRoussos Correct, it's possible something in excel may have been imported that way. [This may explain how R handles missing values](https://stats.idre.ucla.edu/r/faq/how-does-r-handle-missing-values/). There are differences between `NA`, `NULL`, and zero-length entries. You can also the do conversion within your table. `foo$column[foo$column == ""] <- NA` – Anonymous coward Apr 06 '18 at 18:54
  • @Anonymouscoward, thank you for the explanation. I used the code you provided to recode any blank spaces to `NA`, but it didn't change the output of `is.na()` , it's still saying none of the variables have any NA values. And the boot function still produces the error message. :( – Gina Roussos Apr 06 '18 at 19:17

1 Answers1

0

The following code picks out the sixth coefficient in the linear regression model for boot() to use, but in this particular model I only have five coefficients, so I was asking boot() to use a variable that didn't exist.

indirects = function(data,indices) {
  return(lm(monin2$directharm~monin2$racismc*monin2$vig+monin2$manip)$coef[6] * 
           lm(monin2$hatecrime~monin2$racismc*monin2$vig+monin2$manip+monin2$directharm,data=data,subset=indices)$coef[6]) }
Gina Roussos
  • 53
  • 1
  • 1
  • 5