Entering xlsx columns into HypothosisTests

Alas, I can’t find a way to add a file as an attachment, since I,m adding a foreign file, it’s a real pain, unless it created a DataFrame code line, that I can access. When I add the line you provided, I don’t get the matching error, now my error is

ERROR: MethodError: no method matching ChisqTest(::Array{Any,1})

I think that means it’s looking at all the values for Q1, but not all the data, that I want to compare actual to expected. Should I be using one of the packages you mentioned? I’m think I have the indexers mostly understood, but I’m not sure how to include all the rows in a column.

People usually use gist: Discover gists · GitHub at least csv file works.

1 Like

I know your problem. XLSX.jl returns arrays of type Any and ChisqTest requires arrays of type <:Real. In your dataframe, do

julia> for name in names(df)
       df[!, name] = identity.(df[:, name])
end

This will ensure that the types are no longer Any.

Sorry this has been such a frustrating experience, hopefully we can work on some PRs to XLSX.jl to make this easier.

I’m not finding it in the documentation, what is name? What is ! ?

Here’s what an MWE would look like:

using XLSX, DataFrames, HypothesisTests

# Set up - create a dummy data set and write out to xlsx
out = DataFrame(Q1 = [1,2,3,4,5],
                Q2 = [1.0, 2.0, 3.0, 4.0, 5.0])

XLSX.writetable("df.xlsx", collect(eachcol(out)), names(out))
    
# Use XLSX to read data into DataFrames
df = DataFrame(XLSX.readtable("df.xlsx", "Sheet1")...)

# Perform ChisqTest
ChisqTest(identity.(df.Q1))

The DataFrames indexing documentation is here, which explains amongst other things the usage of ! as a row indexer.

name in the above is just a temporary variable used in the loop to iterate over the column names (which are contained in names(df)). If this isn’t clear to you you might benefit from a more basic introduction to programming in Julia - the official manual is a good starting point, as is Ben Lauwens’ Think Julia

1 Like

Thanks, for letting me know about setting up a dummy table, that will help in the futre.

1 Like

For some reason it didn’t work, then I rentered it, and it worked just fine. So, Cool!