(Didn't I show this at the workshop you attended in June?)
You want to sample the levels of childid and subset the group
accordingly.
samp <- sample(levels(group$childid), 100)
subgroup <- subset(group, childid %in% samp)
You could, if you want, combine these into
subgroup <- subset(group, childid %in% sample(levels(group$childid), 100))
In this method each child has equal probability of being chosen. If
you want the probability of being chosen to be proportional to the
number of observations on the child then use
subgroup <- subset(group, childid %in% sample(group$childid, 100))
There is a small chance that your sample will end up with fewer than
100 children but you could work around that by sampling more than 100
and taking the first 100 in the sample.
"Harold Doran" <hdoran at nasdc.org> writes:
> I have a data set with over 7000 students with about 4 observations
> over time per student. I want to examine the within-group fits of a
> random sample of this group as it takes forever to compute and draw
> all 7000 regressions.
>
> Here is the code I have used so far.
>
> >group<-groupedData(math~year|childid, data=scores)
> >group.list<-lmList(group)
> >plot(augPred(group.list))
>
> How might I select a random sample of say 100 students so that I can
visually examine their trajectories?
>
> Thank you
>
> ------
> Harold C. Doran
> Director of Research and Evaluation
> New American Schools
> 675 N. Washington Street, Suite 220
> Alexandria, Virginia 22314
> 703.647.1628
> <http://www.edperform.net/>
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
--
Douglas Bates bates at stat.wisc.edu
Statistics Department 608/262-2598
University of Wisconsin - Madison http://www.stat.wisc.edu/~bates/