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.

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")
```

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

- Prev: VB6 calling WCF: Could not find endpoint element
- Next: in R:how to store number by order in list

*1*### Error Message in Matrix math- object length

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

*3*### Remove empty zero length rows in list with R

*4*### Error message "undefined reference for `CPU_ZERO'"

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

*6*### R - argument is of length zero in if statement

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

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

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

*10*### Override max length error message in MVC

*11*### Error unpack requires a string argument of length 16

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

*13*### Bytes message argument error

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

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

*16*### Error in 1:x : argument of length 0

*17*### Error: Replacement has length zero R

*18*### Invalid 'length' argument Error

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

*20*### 'replacement has length zero' error in R

*21*### "Argument of length zero" in R

*22*### if statement in R. Error argument is of length zero

*23*### r if statement meet error: argument is of length zero

*24*### TSLM Error: Replacement Has Length Zero

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

*26*### R function length error message

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

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

*29*### String cannot be of zero length error

## Comments