# Parameter Estimation using Least Squares with missing data

**URL:** https://discourse.julialang.org/t/parameter-estimation-using-least-squares-with-missing-data/80797
**Category:** Modelling & Simulations
**Tags:** ode
**Created:** [May 10, 2022, 9:27am UTC](https://discourse.julialang.org/t/parameter-estimation-using-least-squares-with-missing-data/80797 "2022-05-10T09:27:16Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![BinaryBot](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/binarybot/32/45258_2.png) [@BinaryBot](https://discourse.julialang.org/u/BinaryBot)
#### Post date: [May 10, 2022, 9:27am UTC](https://discourse.julialang.org/t/parameter-estimation-using-least-squares-with-missing-data/80797/1 "2022-05-10T09:27:16Z")

</div>

I am trying to estimate 4 parameters for an ode that outputs as solution 4 values at any given time point. I have actual data for 2 of those values. I would like to preform parameter estimation using the available incomplete data. I have implemented it on Turing but would also like to use Least Squares for comparison, but I always get “Dimension Inconsistency” errors because the actual data is 2x120 long and the solution from the ode problem is 4x120.

So is there a way to use Least Sqaures with missing data or is there a way I can get the ODEProblem to only return the solution of the 2 values that I actually need?

---

<div class="post-metadata">

### Author: ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)
#### Post date: [May 10, 2022, 9:32am UTC](https://discourse.julialang.org/t/parameter-estimation-using-least-squares-with-missing-data/80797/2 "2022-05-10T09:32:05Z")

</div>

Check out this example  
[https://diffeqflux.sciml.ai/dev/examples/optimization\_ode/](https://diffeqflux.sciml.ai/dev/examples/optimization_ode/)

You can modify the loss function

```julia
function loss(p)
  sol = solve(prob, Tsit5(), p=p, saveat = tsteps)
  loss = sum(abs2, sol.-1)
  return loss, sol
end

```

to calculate the distance between the states you have data for and the data.

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [May 10, 2022, 12:21pm UTC](https://discourse.julialang.org/t/parameter-estimation-using-least-squares-with-missing-data/80797/3 "2022-05-10T12:21:36Z")

</div>

Use `save_idxs` or just index to match your dataset.
