Showing posts with label SAS. Show all posts
Showing posts with label SAS. Show all posts

Sunday, August 7, 2016

Estimating the Causal Effect of Advising Contacts on Fall to Spring Retention Using Propensity Score Matching and Inverse Probability of Treatment Weighted Regression

Matt Bogard, Western Kentucky University

Abstract

In the fall of 2011 academic advising and residence life staff working for a southeastern university utilized a newly implemented advising software system to identify students based on attrition risk. Advising contacts, appointments, and support services were prioritized based on this new system and information regarding the characteristics of these interactions was captured in an automated format. It was the goal of this study to investigate the impact of this advising initiative on fall to spring retention rates. It is a challenge on college campuses to evaluate interventions that are often independent and decentralized across many university offices and organizations. In this study propensity score methods were utilized to address issues related to selection bias. The findings indicate that advising contacts associated with the utilization of the new software had statistically significant impacts on fall to spring retention for first year students on the order of a 3.26 point improvement over comparable students that were not contacted.

Suggested Citation

Matt Bogard. 2013. "Estimating the Causal Effect of Advising Contacts on Fall to Spring Retention Using Propensity Score Matching and Inverse Probability of Treatment Weighted Regression" The SelectedWorks of Matt Bogard
Available at: http://works.bepress.com/matt_bogard/25

Saturday, June 13, 2015

SAS vs R? The right answer to the wrong question?

For a long time I tracked a discussion on LinkedIn that consisted of various opinions about using SAS vs R. Some people can take this very personal.  Recently there was an interesting post at the DataCamp blog addressing this topic. They also provided an interesting infographic making some comparisons between SAS and R as well as SPSS.  Other popular debates also include python in the mix. (By the way, it is possible to integrate all three on the SAS platform and you can also run R via the open source integration node in SAS Enterprise Miner 13.1).

Aside: For older versions of SAS EM-can you drop in a code node and call R via PROC IML?

Anyway, getting back to the article, I tend to agree with this one point:

"While these debates are a good thing for the community and the programming language as a whole, they unfortunately also have a negative effect on those individuals that are just in the beginning of their data analytics career. Biased opinions on all sides of the table make it difficult for new data analysts to see the forest for the trees when choosing a statistical programming language."

While I agree with this notion, I want to reflect for a minute on the concept of a programming language. If you think of SAS as just a programming language, then perhaps these kinds of comparisons and discussions make sense, but for a data scientist, I think one's view of analtyics should transcend just a language. When we think of an overall analytical solution there is a lot to consider, from how the data is generated, how it is captured and warehoused, how it is extracted and cleaned and accessed by whatever programming tool(s), how it is visualized and analyzed, and ultimately, how do we operationalize the solution so that it can be consumed by business users.

So to me the relevant question is not, which programming language is preferred by data scientists, or which program is better for implementing specific machine learning algorithms; but perhaps what is the best analytical solutions platform for solving the problems at hand? 

Tuesday, April 28, 2015

Healthcare Analytics at SAS Global Forum 2015

I was not able to attend this year's SAS Global Forum, but have had a chance to browse the numerous session papers as well as enjoy some live content. The conference page has a searchable catalog and for each paper you will find links to similar sessions in the sidebar. There were around 5000 attendees at this year's conference and over 600 papers. For a 2 1/2 day conference that's more than 200 papers to cover per day. Below is a selection of some papers related to healthcare analytics. If we widen the search to include papers related to other fields, but applications in healthcare analtyics the selection would probably double. I'm sure I missed something, and would be glad to know if you had a favorite paper or presentation you'd like to share in the comments.


1329 - Causal Analytics: Testing, Targeting, and Tweaking to Improve Outcomes This session is an introduction to predictive analytics and causal analytics in the context of improving outcomes. The session covers the following topics: 1) Basic... View More 20 minutes Breakout Jason Pieratt

