Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan A. Knowles committed Apr 23, 2020
1 parent 7f88644 commit 6598252
Show file tree
Hide file tree
Showing 8 changed files with 4,565 additions and 28 deletions.
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# EpistemicNetworkAnalysis.jl

A port of [rENA](https://rdrr.io/cran/rENA/), by [http://www.epistemicnetwork.org/](http://www.epistemicnetwork.org/).
A port of [rENA](https://rdrr.io/cran/rENA/) version 0.2.0.1 into native Julia.

Original R package by [http://www.epistemicnetwork.org/](http://www.epistemicnetwork.org/).

IN DEVELOPMENT
3,825 changes: 3,825 additions & 0 deletions data/RS.data.csv

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/ENADisplay.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# TODO text representation
# TODO graphical representation, default
# TODO graphical, with options
59 changes: 33 additions & 26 deletions src/ENAModel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ struct ENAModel
groupVar::Union{Nothing,Symbol}
treatmentGroup::Any # if groupVar == treatmentGroup, then 1
controlGroup::Any # if groupVar == treatmentGroup, then 0; if neither, leave it out
confounds::Array{Symbol,1}
confounds::Union{Nothing,Array{Symbol,1}}
metadata::Array{Symbol,1}
# plots::Dict{String,Scene} # dropping this in favor of doing it with display/plot methods, for now maybe
rotateBy::Function
Expand All @@ -17,9 +17,9 @@ struct ENAModel
codeModel::DataFrame # all the code-level data we compute
end

function ENAModel(data::DataFrame, codes::Array{Symbol,1}, conversations::Array{Symbol,1}, unitVar::Symbol,
metadata::Array{Symbol,1}=Symbol[], windowSize::Int=4, confounds::Union{Array{Symbol,1},Nothing}=nothing,
groupVar::Union{Symbol,Nothing}=nothing, treatmentGroup::Any=nothing, controlGroup::Any=nothing,
function ENAModel(data::DataFrame, codes::Array{Symbol,1}, conversations::Array{Symbol,1}, unitVar::Symbol;
metadata::Array{Symbol,1}=Symbol[], windowSize::Int=4, confounds::Union{Nothing,Array{Symbol,1}}=nothing,
groupVar::Union{Nothing,Symbol}=nothing, treatmentGroup::Any=nothing, controlGroup::Any=nothing,
rotateBy::Function=svd_rotation!)

# Preparing model structures
Expand All @@ -30,23 +30,27 @@ function ENAModel(data::DataFrame, codes::Array{Symbol,1}, conversations::Array{
if i < j)

## Unit model
unitModel = DataFrame()
if !isnothing(groupVar) && !isnothing(confounds)
unitModel = by(data, unitVar,
[m=>first for m in metadata]...,
groupVar=>first,
[c=>first for c in confounds]...)
elseif !isnothing(groupVar)
unitModel = by(data, unitVar,
[m=>first for m in metadata]...,
groupVar=>first)
elseif !isnothing(confounds)
unitModel = by(data, unitVar,
[m=>first for m in metadata]...,
[c=>first for c in confounds]...)
unitModel = by(data, unitVar, first)
if !isempty(metadata)
if !isnothing(groupVar) && !isnothing(confounds)
unitModel = unitModel[:, [unitVar, metadata..., groupVar, confounds...]]
elseif !isnothing(groupVar)
unitModel = unitModel[:, [unitVar, metadata..., groupVar]]
elseif !isnothing(confounds)
unitModel = unitModel[:, [unitVar, metadata..., confounds...]]
else
unitModel = unitModel[:, [unitVar, metadata...]]
end
else
unitModel = by(data, unitVar,
[m=>first for m in metadata]...)
if !isnothing(groupVar) && !isnothing(confounds)
unitModel = unitModel[:, [unitVar, groupVar, confounds...]]
elseif !isnothing(groupVar)
unitModel = unitModel[:, [unitVar, groupVar]]
elseif !isnothing(confounds)
unitModel = unitModel[:, [unitVar, confounds...]]
else
unitModel = unitModel[:, [unitVar]]
end
end

unitModel = hcat(unitModel, DataFrame(Dict(r => Real[0 for i in 1:nrow(unitModel)]
Expand All @@ -58,7 +62,7 @@ function ENAModel(data::DataFrame, codes::Array{Symbol,1}, conversations::Array{
fit_y=Real[0 for i in 1:nrow(unitModel)]))

## Network model
networkModel = DataFrame(relationship=keys(relationships),
networkModel = DataFrame(relationship=collect(keys(relationships)),
thickness=Real[0 for r in relationships], # how thick to make the line
weight_x=Real[0 for r in relationships], # the weight I contribute to dim_x's
weight_y=Real[0 for r in relationships]) # the weight I contribute to dim_y's
Expand Down Expand Up @@ -135,26 +139,29 @@ function ENAModel(data::DataFrame, codes::Array{Symbol,1}, conversations::Array{
config[:confounds] = confounds
end

rotateBy(networkModel, unitModel, config)
rotateBy(networkModel, unitModel, codes, relationships, config)

# Layout step
# TODO compute dim_x and dim_y of the unit-level model
# TODO fit the x and y positions of the unit-level model and code-level model
# TODO compute the dot sizes for the code-level model

return ENAModel(data, codes, conversations, unitVar, windowSize, groupVar, treatmentGroup, controlGroup,
confounds, metadata, rotateBy, collect(keys(relationships)), unitModel, networkModel, codeModel)
end

function svd_rotation!(networkModel, unitModel, config)
function svd_rotation!(networkModel, unitModel, codes, relationships, config)
# TODO compute the thickness and weights of the network-level model
if haskey(config, :confounds)
if haskey(config, :confounds) # TODO do this with type annotations, when nothing do x, when something do such and such
# TODO use AC-PCA when confounds present
else
# TODO use PCA otherwise
end
end

function means_rotation!(networkModel, unitModel, config)
function means_rotation!(networkModel, unitModel, codes, relationships, config)
# TODO compute the thickness and weights of the network-level model
if haskey(config, :confounds) && haskey(config, :groupVar)
if haskey(config, :confounds) && haskey(config, :groupVar) # TODO do this with type annotations? when nothing do x, when something do such and such?
# TODO use moderated MR1 when confounds present
elseif haskey(config, :groupVar)
# TODO use default MR1 otherwise (this can probably be generalized into the above)
Expand Down
6 changes: 5 additions & 1 deletion src/EpistemicNetworkAnalysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ using DataFrames
using Statistics
using LinearAlgebra
using GLM
using CSV
# TODO using Lasso
using Makie

# TODO sample dataset
include("./ENAModel.jl")
include("./RSData.jl")
include("./examples.jl")

temp_example()

end # module
4 changes: 4 additions & 0 deletions src/RSData.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function ena_dataset(name::String)
filename = joinpath(dirname(@__FILE__), "..", "data", "$(name).csv")
return CSV.read(filename)
end
18 changes: 18 additions & 0 deletions src/examples.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# TODO svd
# TODO ac-svd
# TODO mr1
# TODO mmr1
# TODO different plot options

function temp_example()
RSdata = ena_dataset("RS.data")
print(first(RSdata, 6))

codes = [:Technical_Constraints, :Performance_Parameters, :Client_and_Consultant_Requests, :Design_Reasoning, :Collaboration]
conversations = [:GroupName, :ActivityNumber]
unitVar = :UserName

myENA = ENAModel(RSdata, codes, conversations, unitVar)
print(myENA.unitModel)
print(myENA.networkModel)
end

0 comments on commit 6598252

Please sign in to comment.