- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I have a CSV file containing 100 samples a 10 observations each. How do I perform logistic regression on each individual sample from the one csv-file? How do I extract the values I'm interested in to a vector, such as estimatates and p-values?
proc logistic data = WORK.IMPORT;
class x y;
model y = x;
run;
Here is an extract from the CSV-file:
"","num","y","x"
"1",1,1,0
"2",1,1,1
"3",1,1,1
"4",1,1,1
"5",1,1,0
"6",1,1,0
"7",1,1,1
"8",1,1,1
"9",1,1,1
"10",1,1,1
"11",1,1,1
"12",1,1,1
"13",1,1,0
"14",1,0,0
"15",1,1,0
"16",1,1,0
"17",1,1,0
"18",1,1,1
"19",1,1,1
"20",1,1,0
"21",1,0,0
"22",1,1,1
"23",1,0,0
"24",1,1,1
"25",1,1,1
"26",1,1,1
"27",1,1,0
"28",1,1,1
"29",1,0,0
"30",1,1,0
"31",1,1,1
"32",1,1,0
"33",1,1,1
"34",1,1,0
"35",1,0,0
"36",1,1,0
"37",1,1,0
"38",1,0,1
"39",1,1,1
"40",1,1,1
"41",1,1,0
Grateful for all the help I can get!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What does the ods trace show in the log, is the output name called ParameterEstimates, if so the syntax would be:
ods output ParameterEstimates=estim;
This will create a dataset in work called estim, with the parameter estimates.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What variable indicates which sample the observation belongs to? Not sure this is the answer you are looking for, but I think you want to use the by statement in your PROC LOGISTIC as described here
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@gretaolsson wrote:
Hello,
I have a CSV file containing 100 samples a 10 observations each. How do I perform logistic regression on each individual sample from the one csv-file? How do I extract the values I'm interested in to a vector, such as estimatates and p-values?
proc logistic data = WORK.IMPORT;
class x y;
model y = x;
run;
Here is an extract from the CSV-file:
"","num","y","x"
"1",1,1,0
"2",1,1,1
"3",1,1,1
"4",1,1,1
"5",1,1,0
"6",1,1,0
"7",1,1,1
"8",1,1,1
"9",1,1,1
"10",1,1,1
"11",1,1,1
"12",1,1,1
"13",1,1,0
Grateful for all the help I can get!
You haven't told us what "an individual sample" is.
Also, it appears that both x and y are binary 0/1 variables in which case a logistic regression isn't appropriate, something like a contingency table might be a better choice.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Not sure on the specifics of logistic, but as a general rule in SAS, when you want to do a datastep or a procedure over a certain group, you would use a by statement. So maybe something along the lines of:
proc logistic data=work.import; by sampleid; class x y; model y = x; run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
How does SAS know how many observations it is in each sample?
This did not work for me ....
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This is an outstanding question from @PaigeMiller and @PeterClemmensen which you haven't answered yet. You have not told us the full picture, what is sample - its not shown in any of the post? My code is an example of what you would do if you have a variable for it, if you don't how do you know what sample is?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Okay, I did not really catch any question, sorry.
I have a CSV file containing 100 samples.
Each sample consists of 10 observations. (So overall I have 1000 observations in one file.)
I now want to let SAS read the CSV file and perform logistic regression on the first sample, which is observation "1" to "10" in the CSV-file, then I want SAS to perform logistic regression on the second sample, which is observation "11" to "20" in the CSV-file, and so on and on.
Above I have sent an excerpt on how the data looks in the CSV file. "1" - "10" is the first sample,
"11" - "20" is the second sample, ...., "91" - "100" is the tenth sample and so on up to the hundred sample.
If you have any more questions that you need answered, please let me know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Right, so your steps are:
1) read in the data - you should already have this.
2) Assign sample id to blocks of 10 records:
data want; set have; sampleid=ceil(_n_/10); /* Assign sampleid as record blocks of 10 */ run;
3) Run logistic with by group:
proc logistic data=want; by sampleid; class x y; model y = x; run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
This was really helpful, thankyou!
I have some questions, I think Im missing something obvious.
Now I have the following code:
PROC IMPORT OUT = filename FILE = "/folders/myshortcuts/sf_myfolder/filename.csv" DBMS = CSV REPLACE; RUN;
data want; set have; sampleid=ceil(_n_/10); /* Assign sampleid as record blocks of 10 */ run;
proc logistic data=want; by sampleid; class x y; model y = x; run;
Of course, this does not work and my log looks like this:
...
I thought I would replace "want" with "filename", but it did not work. How should I do?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi!
I changed the code and now it works! Thank you very much!
PROC IMPORT OUT = filename FILE = "/folders/myshortcuts/sf_myfolder/filename.csv" DBMS = CSV REPLACE; RUN; data want; set filename; sampleid=ceil(_n_/10); /* Assign sampleid as record blocks of 10 */ run; proc logistic data=want; by sampleid; class x y; model y = x; run;
Is it possible to extract specific values (estimates and p-values) from the result of each regression and put them together into a vector or something similar?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Firstly, avoid using "filename" as a dataset name. And do please avoid coding in capitals. You can extract certain parts of teh data in various ways. In the example you get a dataset which can be filtered and further processed via datastep syntax. Or you may also get parts of an output by doing:
ods trace on;
--your code--
ods trace off;
Then in the log you will see all the component parts which are created by the procedure, you can then rerun your code (removing the ods trace parts as they are just to find out the names):
ods select <object>=<dataset to store>;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What do you mean with <dataset to store>?
Should I create a new file where I can save, for example, estimates? How do I do that then?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I would like to save all the parameter estimates from each sample to a vector or list, is that possible?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What does the ods trace show in the log, is the output name called ParameterEstimates, if so the syntax would be:
ods output ParameterEstimates=estim;
This will create a dataset in work called estim, with the parameter estimates.