Psych package error with autoR() function: Error in apply(x[1:(n.obs - lag), ], 2, sd, na.rm = na.rm): dim(X) must have a positive length

Viewed 34

This is a follow up to my last question I posted. Someone did find a working solution, or so it seemed. It looked as if the code ran as expected, but I'm a bit dubious now.

I have a dataframe

data <- structure(list(study_id = structure(c(1001, 1001, 1002, 1002, 
1003, 1003), format.spss = "F6.0", display_width = 0L), Date = structure(c(18584, 
18584, 18585, 18585, 18585, 18585), format.spss = "DATE11", display_width = 0L, class = "Date"), 
    SignalNumber = structure(c(1, 2, 3, 4, 5, 6), format.spss = "F8.2", display_width = 0L), 
    NegativeAffect = structure(c(1, 2.25, 1.5, 1, 2.25, 1.5), format.spss = "F8.2", display_width = 0L), 
    PositiveAffect = structure(c(4.33333333333333, 2, 2.66666666666667, 
    3.33333333333333, 3, 4), format.spss = "F8.2", display_width = 0L), 
    Date_first = structure(c(18584, 18584, 18584, 18584, 18584, 
    18584), format.spss = "DATE11", display_width = 0L, class = "Date"), 
    ID_day = structure(c(1001, 1001, 1002, 1002, 1002, 1002), format.spss = "F8.2", display_width = 0L)), row.names = c(NA, 
-6L), class = c("tbl_df", "tbl", "data.frame"))

Initially, I wanted to use the autoR() function in psych grouping PositiveAffect and NegativeAffect by study_id.

library(psych)
autoR(data$NegativeAffect, group=data$study_id, lag=1, na.rm=TRUE) #original method which gave error
autoR(data[,c(4, 5)],group=datat$study_id, lag=1, na.rm=TRUE) #suggested method which does run

So, great, the line of code from the suggestion runs. However, I am also interested in grouping with a different variable called ID_day.

I tried to use the suggested method:

autoR(data[,c(4, 5)],group=ema_affect$ID_day, lag=1, na.rm=TRUE) #gives error

I get the same error I initially got when I was writing the syntax with the $ operator: Error in apply(x[1:(n.obs - lag), ], 2, sd, na.rm = na.rm): dim(X) must have a positive length

I'm now not sure if the solution is actually running the function as intended.

As the user mentioned in my previous post, there is little documentation about this which makes it difficult for me to study up on and fix it. The RDocumentation on the package doesn't seem to go into detail about this specific error...but maybe I'm missing something.

Anyone know what I might be doing wrong?

EDIT: I've tried rearranging my dataframe columns and removing any columns I don't need. I ensured that every column that needs to be numeric is. This error is also keeping me from changing the lags if I ever needed to since this would be the group I want to run analyses on for daily level ratings.

1 Answers

Thanks to AcidCatfish. That bug has been fixed and the new release will be on the pmc server tomorrow. (To get the latest version of psych install.packages("psych", repos= "https://personality-project.org/r,type="source")

Related