Rilcon42 - 5 months ago 119

R Question

I am trying to model values for an interaction, but when I input the IV and moderator one way it fails. When I reverse them it works fine. Both the IV and moderator are numeric, so its not a data type issue. Anyone know why this is happening?

Error message:

`Error in cov[interactionterms[j], interactionterms[j]] : subscript out of bounds`

Example

`library(probemod)`

lm.model<-lm(mpg~cyl*disp,data=mtcars)

## FAILS

ppick<-pickapoint(lm.model, dv="mpg", iv="disp", mod="cyl", method='meansd')

## WORKS FINE

ppick<-pickapoint(lm.model, dv="mpg", iv="cyl", mod="disp", method='meansd')

Answer

Note that your regression model is specified as `cyl*disp`

, so the interaction term is `cyl:disp`

. **Order counts**.

If you specify `iv = "disp"`

and `mod = "cyl"`

, `pickapoint`

will look for `disp:cyl`

*(trace the local variable interactionterms and you will see it)* but there is no such term in

`lm.model`

.Covariance matrix has dimnames:

```
# (Intercept) cyl disp cyl:disp
#(Intercept) 25.04638446 -3.770034504 -0.162461470 2.219922e-02
#cyl -3.77003450 0.705917580 0.017132037 -2.807237e-03
#disp -0.16246147 0.017132037 0.001600197 -1.929310e-04
#cyl:disp 0.02219922 -0.002807237 -0.000192931 2.448097e-05
```

therefore you get "subscript out of bounds" error when looking for `disp:cyl`

.