Skip to content

Real Covariate Design #188

@vladdez

Description

@vladdez
using Distributions

begin
	des = SingleSubjectDesign(;conditions=Dict(:cond => ["car","face"],
										   :cat => ["cat","dog","horse"]
#									:continuous => range(-2,2,8),
#								   :continuousB => range(-2,2,8)
								   ))
cov_des = CovariateDesign(des,120,
						  Dict(:continuousA => Uniform(-1,2),
							   :continuousB => Normal(5,1.2)))
end

	UnfoldSim.@with_kw struct CovariateDesign <: UnfoldSim.AbstractDesign
		design = nothing
		n_trials::Int
		covariates::Dict
	end

begin
	UnfoldSim.size(design::CovariateDesign) = design.n_trials
		
	function UnfoldSim.generate_events(rng::UnfoldSim.AbstractRNG, design::CovariateDesign)
		
		all_evts = []
		for (covariate,dist) in design.covariates
			push!(all_evts,covariate =>rand(rng,dist,design.n_trials))
		end	
		events = UnfoldSim.DataFrame(all_evts)
		if !isnothing(design.design)
			n_rep = design.n_trials ./ size(des)[1]
			try 
				Int(n_rep) 
			catch
				error("design.n_trials need to be divisible by size(design.design)")
			end
			categorical_events = generate_events(deepcopy(rng),RepeatDesign(design.design,n_rep))
			return hcat(categorical_events,events)
		else
		return events#DataFrame(all_evts)
		end
	end
end

generate_events(UnfoldSim.Random.MersenneTwister(), cov_des)
generate_events(des)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions