Search code examples
rstatisticsrobust

Error in Yuen test code


I am trying to perform a Yuen's robust test on R but I am having an issue with the following error code:

Error in formula.default(object, env = baseenv()) : invalid formula

I have used the following packages and code:

library(WRS2)
library(car)
library(akima)
library(MASS)
library(robustbase)
library(rrcov)
library(scatterplot3d)
library(trimcluster)
library(parallel)
PremS <- c(0.06,    0.02,   0.04,   0.03,   0.03,   0.01,   0.04,   0.02,   0.07,   0.05,   0,  0.11,   0.04,   0.02,   0.03,   0.03,   0.04,   0.01,   0.06,   0.03,   0.02,   0.03,   0.03,   0.02,   0.02,   0.03,   0.02,   0.02,   0.04,   0.03,   0.03,   0.03,   0.02,   0.04,   0.06,   0.03)
PremR <- c(0.04,    0.02,   0.05,   0.02,   0.04,   0.02,   0.01,   0.01,   0.02,   0.04,   0,  0.02,   0.01,   0.01,   0.01,   0.03,   0.02,   0.03,   0.02,   0.02,   0.02,   0.01,   0.01,   0.04,   0.01,   0.03,   0.03,   0.03,   0.02)
yuen(PremR,PremS,tr=0.2)

If anyone is able to help, I would be extremely grateful!


Solution

  • First of all, in order to call function yuen, you only need to load package WRS2. The others are a bit too much.

    Now for the question. You need to call the function with an object of class formula. Like this:

    yuen(PremR ~ PremS,tr=0.2)
    Error in model.frame.default(formula) : 
      variable lengths differ (found for 'PremS')
    

    Now the error thrown is different. So I've checked the lengths of the two variables.

    length(PremS)
    [1] 36
    length(PremR)
    [1] 29
    

    You now need to correct your data.