Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: working with a vector and scalars


From   "Austin Nichols" <austinnichols@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: working with a vector and scalars
Date   Sun, 8 Jun 2008 21:00:38 -0400

Cathy L. Antonakos <cathya@umich.edu>
I take it you don't want the reliability reported by -loneway-?  Not
sure what you want from your description... but I don't think that
equation looks right, and I don't have the ref handy.  Can you confirm
that t cancels out?  Is your calculated s equiv to d in your formula?
I don't see where you've tried to calculate something and gotten an
error, but try:

egen N = count(crowdindx), by(placeXhr)
g nr=1/N
mean nr, over(placeXhr)
mat b=e(b)
mat N=b'
loneway crowdindx placeXhr
scalar t = r(sd_b) * r(sd_b)
scalar s = r(sd_w) * r(sd_w)
mat lambda = s*N
mat li lamdba

But if you need to calculate the element-wise reciprocal, it's easier in Mata...

On Sun, Jun 8, 2008 at 8:23 PM, Cathy L. Antonakos <cathya@umich.edu> wrote:
> I am working with scalars and a vector to estimate sample mean reliability
> by group, using a formula from Bryk & Raudenbush (1992) Hierarchical Linear
> Models:
>
> lambda-j = t / [ t / (d /Nj)]
>
> lambda-j is the reliability estimate for group j, t is between-group
> variance, d is within-group variance, and Nj is the group N.
>
> Nj is a vector. The other parameters (t, d) are scalars.
>
> Here's what I tried using -matrix- and -scalar-. The vector comes from a
> collapsed dataset. The scalars come from -loneway- using the original
> (uncollapsed) dataset. I have no trouble producing the vector and scalars,
> but can't figure out how to get them into the same matrix or file together
> so I can calculate the reliability esimates.
>
> Any help will be much appreciated.
>
> Cathy Antonakos
>
> --------------
> . bys placeXhr: egen N = count(crowdindx)
> . preserve
> . collapse (max) N, by(placeXhr)
> . mkmat N
> . levelsof placeXhr, local(l)
> . matrix rownames N = `l' . matrix list N
>
> N[49,1]
>        N
> 2_10    2
> 2_11   81
> 2_12  150
> 2_13  340
> 2_14  138
> 2_15   82
> 2_16  102
> 2_17  119
> 2_18  288
> 2_19  160
>  2_8   48
>  2_9  265
> 3_10  166
> 3_11   71
> 3_12   63
> 3_13   25
> 3_14   53
> 3_15   68
> 3_16   44
> 3_17   61
> 3_18   33
> 3_19   35
>  3_8   36
>  3_9   16
> 6_10   33
> 6_11   69
> 6_12   82
> 6_13   30
> 6_14   87
> 6_15   90
> 6_16   90
> 6_17   92
> 6_18   63
> 6_19   79
>  6_8   86
>  6_9   41
> 9_10   57
> 9_11  135
> 9_12  113
> 9_13   83
> 9_14  152
> 9_15  168
> 9_16  160
> 9_17  151
> 9_18   97
> 9_19  147
>  9_8  216
>  9_9  166
>  9_9  190
>
> . restore
>
> . *create matrices from -loneway- parameter estimates.
> . preserve
> . loneway crowdindx placeXhr
>
>     One-way Analysis of Variance for crowdindx: Crowding Index (wtd. sum)
>
>                                              Number of obs =      5121
>                                                  R-squared =    0.5384
>
>    Source                SS         df      MS            F     Prob > F
> -------------------------------------------------------------------------
> Between placeXhr       682650.69     47    14524.483    125.87     0.0000
> Within placeXhr        585364.53   5073    115.38824
> -------------------------------------------------------------------------
> Total                  1268015.2   5120    247.65922
>
>         Intraclass       Asy.
>         correlation      S.E.       [95% Conf. Interval]
>         ------------------------------------------------
>            0.54152     0.06135       0.42126     0.66177
>
>         Estimated SD of placeXhr effect         11.67412
>         Estimated SD within placeXhr            10.74189
>         Est. reliability of a placeXhr mean      0.99206
>              (evaluated at n=105.73)
>
> . return list
>
> scalars:
>                 r(lb) =  .4212643949911408
>                 r(ub) =  .6617675540515819
>                 r(se) =  .0613539740927638
>               r(sd_w) =  10.74189173110937
>               r(sd_b) =  11.67412402231762
>              r(rho_t) =  .9920556043556278
>                r(rho) =  .5415159745213614
>                  r(N) =  5121
>
> . scalar t = r(sd_b) * r(sd_b) . scalar s = r(sd_w) * r(sd_w)
> . restore
>
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index