Please go through the documentation for the wtd.chi.sq() function; it doesn't have any parameters named x and y. Instead the first two parameters are var1 and var2.
Maybe you could try modifying the names of the function parameters and see if that works?