I am trying to match SAS output with R.
I am using Proc Npar1way with D option to get KS test statistic.
?
Here X is a binary dependent variable and Y is the predicted probabilities;
proc npar1way data = mydata D; class x; var y; run;
When i try this in R
ks.test(x, fitted(y),alternative = c("two.sided"),exact = NULL) I get very
different result compared to SAS.
I am new to R. Any help is appreciated. I think i am missing a datastep
maybe ?
Thank you.
--
View this message in context: http://r.789695.n4.nabble.com/Proc-Nnpar1way-with-D-option-equivalent-in-R-tp4649348.html
Sent from the R help mailing list archive at Nabble.com.
Proc Nnpar1way with D option - equivalent in R
5 messages · Daniel Nordlund, SASandRlearn, Nordlund, Dan (DSHS/RDA)
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On Behalf Of SASandRlearn
Sent: Monday, November 12, 2012 5:55 PM
To: r-help at r-project.org
Subject: [R] Proc Nnpar1way with D option - equivalent in R
I am trying to match SAS output with R.
I am using Proc Npar1way with D option to get KS test statistic.
?
Here X is a binary dependent variable and Y is the predicted
probabilities;
proc npar1way data = mydata D; class x; var y; run;
When i try this in R
ks.test(x, fitted(y),alternative = c("two.sided"),exact = NULL) I get very
different result compared to SAS.
I am new to R. Any help is appreciated. I think i am missing a datastep
maybe ?
Thank you.
To reproduce the SAS results in R, you need to specify the ks.test something like:
ks.test(y[x==1], y[x==0],alternative = c("two.sided"),exact = NULL)
I say something "like", because I don't know what the binary values for x are, so I just used 1 and 0. If this doesn't help, then you need to provide some data and your actual results so that you have an actual reproducible example (see the posting guide).
Hope this is helpful,
Dan
Daniel Nordlund
Bothell, WA USA
Dan
Thank you for your reply. I will try what you recommended.
yes.. i have a 1 and 0 as binary.
Here is what i have so far
d <- read.csv(c:/test.csv", header=T)
dlogit <- glm(x ~ a + b + c, data = d, family = "binomial")
attach(d)
ks.test(x, fitted(values),alternative = c("two.sided"),exact = NULL)
I would also like to know how to export the model output from the glm into a
output dataset with those fitted values and then subset them into the 1's
and 0's. That might work as well ?
--
View this message in context: http://r.789695.n4.nabble.com/Proc-Nnpar1way-with-D-option-equivalent-in-R-tp4649348p4649370.html
Sent from the R help mailing list archive at Nabble.com.
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
project.org] On Behalf Of SASandRlearn
Sent: Tuesday, November 13, 2012 4:26 AM
To: r-help at r-project.org
Subject: Re: [R] Proc Nnpar1way with D option - equivalent in R
Dan
Thank you for your reply. I will try what you recommended.
yes.. i have a 1 and 0 as binary.
Here is what i have so far
d <- read.csv(c:/test.csv", header=T)
dlogit <- glm(x ~ a + b + c, data = d, family = "binomial")
attach(d)
ks.test(x, fitted(values),alternative = c("two.sided"),exact = NULL)
I would also like to know how to export the model output from the glm
into a
output dataset with those fitted values and then subset them into the
1's
and 0's. That might work as well ?
I am not sure what you mean about exporting the output from glm. You basically already have that in the dlogit object. Given your code above, you could call the ks.test() function like this
ks.test(fitted(dlogit)[d$x==1], fitted(dlogit)[d$x==0], alternative = c("two.sided"), exact = NULL)
This should produce results consistent with the SAS results. Whether you should do this I can't tell from way over here, because I don't know your data nor do I know what you are trying to do. You may want to seek out a local statistical consultant.
Dan
Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204
Dan,
what you suggested worked out well. This code below also worked out well for
me and it matches with SAS output.
Ks <- cbind(x,fitted(d1logit))
ks.df <- data.frame(Ks)
x <- subset(ks.df,x==0,select=c(V2))
y <- subset(ks.df,x==1,select=c(V2))
ks.test(x[,'V2'], y[,'V2'], alternative = c("two.sided"),exact=NULL)
Thank you
--
View this message in context: http://r.789695.n4.nabble.com/Proc-Nnpar1way-with-D-option-equivalent-in-R-tp4649348p4649459.html
Sent from the R help mailing list archive at Nabble.com.