1340 - Using SAS® Macros to Flag Claims Based on Medical Codes Many epidemiological studies use medical claims to identify and describe a population. But finding out who was diagnosed, and who received treatment, isn't always simple.... View More 50 minutes Breakout Andy Karnopp

2382 - Reducing the Bias: Practical Application of Propensity Score Matching in Health-Care Program Evaluation To stay competitive in the marketplace, health-care programs must be capable of reporting the true savings to clients. This is a tall order, because most health-care programs... View More 20 minutes Breakout Amber Schmitz

2920 - Text Mining Kaiser Permanente Member Complaints with SAS® Enterprise Miner™ This presentation details the steps involved in using SAS® Enterprise Miner™ to text mine a sample of member complaints. Specifically, it describes how the Text Parsing, Text... View More 30 minutes E-Poster Amanda Pasch

3214 - How is Your Health? Using SAS® Macros, ODS Graphics, and GIS Mapping to Monitor Neighborhood and Small-Area Health Outcomes With the constant need to inform researchers about neighborhood health data, the Santa Clara County Health Department created socio-demographic and health profiles for 109... View More 20 minutes Breakout Roshni Shah

3254 - Predicting Readmission of Diabetic Patients Using the High-Performance Support Vector Machine Algorithm of SAS® Enterprise Miner™ 13.1 Diabetes is a chronic condition affecting people of all ages and is prevalent in around 25.8 million people in the U.S. The objective of this research is to predict the... View More 20 minutes Breakout Hephzibah Munnangi

3281 - Using SAS® to Create Episodes-of-Hospitalization for Health Services Research An essential part of health services research is describing the use and sequencing of a variety of health services. One of the most frequently examined health services is... View More 20 minutes Breakout MeriƧ Osman

3282 - A Case Study: Improve Classification of Rare Events with SAS® Enterprise Miner™ Imbalanced data are frequently seen in fraud detection, direct marketing, disease prediction, and many other areas. Rare events are sometimes of primary interest. Classifying... View More 20 minutes Breakout Ruizhe Wang

3411 - Identifying Factors Associated with High-Cost Patients Research has shown that the top five percent of patients can account for nearly fifty percent of the total healthcare expenditure in the United States. Using SAS® Enterprise... View More 30 minutes E-Poster Jialuo Cheng

3488 - Text Analytics on Electronic Medical Record Data This session describes our journey from data acquisition to text analytics on clinical, textual data. 50 minutes Breakout Mark Pitts

3560 - A SAS Macro to Calculate the PDC Adjustment of Inpatient Stays The Centers for Medicare & Medicaid Services (CMS) uses the Proportion of Days Covered (PDC) to measure medication adherence. There is also some PDC-related research based on... View More 20 minutes Breakout anping chang


3600 - When Two Are Better Than One: Fitting Two-Part Models Using SAS In many situations, an outcome of interest has a large number of zero outcomes and a group of nonzero outcomes that are discrete or highly skewed.  For example, in modeling... View More 20 minutes Breakout Laura Kapitula

3740 - Risk-Adjusting Provider Performance Utilization Metrics Pay-for-performance programs are putting increasing pressure on providers to better manage patient utilization through care coordination, with the philosophy that good... View More 50 minutes Breakout Tracy Lewis

3741 - The Spatio-Temporal Impact of Urgent Care Centers on Physician and ER Use The unsustainable trend in healthcare costs has led to efforts to shift some healthcare services to less expensive sites of care. In North Carolina, the expansion of urgent... View More 50 minutes Breakout Laurel Trantham

3760 - Methodological and Statistical Issues in Provider Performance Assessment With the move to value-based benefit and reimbursement models, it is essential toquantify the relative cost, quality, and outcome of a service. Accuratelymeasuring the cost... View More 50 minutes Breakout Daryl Wansink

SAS1855 - Using the PHREG Procedure to Analyze Competing-Risks Data Competing risks arise in studies in which individuals are subject to a number of potential failure events and the occurrence of one event might impede the occurrence of other... View More 20 minutes Breakout Ying So


SAS1900 - Establishing a Health Analytics Framework Medicaid programs are the second largest line item in each state’s budget. In 2012, they contributed $421.2 billion, or 15 percent of total national healthcare expenditures.... View More 20 minutes Breakout Krisa Tailor


SAS1951 - Using SAS® Text Analytics to Examine Labor and Delivery Sentiments on the Internet In today’s society, where seemingly unlimited information is just a mouse click away, many turn to social media, forums, and medical websites to research and understand how mothers feel about the birthing process. Mining the data in these resources helps provide an understanding of what mothers value and how they feel. This paper shows the use of SAS® Text Analytics to gather, explore, and analyze reports from mothers to determine their sentiment about labor and delivery topics. Results of this analysis could aid in the design and development of a labor and delivery survey and be used to understand what characteristics of the birthing process yield the highest levels of importance. These resources can then be used by labor and delivery professionals to engage with mothers regarding their labor and delivery preferences. View Less 20 minutes Breakout Michael Wallis


Saturday, March 28, 2015

Applied Propensity Score Analysis with SAS: SAS Global Forum Papers

Below are two interesting SAS Global Forum papers implementing propensity score methods.

Paper 314-2012
PROPENSITY SCORE ANALYSIS AND ASSESSMENT OF PROPENSITY SCORE APPROACHES USING SAS® PROCEDURES
Rheta E. Lanehart, Patricia Rodriguez de Gil, Eun Sook Kim, Aarti P. Bellara, Jeffrey D. Kromrey, and Reginald S. Lee, University of South Florida


This paper is a very good paper with a succinct review of the literature and very clear SAS code for implementation of several propensity score methods including caliper based matching, inverse probability of treatment weighted regression, and analysis of covariance. 

Paper 220-2013
Propensity Score-based Analysis of Short-Term Complications in Patients with Lumbar Discectomy in the ACS-NSQIP Database
Yubo Gao The University of Iowa Hospitals and Clinics, Iowa City, Iowa


What I find interesting about the above paper is the use of the hash object in the matching implementation (vs. arrays used in the previous paper)

I am currently working on a suite of SAS programs that utilize the Mayo Clinic %gmatch macro as well as parametrization of the programs presented in Lanehart (suitable for a macro call)

Tuesday, March 25, 2014

Institutional Research Presentations at SAS Global Forum

I'm not attending #SASGF14, but some of my colleagues in higher ed are. Here is what they are doing. If you are not attending global forum, or can't make their talks, I encourage you to check out their papers via the online proceedings once they are posted.

Tuesday March 25

Paper 1448 - From Providing Support to Driving Decisions: Improving the Value of Institutional Research For almost two decades, Western Kentucky University's Office of Institutional Research (WKU-IR) has used SAS® to help shape the future of the institution by providing faculty and administrators with information they can use to make a difference in the lives of their students. This presentation provides specific examples of how WKU-IR has shaped the policies and practices of our institution and discusses how WKU-IR moved from a support unit to a key strategic partner. In addition, the presentation covers the following topics: How the WKU Office of Institutional Research developed over time; Why WKU abandoned reactive reporting for a more accurate, convenient system using SAS® Enterprise Intelligence Suite for Education; How WKU shifted from investigating what happened to predicting outcomes using SAS® Enterprise Miner™ and SAS® Text Miner; How the office keeps the system relevant and utilized by key decision makers; What the office has accomplished and key plans for the future.


Paper 1638 - Institutional Research: Serving University Deans and Department Heads Administrators at Western Kentucky University rely on the Institutional Research department to perform detailed statistical analyses to deepen the understanding of issues associated with enrollment management, student and faculty performance, and overall program operations. This paper presents several instances of analyses performed for the university to help it identify and recruit suitable candidates, uncover root causes in grade and enrollment trends, evaluate faculty effectiveness, and assess the impact of student characteristics, programs, or student activities on retention and graduation rates. The paper briefly discusses the data infrastructure created and used by Institutional Research. For each analysis performed, it reviews the SAS® program and key components of the SAS code involved. The studies presented include the use of SAS® Enterprise Miner™ to create a retention model incorporating dozens of student background variables. It shows an examination of grade trends in the same courses taught by different faculty and subsequent student behavior and success, providing insights into the nuances and subtleties of evaluating faculty performance. Another analysis uncovers the possible influence of fraternities and sororities in freshmen algebra courses. Two investigations explore the impact of programs on student retention and graduation rates. Each example and its findings illustrate how Institutional Research can support the administration of university operations. The target audience is any SAS professional interested in learning more about Institutional Research in higher education and how SAS software is used by an Institutional Research department to serve its organization.


Monday March 24

Paper 1689 - Simple ODS Tips to Get RWI (Really Wonderful Information) SAS® continues to expand and improve its reporting capability. With new SAS® 9.4 enhancements in ODS (Output Delivery System), the opportunity to create stunning reports has expanded even further. If you are charged with creating relevant, informative, easy-to-read reports for clients or administrators, then the ODS Report Writing Interface, ODS LAYOUT enhancements, and the new ODSTEXT procedure are important tools to use. These tools allow you to create reports in a smart, eye-catching format that can be turned around quite quickly and programmed to provide optimum flexibility. How many times have you worked hours to tweak and fine-tune a report directly in Microsoft Excel, Microsoft Word, Microsoft Power Point or some other similar software only to be asked for a “quick update”, which would then take hours to recreate because you are manually transferring data? Do you ever dread receiving the compliment, “This is really wonderful information!!!!” because you know it will be followed by “Can you run this for EVERY region?” Well, dread no more, because when you harness the power of SAS® ODS, you can create first-rate, flexible, fabulous reports! Join me as I share with you two real-world examples of ODS capabilities using (1) a marketing piece I designed to help the president of our university spotlight county- and region-specific data as he recruited across the state and (2) our academic program review form, a multi-page report that outputs to Word so that program coordinators can add personalized commentary to support their program’s effectiveness.

Friday, April 26, 2013

SAS Global Forum 2013 Paper 144-2013: SAS IML Worskshop

I didn't realize until now that the hands on workshops also had accompanying papers! ( I also just noticed this year  that the same was true for the posters as well).

This paper is a great intro to SAS IML. (see my other posts with statistical programming applications in social network analysis, text mining, and maximum likelihood estimation here )

Paper 144-2013
Getting Started with the SAS/IML® Language
Rick Wicklin, SAS Institute Inc.

ABSTRACT

Do you need a statistic that is not computed by any SAS® procedure? Reach for the SAS/IML® language! Many statistics are naturally expressed in terms of matrices and vectors. For these, you need a matrix language. This paper introduces the SAS/IML language to SAS programmers who are familiar with elementary linear algebra. The focus is on statements that create and manipulate matrices, read and write data sets, and control the program flow. The paper demonstrates how to write user-defined functions, interact with other SAS procedures, and recognize efficient programming techniques.

Link: http://support.sas.com/resources/papers/proceedings13/144-2013.pdf



Wednesday, April 10, 2013

SAS Global Forum Paper 089-2013 (CART)

This was a nice paper illustrating and explaining CART (classification and regression trees).

089-2013  Using Classification and Regression Trees (CART) in SAS® Enterprise Miner™ for Applications in Public Health


"They (CARTs) are typically model free in their implementation. Howbeit, a model based statistic is sometimes used for a splitting criterion. The main idea of a classification tree is a statistician’s version of the popular twenty questions game. Several questions are asked with the aim of answering a particular research question at hand. However, they are advantageous because of their non -parametric and non- linear nature. They do not make any distribution assumptions and treat the data generation process as unknown and do not require a functional form for the predictors. They also do not assume additivity of the predictors which allows them to identify complex interactions. Tree methods are probably one of the most easily interpreted  statistical techniques. They can be followed with little or no understanding of Statistics and to a certain extent follow the decision process that humans use to make decisions. In this regard, they are conceptually simple yet present a powerful analysis (Hastie et al 2009)."

Interesting SAS Global Forum 2013 Papers

I recently noticed almost all of the papers for SASGF13 are posted. Instead of browsing the conference materials (which are larger than my local telephone directory- such a huge conference) I decided to start by browsing the papers (which can be found in the proceedings). I can then refer back to this post when I start trying to actually map out which sessions I'll go to. (and I can get back to the papers for the sessions I miss)

Most of the sessions and papers I typically like are in the area of Statistics and Data Analysis or Data Mining and Text Analytics. These sessions and papers offer direct applications in SAS that I can immediately take back to my job and implement.  There are often other papers throughout  Pharma, Operations Research, and Financial Services that also can be really helpful.

Below are the titles and links to papers that I've found so far. Yes this seems like a lot, but its only a small portion of the total proceedings. There are tons of other sections related to business intelligence, data management, and programming. I'm not sure I'll fit all of the sessions I've found into a 3.5 day conference schedule.

Business Intelligence Applications
044-2013 A Data-Driven Analytic Strategy for Increasing Yield and Retention at Western Kentucky University Using SAS Enterprise BI and SAS® Enterprise Miner™

Operations Research
Pharma:

Statistics and Data Analysis


Data Mining and Text Analytics




Posters and Videos (papers included)




Monday, April 1, 2013

SAS Global Forum Papers

Using SAS® Enterprise BI and SAS® Enterprise MinerTM to Reduce Student Attrition

Matt Bogard, Western Kentucky University
Chris James
Tuesdi Helbig
Gina Huff

Abstract

The true supremacy of the SAS® Enterprise Business Intelligence Server is the ability to utilize the power of SAS® Analytics to deliver real-time information to end users, who usually do not understand statistics, but have the ability to make a difference if they have easy access to the analyzed data. This paper describes the process of using SAS® Enterprise Miner to develop a model to score university students based on their risk of attrition and deliver easy-to-understand results to university personnel using SAS® EBI.

Suggested Citation

Matt Bogard, Chris James, Tuesdi Helbig, and Gina Huff. "Using SAS® Enterprise BI and SAS® Enterprise MinerTM to Reduce Student Attrition" SAS Global Forum 2012 Proceedings.031-2012 (2012).

http://support.sas.com/resources/papers/proceedings12/031-2012.pdf 

A Data Driven Analytic Strategy for Increasing Yield and Retention at Western Kentucky University Using SAS Enterprise BI and SAS Enterprise Miner

Matt Bogard, Western Kentucky University

Article comments

SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Other brand and product names are trademarks of their respective companies.

Abstract

As many Universities face the constraints of declining enrollment demographics, pressure from state governments for increased student success, as well as declining revenues, the costs of utilizing anecdotal evidence and intuition based on ‘gut’ feelings to make time and resource allocation decisions become significant. However, grasping advanced statistical methods and analytics for data driven decision making can be overwhelming to some staff making buy in difficult. This paper describes how we are using SAS® Enterprise Miner to develop a model to score university students based on their probability of enrollment and retention early in the enrollment funnel so that staff and administrators can work to recruit students that not only have an average or better chance of enrolling but also succeeding once they enroll. Incorporating these results into SAS® EBI will allow us to deliver easy-to-understand results to university personnel.

 http://support.sas.com/resources/papers/proceedings13/044-2013.pdf

Tuesday, January 8, 2013

Decomposition: The Statistics Software Signal

From:

Decomposition: The Statistics Software Signal

http://seanjtaylor.com/post/39573264781/the-statistics-software-signal

"When you don't have to code your own estimators, you probably won't understand what you're doing. I'm not saying that you definitely won't, but push-button analyses make it easy to compute numbers that you are not equipped to interpret."

I agree that statistics is a language best communicated and understood via code vs. a point and click GUI.

However, particularly interesting is his view of how the use of a given software package may relate to the quality of research:

"SPSS: You love using your mouse and discovering options using menus. You are nervous about writing code and probably manage your data in Microsoft Excel." (see the linked article for similar remarks)


 To be fair, STATA, SPSS, SAS and R have coding environments, and as a user of both SAS and R products I don't see why using PROC REG in SAS is any less sophisticated than the 'lm' function in R. Nor do I see any difference in coding an estimator or algorithm in R vs. SAS IML.

In fact, there has been a long running discussion for over a year now on SAS vs. R on LinkedIn and in my opinion it all it has established is that R certainly provides a powerful software solution for many researchers and businesses. 

It would be interesting to quantify and test Taylor's theory.

UPDATE: see You say Stata I Say SAS: software signaling and social identity theory.

Tuesday, November 20, 2012

An Intuitive Approach to Eigenvector Centrality using SAS IML

A network can be thought of in terms of graph theory as a set of vertices connected by ties. The vertices can include individuals, teams, government agencies, organizations, facebook group members, topics, patents,etc. (Coulon,2005). The ties, represented as lines connecting the vertices are referred to as ‘edges.’ Edges therefore indicate the connections between individuals, organizations etc. Vertices and connections can be represented by what’s referred to as an adjacency matrix ‘A’, where Aij = 1 if there is an edge between vertices ‘i’ and ‘j’, and Aij = 0 otherwise. Adjacency matrices are symmetric, in that Aij= Aji. For example, the following adjacency matrix corresponds to the network depicted below:



Who’s who in a network?
The role a given vertice plays in the cohesiveness of the network (its ‘importance’ or ‘centrality’ )can be assessed by a number of social network metrics. 

Degree Centrality is simply the number of connections (or edges) a vertex has to other vertices. Its clear from counting that #1’s degree centrality is 3, while vertex #4 has a measure of degree centrality equal to 1. 

In terms of matrix algebra, if we can obtain this result as a vector (one entry per vertice) as follows:
x= (1,1,1,1)  degree = A’x 

Eigenvector Centrality is a measure that reflects the fact that not all connections are equal, and in fact, connections to people that are more influential are more important (Newman, 2012).  Mathematically, the measure of eigenvector centrality is derived from the weights that consist of the values from the leading eigenvector  (the eigenvector associated with the largest eigenvalue) of the adjacency matrix depicting the network. 

Recall, the value Ī» is an eigenvalue (or vector of eigenvalues) of the matrix A, and x is an eigenvector of A if the following equation holds:

Ī» x = A x

So, for the network depicted above, the centrality measures for each vertex = 1,2,3,4 can be derived from the components (x1,x2,x3,x4) that comprise the eigenvector x, and what we are interested in for this metric is the leading eigenvector (associated with the largest eigenvalue of A). 

Eigenvectors and eigenvalues can be derived by solving:

(A-Ī» I)x = 0
This metric can be found using canned functions in SAS and R. In SAS IML, the eigen function will allow you to obtain the leading eigenvector  x =( 0.6116285,0.5227207,0.5227207,0.2818452). 

A Path Centric Approach to Centrality

One way of looking at centrality in terms of connectivity is counting the number of paths emanating from a vertice to other vertices in the network.  For example, degree represents the number of paths of length 1 to other vertices in the network.  To look at this further, lets define the matrix B as:
B = A + I, where I is the identity matrix of A. The elements of B represent the number of paths of length 1 from a vertice ‘i’ to another vertice ‘j’. The row sums of B tell us the total number of paths of length one emanating for a given vertice (counting each vertice itself as 1). We can store this sum for each vertice in a vector ‘d’ obtained by multiplyting B’x



This gives us B’x = d1 = (4,3,3,2)

Now let’s define the matrix power of such that B2 = B*B


Each entry in B2 represents the number of paths of length 2 from vertice i to vertice j.
The sum  d2 = B2 *x = d2 = (12,10,10,6) is the total number of paths of length 2 originating from each corresponding vertice.

So Bk is a matrix with elements indicating the number of paths of length k between vertices i and j. The product Bk*x gives the sum of all paths of length k emanating from a given vertice. What we find is that as we consider longer and longer paths (as k becomes large) the normalized vector:

v = Bk*x / || Bk*x||   will approach the leading eigenvector of B (which consequently is also the leading eigenvector of A)

v1 = B1*x / || Bk*x||    = (0.6488857,0.4866643,0.4866643,0.3244428)
v5 = B5*x / || Bk*x||   =  (0.6121647,0.521951,    0.521951,0.2835289)
v10 = B10*x / || Bk*x||   =( 0.6116348,0.5227115,0.5227115,0.2818657)

Recall the leading eigenvector of A:

 x = ( 0.6116285,0.5227207,0.5227207,0.2818452)

So, what we have is a notion of eigenvector centrality as a metric that captures the number of paths emanating from a given vertice. A vertice that is connected to other vertices that also have lots of connections will have a greater number of k-length paths originating from it. This is information is reflected by eigenvector centrality. It turns out that the iterative  calculation of v above is essentially  the power iteration algorithm for calculating the leading eigenvector of a matrix B.

The following code from SAS IML and output provides an illustration of the preceding discussion.  In addition I have provided the function written by Rick Wicklin that implements the power iteration algorithm used to obtain the leading eigenvector and eigenvalue of a given matrix A.

REFERENCES:
Justification and Application of Eigenvector Centrality by Leo Spizzirri     https://www.math.washington.edu/~morrow/336_11/papers/leo.pdf

The power method: compute only the largest eigenvalue of a matrix.  The Do Loop. By  Rick Wicklin.

SAS IML MATRIX PROGRAMMING: 
 
proc iml;

*specify adjacency matrix A;
A = {0 1 1 1,
     1 0 1 0,
      1 1 0 0,
      1 0 0 0};

x = {1,1,1,1};

* Degree centraltiy;

d1 = A*x;
print(A);
print(x);
print(d1);

call eigen(u,v,A);
print v;

B = A + I(4);
print B;

d1 = B*x;
print d1;

B2 = B**2;
print B2;

* Degree Centrality including stopovers;

d1 = B*x;
print(d1);

d2 = (B**2)*x;
print(d2);

d3 = (B**3)*x;
print(d3);

* as k--> infinity, the normalized vector v approaches the leading eigenvector of A and/or B;
v1 =  d1/sqrt(d1[##]);
print v1;

d5 = (B**5)*x;
print(d5);

v5 =  d5/sqrt(d5[##]);
print v5;

d10 = (B**10)*x;
print(d5);

v10 =  d10/sqrt(d10[##]);
print v10;

run; quit;

* Rick Wicklin's Power Method Function;
proc iml;
     start PowerMethod(v, A, maxIters);
   /* specify relative tolerance used for convergence */
   tolerance = 1e-6;
   v = v / sqrt( v[##] );  /* normalize */
   iteration = 0; lambdaOld = 0;

   do while ( iteration <= maxIters);
      z = A*v;                /* transform */
      v = z / sqrt( z[##] );  /* normalize */
      lambda = v` * z;
      iteration = iteration + 1;
      if abs((lambda - lambdaOld)/lambda) < tolerance then
         return ( lambda );
      lambdaOld = lambda;
   end;
   return ( . ); /* no convergence */
finish;

* try our data;
A = {0 1 1 1,
     1 0 1 0,
      1 1 0 0,
      1 0 0 0};

v = {1,1,1,1}; 

lambda = PowerMethod(v, A, 40 );
print lambda;
print v;

run;quit;