0

I try to run the command file for application of Size-free canonical discriminant analysis from SAS to R [Size-Free CDA1. But, i have no idea how interpretate PROC SCORE in r

This is the my problematic step in SAS

proc princomp cov n=1 data=sashelp.iris out=prin;
var SepalLength SepalWidth PetalLength PetalWidth;

proc reg data=prin outest=coefregs;
r1: Model SepalLength = prin1;
r2: Model SepalWidth = prin1;
r3: Model PetalLength = prin1;
r4: Model PetalWidth = prin1;

proc score type= parms residual data=prin score=coefregs out= resid;
var SepalLength SepalWidth PetalLength PetalWidth prin1;

And this is my script in R for this step, without the PROC SCORE

pc <- princomp(iris[1:4], cor = F)
scores <- pc[["scores"]]
prin1 <- as.data.frame(scores[,1])

coefregs <- lm(cbind(Sepal.Length, Sepal.Width, Petal.Length, Petal.Width) ~ prin1[,1], 
data=iris) 

glht???

I still dont understand how this function works in SAS, Therefore, i would be grateful if you could help me with some of code in r that mimic PROC SCORE

Note: SAS iris data is in mm, in R it is cm

  • Maybe someone with more programming experience knows directly how to answer your question, but to me the desired/SAS output would have been helpful. I have never used proc score in sas but from what I understand it adds the output of (in this case) lm to the raw data. So this could be solved with a join/merge. Furthermore, you might want to calculate the scores based on the regression coefficeints which might be solved with a mutation. – Annet Feb 12 '20 at 08:19
  • Isn't it just getting you the predicted and residual values in the PROC SCORE or is it doing something beyond that? I'm assuming it's doing it for each model? – Reeza Feb 12 '20 at 17:20
  • Your R code is using the `iris` data again for the regression but in SAS you're using the `prin` data set for the regression. This is using the output of the principal component in the regression. If you want the same in R, use the `scores` data set in your regression, not the `iri`s data set. – Reeza Feb 12 '20 at 17:35
  • Hi Annet, yes, i want to calculate the based on the regression coefficeints. I will try this – Duvan Zambrano Feb 12 '20 at 19:01
  • @Reeza, i only use the residual values for PROC SCORE. The scores will be used to calculate a CDA. Respect to out `prin` data set, the values of variable are the same to `iris` raw data in my execise. PRINCOMP only add `prin1` to `iris`, is it an error? – Duvan Zambrano Feb 12 '20 at 19:22
  • Try `residuals(coefregs)` to see if you get what you need then, assuming your R code works. Note that in SAS you ran 4 single regressions but I'm not sure that's what R is doing. If you are sure the regressions are the same, you should be good to go with the residuals command. – Reeza Feb 12 '20 at 19:28
  • Thanks @Reeza, but i try to emulate the score from PROC SCORE on residuals, as in a post processing procedure. `residuals` only extracts the residual values from `lm`. However, i will try another approach for this, no just a literal translation from SAS to R – Duvan Zambrano Feb 12 '20 at 20:48
  • You want this then: https://stackoverflow.com/questions/33677488/using-an-already-created-model-for-scoring-a-new-data-set-in-r Spefically, the`predict()` function but it also shows you how to save the model and use it later if needed. – Reeza Feb 13 '20 at 16:36

0 Answers0