Please can someone post a really simple logistic regression implemented in Mamba, i.e. something like this but that actually works. I have been unable to figure it out and have not found another reference that might help. Thanks.
using Distributed, Mamba, LinearAlgebra
@everywhere using Mamba
using DataFrames
dat = Dict{Symbol, Any}(
:y => [1 0 1 1 0 0 0 0 1 0 1 0 1 1 0 0 0 0 0 1 1 1 1 1 0 1 1 1 0 1 1 0 0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0 1 1],
:trt => [0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1],
:remote => [1 1 0 1 1 1 0 1 1 1 1 1 1 1 1 1 0 0 0 1 0 0 1 0 0 0 0 0 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 0 0 0 1 1 0 0]
)
dat[:N] = length(dat[:y])
dat[:xmat] = [ones(dat[:N]) transpose(dat[:trt]) transpose(dat[:remote])]
inits = [
Dict{Symbol, Any}(
:y => dat[:y],
:b => rand(Normal(0, 1), size(dat[:xmat], 2))
)
for i in 1:3 # 3 chains
]
scheme1 = [NUTS(:b)]
model = Model(
y = Stochastic(1,
(p, N) -> UnivariateDistribution[(
Bernoulli(p[i])) for i in 1:N],
false
),
p = Logical(1,
(xmat, b) -> invlogit.(xmat * b),
false
),
b = Stochastic(1,
() -> MvNormal(3, sqrt(100))
)
)
setsamplers!(model, scheme1)
sim1 = mcmc(model, dat, inits,
1000,
burnin=250,
thin=2,
chains=3)
Aside - the above gives:
MethodError: no method matching Array{Float64,1}(::Array{Int64,2})
You might have used a 2d row vector where a 1d column vector was required.
Note the difference between 1d column vector [1,2,3] and 2d row vector [1 2 3].
You can convert to a column vector with the vec() function.
Closest candidates are:
Array{Float64,1}(::AbstractArray{S,N}) where {T, N, S} at array.jl:497
Array{Float64,1}() where T at boot.jl:413
Array{Float64,1}(!Matched::UndefInitializer, !Matched::Int64) where T at boot.jl:394
...
convert(::Type{Array{Float64,1}}, ::Array{Int64,2}) at array.jl:489
setinits!(::ArrayStochastic{1}, ::Model, ::Array{Int64,2}) at dependent.jl:168
setinits!(::Model, ::Dict{Symbol,Any}) at initialization.jl:11
setinits!(::Model, ::Array{Dict{Symbol,Any},1}) at initialization.jl:24
#mcmc#23(::Int64, ::Int64, ::Int64, ::Bool, ::Function, ::Model, ::Dict{Symbol,Any}, ::Array{Dict{Symbol,Any},1}, ::Int64) at mcmc.jl:30
(::getfield(Mamba, Symbol("#kw##mcmc")))(::NamedTuple{(:burnin, :thin, :chains),Tuple{Int64,Int64,Int64}}, ::typeof(mcmc), ::Model, ::Dict{Symbol,Any}, ::Array{Dict{Symbol,Any},1}, ::Int64) at none:0
top-level scope at none:0
include_string(::Module, ::String, ::String) at loading.jl:1005
include_string(::Module, ::String, ::String, ::Int64) at eval.jl:30
(::getfield(Atom, Symbol("##114#119")){String,Int64,String})() at eval.jl:94
withpath(::getfield(Atom, Symbol("##114#119")){String,Int64,String}, ::String) at utils.jl:30
withpath at eval.jl:46 [inlined]
#113 at eval.jl:93 [inlined]
with_logstate(::getfield(Atom, Symbol("##113#118")){String,Int64,String}, ::Base.CoreLogging.LogState) at logging.jl:397
with_logger at logging.jl:493 [inlined]
#112 at eval.jl:92 [inlined]
hideprompt(::getfield(Atom, Symbol("##112#117")){String,Int64,String}) at repl.jl:85
macro expansion at eval.jl:91 [inlined]
(::getfield(Atom, Symbol("##111#116")))(::Dict{String,Any}) at eval.jl:86
handlemsg(::Dict{String,Any}, ::Dict{String,Any}) at comm.jl:164
(::getfield(Atom, Symbol("##19#21")){Array{Any,1}})() at task.jl:259