BookmarkSubscribeRSS Feed
davidsmarch1
Fluorite | Level 6

Hello all and thanks ahead of time for any help. 

 

I have a dataset with 117 subjects containing a variable (yt) that changes over time. Each trial can last anywhere from 20-90 samples (rows) depending on how long the subject takes to respond. The data looks like this:

 

subjectracetargetdistractortimeXYyt
1asiancalmdang0.020.000980.05097-0.00112
1asiancalmdang0.040.001920.05237-0.00221
1asiancalmdang0.060.002550.05625-0.00292
1asiancalmdang0.080.003790.06979-0.00433
1asiancalmdang0.10.005250.08874-0.00601
1asiancalmdang0.120.005980.10097-0.00688
1asiancalmdang0.140.006040.11558-0.00697
1asiancalmdang0.160.005730.13953-0.00673
1asiancalmdang0.180.005670.16903-0.00701
1asiancalmdang0.20.006620.19264-0.00854
1asiancalmdang0.220.007720.23229-0.01042
1asiancalmdang0.240.008490.27722-0.01157
1asiancalmdang0.260.0090.30805-0.0122

 

You can see that the yt changes over time. There is also 3 races, 2 targets, and 2 distractors that I'll end up doing the below for each combination. 

 

I need to know at which times does each yt differs from 0 so I'm running a glm regressing each yt against 0 at each time point and using the ods output to save the parameter estimate. 

 

ods output  ParameterEstimates = acd (keep = time Estimate 
StdErr tValue Probt Cond rename=(Dependent=Cond);
proc glm;
model yt = / solution ss3;
by time; run;

The parameters estimates dataset now contains 90 rows of data that look like the below (I cut it at 6):


timeCond  EstimateStdErrtValueProbt
0.02yt-0.0001648500.00003056-5.39<.0001
0.04yt-0.0002268940.00010429-2.180.0316
0.06yt-0.0003194270.00019644-1.630.1066
0.08yt-0.0004885310.00035148-1.390.1672
0.10yt-0.0007399010.00059421-1.250.2156
0.12yt-0.0010511320.00081990-1.280.2024

 

What I want to do is bootstrap subsamples of participants from the original dataset where I pull out random sample sizes of the original set (say, 25%, 50%, 75% of participants) 10000 times and run the same regression and output another ParameterEstimates table. Eventually I want to set together all the output tables so that I can look at the distribution of Probt at each time across the bootstrapped samples. I'm not sure, but I may need a variable in each dataset to identify which run this 90 rows belongs to. I hope that makes sense. I've attached a sample of the dataset here with 20 participants.  Please advise! 

 

 

4 REPLIES 4
ballardw
Super User

I can't tell quite whether any of your variables are involved in grouping for your selection criteria or not. I am going to assume so as that is the slightly more complex version for selecting sample.

 

Your " random sample sizes of the original set (say, 25%, 50%, 75% of participants) 10000 times" can be accomplished with Proc Surveyselect and the Reps (replicates) to generate multiple samples using similar options.

Here is an example using the SASHELP.Class data set as an example. It is small enough that you can compare the result to the basic set relatively easily.

 

/* sort data so we can use Strat
   based on sex later
*/
proc sort data=sashelp.class
   out=work.class;
   by sex;
run;

proc surveyselect data=work.class
    out=work.sample
    samprate=.25  reps=10;
    strata sex;
run;

The Samprate in the example selects a 25% sample from each level of the Strata variable Sex. The Reps=10 says to create 10 samples. There will be a variable added to indicate which replicate a group of records comes from.

If you wanted to run a separate analysis for each level of Sex and 10 separate regressions you would use a

By Sex Replicate;

in the regression.

 

If you don't need strata, which could be several variables but the input needs to be sorted by all, then drop the strata statement.

I suspect that Race, Target and Distractor would be CLASS variables and used in your model to get comparisons between the levels (or combinations).

 

I would suggest, if you intend to combine any of these sets to make sure there is a variable indicating the source. The indsname option at the time you combine sets can make this easy. Example

data junk;
   set sashelp.class
       sashelp.cars (obs=20)
       indsname=ds
   ;
   source=ds;
run;

Not a particularly useful set but the object is to show there is a variable added to the data named Source and has the name of the data set each record came from.

 

 

davidsmarch1
Fluorite | Level 6

The subject variable is the grouping criteria. There are 117 subjects, and each of their 6 trials (cond) is many rows long. I had originally tried this method before posting, but it doesn't seem to work as you describe. When I use the code:

 

				proc surveyselect data=gomp_bar_reorder_manyrows out=bootsample
				samprate = .25 rep = 10;
				strata subject;
				run;

What I end up with is 25% of each subject's rows of data randomly pulled into a replicate. That is, the original condition which went time .02, .04, .06, .08... now goes time .04, .12, .14, .20 as it didn't keep the subject together, it simply pulled out 25% of their data. I need to pull entire subjects, not samples within each subject. I want to take say, 25% of participants, not 25% of a participant's data. 

 

 

 

 

 

ballardw
Super User

@davidsmarch1 wrote:

The subject variable is the grouping criteria. There are 117 subjects, and each of their 6 trials (cond) is many rows long. I had originally tried this method before posting, but it doesn't seem to work as you describe. When I use the code:

 

				proc surveyselect data=gomp_bar_reorder_manyrows out=bootsample
				samprate = .25 rep = 10;
				strata subject;
				run;

What I end up with is 25% of each subject's rows of data randomly pulled into a replicate. That is, the original condition which went time .02, .04, .06, .08... now goes time .04, .12, .14, .20 as it didn't keep the subject together, it simply pulled out 25% of their data. I need to pull entire subjects, not samples within each subject. I want to take say, 25% of participants, not 25% of a participant's data. 

 


You did not describe very clearly what you wanted in the first place.. Do you want subjects selected? That would mean make a data set with just the subjects, one record per, select, and then join the selections back to the observation data.

 

An example of joining selected data back to your original:

 

Proc sql;
   create table want as
   select b.* , a.replicate 
   from selected as a
        left join
        full_data as b
        on a.id =b.id
   ;
quit;

This assumes the survey select output data set was created from a set with one record per Id.

davidsmarch1
Fluorite | Level 6

I thought I described it pretty clearly. Each subject has 6 trials. Each trial has up to 90 rows of data, one row for each time point (see the original post and sample data).

 

I want to sample subjects, not rows within subjects. I need to keep the entirety of a trial together in the sampling. I can't have it taking 25% of a subjects trials, but I need 25% of the subjects. And each subject's entire length of trials needs to be retained. It's not sufficient to simply reduce each subject to one row and sample from that, which is I think what you are proposing. I need to keep the entire trial coherent and sample participants, not rows within a participant. 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1787 views
  • 0 likes
  • 2 in conversation