Issues implementing Copula regression using copula and Turing

It would help if you show us the error that pops out.

On my machine, after some massaging of your code, the error seems to be that OrderedLogisitc does not have a CDF, which is necessary for the copula object to provide a pdf (and therefore it wont work).

Also, the in this version, the Y2[i] ~ OrderedLogistic(Y2st[i]+μ2[i],cutpoints) line does nothing since it is not used later, right ? So you might just remove it.

Moreover, you may change

    # Regression parameters
    μ1 = zeros(typeof(θ₁), n)
    μ2 = zeros(typeof(θ₂), n)
     ρ = zeros(typeof(θ), n)
     Y2st ~ filldist(Logistic(0, 1.), n)


    # Implement  Shrinkage Priors
    for i in 1:n
        μ1[i] = θ₁ .+ sum(X[i,:].* β1)
        μ2[i] = θ₂ .+ sum(X[i,:].* β2)
        ρ[i] = exp(θ .+ sum(X[i,:].* β))
        Y2[i] ~ OrderedLogistic(Y2st[i]+μ2[i],cutpoints)

        #Now the copula is between Y1 (observed) and Y2st (latent)
        Turing.Turing.@addlogprob! loglikelihood(SklarDist(SurvivalCopula(ClaytonCopula(2,ρ[i]),(1,2)), (Normal(μ1[i], 1.), Logistic(μ2[i],1.))), [Y1[i],Y2st[i]+μ2[i]] )

    end

to simply

    # Regression parameters
    # nothing here.


    # Implement  Shrinkage Priors
    for i in 1:n
        μ1i = θ₁ .+ sum(X[i,:].* β1)
        μ2i = θ₂ .+ sum(X[i,:].* β2)
        ρi = exp(θ .+ sum(X[i,:].* β))

        #Now the copula is between Y1 (observed) and Y2st (latent)
        Turing.Turing.@addlogprob! loglikelihood(SklarDist(SurvivalCopula(ClaytonCopula(2,ρi),(1,2)), (Normal(μ1i, 1.), Logistic(μ2i,1.))), [Y1[i],Y2st[i]+μ2[i]] )

    end

Removing useless vectors will probably make your function a bit faster.

Here is the error message I get. It seems confusing to me

ERROR: TaskFailedException

    nested task error: TaskFailedException
    
        nested task error: MethodError: no method matching loglikelihood(::OrderedLogistic{Float64, Vector{Float64}}, ::CategoricalValue{Int64, UInt32})
        Closest candidates are:
          loglikelihood(!Matched::Union{StatsModels.TableRegressionModel, StatsModels.TableStatisticalModel}, ::Any...; kwargs...) at ~/.julia/packages/StatsModels/fK0P3/src/statsmodel.jl:28
          loglikelihood(!Matched::DynamicPPL.Model, ::Any) at ~/.julia/packages/DynamicPPL/xKo8W/src/simple_varinfo.jl:647
          loglikelihood(::UnivariateDistribution, !Matched::Real) at ~/.julia/packages/Distributions/gggmX/src/univariates.jl:329
          ...


Y2[i] ~ OrderedLogistic(Y2st[i]+μ2[i],cutpoints)

I think that is the contribution of the ordinal categorical data to the likelihood, right?
Otherwise it looks Ycat has not part in the likelihood.

I think I understand it now. I needed to convert Ycat to integer

convert.(Int,Ycat)

does the trick. but @lrnv this takes too long

Iterations        = 1001:1:3000
Number of chains  = 3
Samples per chain = 2000
Wall duration     = 18177.01 seconds
Compute duration  = 18174.29 seconds

Indeed that is a lot of time. How does it compare to the same thing without the copula (say with a gaussian noise with correlation rho instead of the Clayton copula) ? So that we can see if the time is eaten up by the copula code or by Turing.

Also you may have a look at Turing performance tips (google it) to check if your model is type stable, that might be the issue.