Note that there are some explanatory texts on larger screens.

plurals
  1. POBetween/within standard deviations in R
    primarykey
    data
    text
    <p>When working on a hierarchical/multilevel/panel dataset, it may be very useful to adopt a package which returns the within- and between-group standard deviations of the available variables. </p> <p>This is something that with the following data in <code>Stata</code> can be easily done through the command</p> <pre><code>xtsum, i(momid) </code></pre> <p>I made a research, but I cannot find any <code>R</code> package which can do that.. </p> <p><strong>edit:</strong></p> <p>Just to fix ideas, an example of hierarchical dataset could be this:</p> <pre><code>son_id mom_id hispanic mom_smoke son_birthweigth 1 1 1 1 3950 2 1 1 0 3890 3 1 1 0 3990 1 2 0 1 4200 2 2 0 1 4120 1 3 0 0 2975 2 3 0 1 2980 </code></pre> <p>The "multilevel" structure is given by the fact that each mother (higher level) has two or more sons (lower level). Hence, each mother defines a group of observations.</p> <p>Accordingly, each dataset variable can vary either between and within mothers or only between mothers. <code>birtweigth</code> varies among mothers, but also within the same mother. Instead, <code>hispanic</code> is fixed for the same mother.</p> <p>For example, the within-mother variance of <code>son_birthweigth</code> is:</p> <pre><code># mom1 means bwt_mean1 &lt;- (3950+3890+3990)/3 bwt_mean2 &lt;- (4200+4120)/2 bwt_mean3 &lt;- (2975+2980)/2 # Within-mother variance for birthweigth ((3950-bwt_mean1)^2 + (3890-bwt_mean1)^2 + (3990-bwt_mean1)^2 + (4200-bwt_mean2)^2 + (4120-bwt_mean2)^2 + (2975-bwt_mean3)^2 + (2980-bwt_mean3)^2)/(7-1) </code></pre> <p>While the between-mother variance is:</p> <pre><code># overall mean of birthweigth: # mean &lt;- sum(data$son_birthweigth)/length(data$son_birthweigth) mean &lt;- (3950+3890+3990+4200+4120+2975+2980)/7 # within variance: ((bwt_mean1-mean)^2 + (bwt_mean2-mean)^2 + (bwt_mean3-mean)^2)/(3-1) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload