[prev in list] [next in list] [prev in thread] [next in thread] 

List:       sas-l
Subject:    Selecting lower tiangular correlations with p values <= .05
From:       Roger DeAngelis <rogerjdeangelis () GMAIL ! COM>
Date:       2017-02-28 21:14:37
Message-ID: 1062780332056883.WA.rogerjdeangelisgmail.com () listserv ! uga ! edu
[Download RAW message or body]

Selecting lower tiangular correlations with p values <= .05

You can cut and paste the R code into IML/R
or just use IML

1. SAS Using proc corr (too many observartions for WPS express - unable to test)
2. SAS/WPS/R


One of the problems is

%let XVARS=SEPALLENGTH  SEPALWIDTH  PETALLENGTH;

P&xvars is not what you need

%put P&xvars;

PSEPALLENGTH  SEPALWIDTH  PETALLENGTH

You need

%let PXVARS=PSEPALLENGTH  PSEPALWIDTH  PPETALLENGTH;


HAVE  This correlation matrix
=============================

%let XVARS=SEPALLENGTH  SEPALWIDTH  PETALLENGTH;
%let PXVARS=PSEPALLENGTH  PSEPALWIDTH  PPETALLENGTH;
%let dimsqr=%sysfunc(countw(&xvars));

Up to 40 obs from fullcorr total obs=3

                       CORRELATIONS                                        PVALUE
               =======================================     ==========================================
  VARIABLE     SEPALLENGTH    SEPALWIDTH    PETALLENGTH    PSEPALLENGTH    PSEPALWIDTH    PPETALLENGTH

 SEPALLENGTH      1.00000      -0.11757        0.87175         _             0.15190            0
 SEPALWIDTH      -0.11757       1.00000       -0.42844        0.15190         _                 0
 PETALLENGTH      0.87175      -0.42844        1.00000        0.00000        0.00000            _

WANT
====

SAS/WPS proc corr
=================

        SEPALLENGTH    SEPALWIDTH    PETALLENGTH

row=1     1.00000         .               .
row=2      .             1.00000          .
row=3     0.87175       -0.42844       1.00000


DETAILS  (SAS/WPS operations on correlation matrix)

  1. Set upper triangular to missing
  2. keep 1s on diagonal
  3. set correlations to missing for 0.15190  because 0.15190 ge to 0.05.
     see below

                     PVALUE
     ==========================================
     PSEPALLENGTH    PSEPALWIDTH    PPETALLENGTH

         _             0.15190            0
        0.15190         _                 0
        0.00000        0.00000            _

R
==
             SEPALLENGTH SEPALWIDTH PETALLENGTH
 SEPALLENGTH   1.0000000         NA          NA
 SEPALWIDTH    0.0000000  1.0000000          NA
 PETALLENGTH   0.8717538 -0.4284401           1


SOLUTION
========

*____    _    ____
/ ___|  / \  / ___|
\___ \ / _ \ \___ \
 ___) / ___ \ ___) |
|____/_/   \_\____/
;

* get the correlation matrix with pvalues;

%let XVARS=SEPALLENGTH  SEPALWIDTH  PETALLENGTH;
%let PXVARS=PSEPALLENGTH  PSEPALWIDTH  PPETALLENGTH;
%let dimsqr=%sysfunc(countw(&xvars));
/* dimsqr = 3 */
**Get full correlation matrix;
ods output PearsonCorr=fullcorr;
proc corr data=sashlp.iris(keep=sepallength sepalwidth petallength);
var &XVARS.;
run;


* load into arrays;
data want(keep=&xvars);
 retain n 0;
 array pval{*} &pXVARS.;
 array vrbl{*} &XVARS.;

 array cor(&dimsqr,&dimsqr) _temporary_;
 array pvl(&dimsqr,&dimsqr) _temporary_;

 do until(dne);
   set fullcorr end=dne;
   n=n+1;
   do j=1 to &dimsqr.;
     cor[n,j]=vrbl[j];
     pvl[n,j]=pval[j];
     * put
      cor[n,j]=
      pvl[n,j]=
    ;
   end;
 end;
 do i=1 to &dimsqr.;
    do j=1 to &dimsqr.;
      if pvl[i,j] ge .05 then cor[i,j]=.;
      if i<j then cor[i,j]=.;
    end;
    put "row=" i @@;
    do j=1 to &dimsqr.;
      put  cor[i,j] @@;
      vrbl[j]=cor[i,j];
    end;
    put;
    output;
 end;
run;quit;

*____
|  _ \
| |_) |
|  _ <
|_| \_\
;

options validvarname=upcase;
libname sd1 "d:/sd1";
data sd1.iris(keep=sepallength  sepalwidth  petallength);
   set sashelp.iris;
run;quit;

%utl_submit_wps64('
options set=R_HOME "C:/Program Files/R/R-3.3.1";
proc r;
submit;
library(haven);
library(Hmisc);
eyerus<-as.matrix(read_sas("d:/sd1/iris.sas7bdat"));
cor<-rcorr(eyerus,type=c("pearson"));
pval<- cor[[3]] < 0.05;
pval[is.na(pval)]<-FALSE;
fin<-cor[[1]]*pval;
fin[upper.tri(fin)] <- NA;
diag(fin) <- 1;
fin;
endsubmit;
run;quit;
');


The WPS System

            SEPALLENGTH SEPALWIDTH PETALLENGTH
SEPALLENGTH   1.0000000         NA          NA
SEPALWIDTH    0.0000000  1.0000000          NA
PETALLENGTH   0.8717538 -0.4284401           1
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic