# Spearman Correlation, How do I find rho?

``````B= df.Crude_Birth_Rate

Employment_df = DataFrame(A=df.Female_Employment,B=df.Crude_Birth_Rate, )corspearman(x=A, y=B) = cor(tiedrank(A), tiedrank(B))
``````

I’m trying to do a Spearman Correlation Test, because I know from my regression test, that the data is polynomial, not linear. But, when I run the test, it just says corspearman, how do I enter the variables from my dataframe, into the test?

I am not aware of a package that implements p-values of correlation tests (this stackoverflow question and answer might be useful though).

If your main question is how to calculate the correlation, just put the vectors into the function:

``````corspearman(df.Female_Employment, df.Crude_Birth_Rate)
``````

Yeah that was a mistake, I just want to know how to find rho.

Ok I entered it the way you did and it worked.

What would I have to do to run a Kendall tests

``````corkendall(df.Female_Employment, df.Crude_Birth_Rate)
``````
```````float` not defined on abstractly-typed arrays; please convert to a more specific type
error(::String) at error.jl:33
float(::Array{Real,1}) at float.jl:894
corkendall(::Array{Real,1}, ::Array{Real,1}) at rankcorr.jl:103
top-level scope at FemLabour.jl:29
``````

I’m thinking I need to change the number type.

What are the types of the dataframe columns? If you type in the name of the DataFrame in the REPL and press enter, the top of each column will be the types.

You can also see the types of the columns by using the describe function, `describe(df)`

Real

It looks like you’re running into trouble with typing from XLSX again - I would therefore again suggest you put your tabluar data in csv format, which will make life a lot easier.

Apart from that you can try `corkendall(Float64.(df.Female_Employment), Float64.(df.Crude_Birth_Rate))`

1 Like

I’d have to get the CSV to work, besides I’m using Excel at the same time, and doing charts on Excel instead of plots.

If it still is not working, can you post some sample data and the code you are using so we can better help you?

Sorry, yes I got it fixed.

“Getting the csv to work” is as easy as doing “Save as” in Excel and changing the file format to csv. That obviously doesn’t preclude you from keeping an xlsx version around if you want to make charts in Excel, although I’d say here’s a great opportunity to learn how to make Plots in Julia 1 Like

True, I probably will learn plots next thing. I already started doing some.

1 Like

Right now I need to export a matrix to Excel. I would like to do this as an XLSX, but a CSV should work too.

You can export it via XLSX, see the docs here.

Alternatively, you can just wrap your Matrix in a `DataFrame` and write it with `CSV.jl`:

``````julia> using CSV, DataFrames

julia> my_matrix = rand(5, 5);

julia> CSV.write("C:/Users/brett/OneDrive/Documents/Soc323/test.csv", my_matrix)
``````

You can of course then open this csv with Excel and save it in XLSX format from within Excel if you need that.

1 Like
``````ERROR: ArgumentError: a 'Array{Real,2}' is not a table; see `?Tables.table` for ways to treat an AbstractMatrix as a table
``````

I tried to look up Tables.table in help, but coludn’t find anything. How do I change this into a usable table?

My apologies, I screwed up my own MWE above: I added `using DataFrames` at the start clearly because I was going to actually use it in the example…

As the error says, a `Matrix` is not a `Table`, so you need to convert it into one - an easy way to do it is to pass it to the `DataFrame` constructor. Replace the second line with:

``````julia> my_matrix = DataFrame(rand(5, 5))
``````