Skip to content

Commit

Permalink
Development
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-metherell committed Nov 9, 2023
1 parent d93f447 commit cddb0c3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/src/imputation.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ plot
```

## Binding imputations together
If you have a number of `Mids` objects that were produced in the same way (e.g. through [multithreading](#multithreading)), you can bind them together into a single `Mids` object using the function `bindImputations`.
If you have a number of `Mids` objects that were produced in the same way (e.g. through [multithreading](#multithreading)), you can bind them together into a single `Mids` object using the function `bindImputations`. Note that the log of events might not make sense in the resulting object: it is better to inspect the logs of the individual objects before binding them together.

```@docs
bindImputations
Expand Down
2 changes: 1 addition & 1 deletion docs/src/multithreading.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ imputedData = Vector{Mids}(undef, 10); # Initialise vector of Mids outputs

Threads.@threads for i in 1:10 # Number of parallel runs
# Produces 5 x 10 = 50 imputed datasets in 10 separate Mids objects
imputedData[i] = mice(myData, m = 5, predictorMatrix = myPredictorMatrix, methods = myMethods, threads = false)
imputedData[i] = mice(myData, m = 5, predictorMatrix = myPredictorMatrix, methods = myMethods, threads = false, progressReports = false)
end

imputedData = bindImputations(imputedData) # Binds the separate Mids objects into a single output
Expand Down
10 changes: 6 additions & 4 deletions src/Mice.jl
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ module Mice
)

data = mids1.data
if data != mids2.data
if data !== mids2.data
throw(error(ArgumentError, "Cannot bind these Mids objects: they appear to result from different datasets."))
end

Expand All @@ -362,13 +362,15 @@ module Mice
end

m = mids1.m + mids2.m
loggedEvents = push(mids1.loggedEvents, mids2.loggedEvents)
loggedEvents = vcat(mids1.loggedEvents, mids2.loggedEvents)

# Initialise new imputations object
imputations = Vector{Matrix}(undef, length(mids1.imputations))
# Concatenate imputations
for i in eachindex(imputations)
imputations[i] = hcat(mids1.imputations[i], mids2.imputations[i])
if isassigned(mids1.imputations, i)
imputations[i] = hcat(mids1.imputations[i], mids2.imputations[i])
end
end

# Initialise new mean and variance traces
Expand Down Expand Up @@ -423,7 +425,7 @@ module Mice

"""
bindImputations(
mids...::Mids
mids...
)
Combines any number of `Mids` objects into one `Mids` object. They must all have been
Expand Down

0 comments on commit cddb0c3

Please sign in to comment.