# Nobs() -\> Float or Int?

**URL:** <https://discourse.julialang.org/t/nobs-float-or-int/15485>\
**Category:** Statistics\
**Created:** [September 25, 2018, 9:01pm UTC](https://discourse.julialang.org/t/nobs-float-or-int/15485 "2018-09-25T21:01:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)\
**Post date:** [September 25, 2018, 9:01pm UTC](https://discourse.julialang.org/t/nobs-float-or-int/15485/1 "2018-09-25T21:01:27Z")

</div>

minor question: shouldn’t nobs() return an integer for a GLM lm model?

```julia
julia> y= [1:10;] ; X= hcat( fill(1,10), y.^2, y.^3 );

julia> nobs( GLM.lm(X,y) )
10.0

```

are there cases where this can become a fraction?

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [September 26, 2018, 7:55am UTC](https://discourse.julialang.org/t/nobs-float-or-int/15485/2 "2018-09-26T07:55:50Z")

</div>

> [@iwelch](#):
>
> are there cases where this can become a fraction?

Yes, when non-integer weights are provided. A solution to that would be to parameterize the model on the type of weights, and default to `Int` when there are no weights.

---

<div class="post-metadata">

**Author:** ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)\
**Post date:** [September 26, 2018, 4:21pm UTC](https://discourse.julialang.org/t/nobs-float-or-int/15485/3 "2018-09-26T16:21:49Z")

</div>

thx. Simplicity is better. I would suggest an nobs() function that is truly the number of observations (and always integer) and a wobs() function that is the sum of the weights. should I suggest it as an issue on github?

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [September 27, 2018, 9:36am UTC](https://discourse.julialang.org/t/nobs-float-or-int/15485/4 "2018-09-27T09:36:21Z")

</div>

Feel free to file an issue, but I’m afraid it’s more complex than that. For example, with frequency/replicate weights, the apparent “number of observations” doesn’t have any meaning, it’s just the way the data has been compressed to save space. So it would be misleading to have `nobs` return that.

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [September 27, 2018, 1:14pm UTC](https://discourse.julialang.org/t/nobs-float-or-int/15485/5 "2018-09-27T13:14:18Z")

</div>

I would appreciate an option to return the number of rows used in a regression. It’s useful in regressions with missing values where you want to make sure you are getting the right subset of data each time.

It’s pretty easy to define a function though.

```julia
function unweightednobs(m) nrow(m.mf.df) end

```

---

<div class="post-metadata">

**Author:** ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)\
**Post date:** [September 27, 2018, 4:28pm UTC](https://discourse.julialang.org/t/nobs-float-or-int/15485/6 "2018-09-27T16:28:26Z")

</div>

thx. agreed with everything.

[https://github.com/JuliaStats/GLM.jl/issues/259](https://github.com/JuliaStats/GLM.jl/issues/259)

/iaw
