error message in R : if (nomZ %in% coded) { : argument is of length zero

user6591823

I'm very new to R (and stackoverflow). I've been trying to conduct a simple slopes analysis for my continuous x dichotomous regression model using lmres, and simpleSlope from the pequod package.

My variables:

SLS - continuous DV csibdiff - continuous predictor (I already manually centered the variable with another code) culture - dichotomous moderator

newmod<-lmres(SLS ~ csibdiff*culture, data=sibdat2)
newmodss <-simpleSlope(newmod, pred="csibdiff", mod1="culture")

However, after running the simpleSlope function, I get this error message:

Error in if (nomZ %in% coded) { : argument is of length zero

I don't understand the nomZ part but I assume something was wrong with my variables. What does this mean? I don't have a nomZ named thing in my data at all. None of my variables are null class (I checked them with the is.null() function), and I didn't seem to have accidentally deleted the contents of the variable (I checked with the table() function).

If anyone else can suggest another function/package that I can do a simple slope analysis in, as well, I'd appreciate it. I've been stuck on this problem for a few days now.

EDIT: I subsetted the relevant variables into a csv file.

https://www.dropbox.com/s/6j82ky457ctepkz/sibdat2.csv?dl=0

Ben Bolker

tl;dr it looks like the authors of the package were thinking primarily about continuous moderators; if you specify mod1="cultureEuropean" (i.e. to match the name of the corresponding parameter in the output) the function returns an answer (I have no idea if it's sensible or not ...)

It would be a service to the community to let the maintainers of the pequod package (maintainer("pequod")) know about this issue ...

Read data and replicate error:

sibdat2 <- read.csv("sibdat2.csv")
library(pequod)
newmod <- lmres(SLS ~ csibdiff*culture, data=sibdat2)
newmodss <- simpleSlope(newmod, pred="csibdiff", mod1="culture")

Check the data:

summary(sibdat2)

We do have some NA values in csibdiff, so try removing these ...

sibdat2B <- na.omit(sibdat2)

But that doesn't actually help (same error as before).

Plot the data to check for other strangeness

library(ggplot2); theme_set(theme_bw())
ggplot(sibdat2B,aes(csibdiff,SLS,colour=culture))+
  stat_sum(aes(size=factor(..n..))) +
  geom_smooth(method="lm")

enter image description here

There's not much going on here, but nothing obviously wrong either ...

Use traceback() to see approximately where the problem is:

traceback()
3: simple.slope(object, pred, mod1, mod2, coded)
2: simpleSlope.default(newmod, pred = "csibdiff", mod1 = "culture")
1: simpleSlope(newmod, pred = "csibdiff", mod1 = "culture")

We could use options(error=recover) to jump right to the scene of the crime, but let's try step-by-step debugging instead ...

debug(pequod:::simple.slope)

As we go through we can see this:

nomZ <- names(regr$coef)[pos_mod]
nomZ ## character(0)

And looking a bit farther back we can see that pos_mod is also a zero-length integer. Farther back, we see that the code is looking through the parameter names (row names of the variance-covariance matrix) for the name of the modifier ... but it's not there.

debug: pos_pred_mod1 <- fI + grep(paste0("\\b", mod1, "\\b"), jj[(fI + 
    1):(fI + fII)])
Browse[2]> pos_mod
## integer(0)
Browse[2]> jj[1:fI]
## [[1]]
## [1] "(Intercept)"
## 
## [[2]]
## [1] "csibdiff"
## 
## [[3]]
## [1] "cultureEuropean"
Browse[2]> mod1
## [1] "culture"

The solution is to tell simpleSlope to look for a variable that is there ...

(newmodss <- simpleSlope(newmod, pred="csibdiff", mod1="cultureEuropean"))
## Simple Slope:
##                              simple slope standard error   t-value   p.value
## Low cultureEuropean (-1 SD)    -0.2720128      0.2264635 -1.201133 0.2336911
## High cultureEuropean (+1 SD)    0.2149291      0.1668690  1.288011 0.2019241

We do get some warnings about NaNs produced -- you'll have to dig farther yourself to see if you need to worry about them.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Error Message in Matrix math- object length

From Dev

R caret package rfe never finishes error task 1 failed - "replacement has length zero"

From Dev

Remove empty zero length rows in list with R

From Dev

Error message "undefined reference for `CPU_ZERO'"

From Dev

While loop in R giving "argument is of length zero" error

From Dev

R - argument is of length zero in if statement

From Dev

The Group expression for the grouping ‘Origin2’ contains an error: Argument 'Length' must be greater or equal to zero. (rsRuntimeErrorInExpression)

From Dev

R “argument is of length zero” in if(condition)

From Dev

PG::Error: ERROR: zero-length delimited identifier at or near """"

From Dev

Override max length error message in MVC

From Dev

Error unpack requires a string argument of length 16

From Dev

R plot.gam Error "Error in 1:object$nsdf : argument of length 0"

From Dev

Bytes message argument error

From Dev

R caret package rfe never finishes error task 1 failed - "replacement has length zero"

From Dev

R: Adding qualitative data using a text() argument to a for loop: unknown index type 'list' error message

From Dev

Error in 1:x : argument of length 0

From Dev

Error: Replacement has length zero R

From Dev

Invalid 'length' argument Error

From Dev

error message in R : if (nomZ %in% coded) { : argument is of length zero

From Dev

'replacement has length zero' error in R

From Dev

"Argument of length zero" in R

From Dev

if statement in R. Error argument is of length zero

From Dev

r if statement meet error: argument is of length zero

From Dev

TSLM Error: Replacement Has Length Zero

From Dev

Ruby: Comparison of String to zero failed (Argument Error)

From Dev

R function length error message

From Dev

Error when iterating for loop over columns: "argument is of length zero"

From Dev

Receiving error while trying to loop an if condition: "argument is of length zero"

From Dev

String cannot be of zero length error

Related Related

  1. 1

    Error Message in Matrix math- object length

  2. 2

    R caret package rfe never finishes error task 1 failed - "replacement has length zero"

  3. 3

    Remove empty zero length rows in list with R

  4. 4

    Error message "undefined reference for `CPU_ZERO'"

  5. 5

    While loop in R giving "argument is of length zero" error

  6. 6

    R - argument is of length zero in if statement

  7. 7

    The Group expression for the grouping ‘Origin2’ contains an error: Argument 'Length' must be greater or equal to zero. (rsRuntimeErrorInExpression)

  8. 8

    R “argument is of length zero” in if(condition)

  9. 9

    PG::Error: ERROR: zero-length delimited identifier at or near """"

  10. 10

    Override max length error message in MVC

  11. 11

    Error unpack requires a string argument of length 16

  12. 12

    R plot.gam Error "Error in 1:object$nsdf : argument of length 0"

  13. 13

    Bytes message argument error

  14. 14

    R caret package rfe never finishes error task 1 failed - "replacement has length zero"

  15. 15

    R: Adding qualitative data using a text() argument to a for loop: unknown index type 'list' error message

  16. 16

    Error in 1:x : argument of length 0

  17. 17

    Error: Replacement has length zero R

  18. 18

    Invalid 'length' argument Error

  19. 19

    error message in R : if (nomZ %in% coded) { : argument is of length zero

  20. 20

    'replacement has length zero' error in R

  21. 21

    "Argument of length zero" in R

  22. 22

    if statement in R. Error argument is of length zero

  23. 23

    r if statement meet error: argument is of length zero

  24. 24

    TSLM Error: Replacement Has Length Zero

  25. 25

    Ruby: Comparison of String to zero failed (Argument Error)

  26. 26

    R function length error message

  27. 27

    Error when iterating for loop over columns: "argument is of length zero"

  28. 28

    Receiving error while trying to loop an if condition: "argument is of length zero"

  29. 29

    String cannot be of zero length error

HotTag

Archive