I have a dataframe. Call it "data" for simplicity.
structure(list(study_id = structure(c(001, 001, 002, 002,
003, 003), 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, 1, 2, 1, 2), format.spss = "F8.2", display_width = 0L),
Negative = structure(c(1, 3.3, 1.5, 4, NA, 1.5), format.spss = "F8.2", display_width = 0L),
Positive = structure(c(4.33333333333333, NA, 2.66666666666667, NA, 3, 4), format.spss = "F8.2", display_width = 0L)), row.names = c(NA,
-6L), class = c("tbl_df", "tbl", "data.frame"))
As you can see, there are repeated study_id's with observations at different sessions. Some observations have NA in either only Positive or Negative and some have NA in both.
I'm trying to use the psych package to run an autocorrelation on my full data:
mssd(data$Negative,group=data$study_id, lag = 1,na.rm=TRUE)
rmssd(data$Negative,group=data$study_id, lag=1, na.rm=TRUE)
autoR(data$Negative,group=data$study_id,lag=1,na.rm=TRUE, use="pairewise")
mssd() and rmssd() work on my full data as expected. Running autoR() gets me the following error: Error in apply(x[1:(n.obs - lag), ], 2, sd, na.rm = na.rm) :
dim(X) must have a positive length
Not sure what's going on here. My full dataset has many more data observations (into the thousands). This example I posted is working the same way as my code, however.
Is it because of the standing NA's? If that's the case, shouldn't the na.rm argument remove them? Besides, when I used na.omit() on my data I still got this error. Can't seem to find an answer specific to the autoR function.