Download presentation
Presentation is loading. Please wait.
Published byStephany Parker Modified over 7 years ago
1
JMP® and R Integration Application using Alaskan Pipeline Data
Melvin Alexander MAJUG Co-Chair MAJUG Meeting, Thursday, September 28, 2017
2
Agenda Purpose: Demonstrate and apply JMP® and R Integration functionality on Alaskan pipeline data. Review steps and basic functions connecting JMP® with R Compare results from both products Conclusions Q & A This presentation will review ways of using JMP® to convert pixel values from images (i.e., discrete numerical representations of colors in GIF, PNG, JPG formats) into data tables and matrices. Once data are in data tables, additional analyses and data visualizations may be performed. I will demonstrate these capabilities using examples from medical computer tomographic (CT) images. CT images are special types of X-rays that are three dimensional cross-sections of internal body organs. Radiologists and medical clinicians look for certain signs in these images to diagnose patients with specific injuries and/or medical conditions. Results of the image analyses help radiologists and clinicians decide the medical treatments to give to patients (e.g., surgery, non-operative management, targeted radiation-beam therapies). Combining the statistical, graphical and data analytic functionality of JMP® extends information visualization beyond what can be seen with standard image interpretation. Ways to replicate these visualizations in SAS® will also be discussed
3
JMP® and R Integration Application using Alaskan Pipeline Data
Abstract: JMP® and R Integration is a powerful interface that facilitates communication between both environments. This interface allows JMP® to execute R commands, exchange data and output. This presentation will illustrate this capability using Alaskan Pipeline data from the NIST/SEMATECH e-Handbook of Statistical Methods, The advantage of this interface allows users access to the statistical and visualization tools available in both products.
4
Getting Started JMP® and R (additional optional libraries as needed) must be installed on the same machine Open JMP® Script window and Log Use File > Open (select script from dialog) or File > New > Script (type or paste code in Script window) Execute R Init(); (opens R and links JMP® to R) Output written to JMP® Log and Output Windows
5
Basic JSL R-Integration Functions
R Init(); (Connects JMP® to R) R Send(); (Sends data object, table, list, matrix, or number from JMP® to R) R Submit(“\[ …R code…]\”); (Executes string of R code commands) or R Submit File(/*path to the file that contains the R code you want to execute*/); (Executes externally stored string of R code commands) R Execute(/*list of R input var names*/, /*list of R output var names*/, "\[your R code to submit]\"); (Executes R code ) Varname = R Get(); (Brings data from R to JMP®, assigning it to Varname) or R Get Graphics(/*either png or jpg*/); (displays the most recent R plot) R Term(); (Disconnects JMP® and R link)
7
R Code of Alaskan Pipeline Data
8
Open in JMP® and Use Alaskan Pipeline Data in R
R Init(); /* starts connection to R */ R Submit( “\[ ## Generate conditional plot ## create vector with dependent variable, field defect size fdef = c(18,38,15,20,18,36,20,43,45,65,43,38,33,10,50,10,50,15,53,60,18,38,15,20,18,36,20, 43,45,65,43,38,33,10,50,10,50,15,53,15,37,15, 18,11,35,20,40,50,36,50,38,10,75,10,85,13, 50,58,58,48,12,63,10, 63,13,28,35,63,13,45,9,20,18,35,20,38,50,70,40,21,19,10,33,16,5, 32,23,30,45,33,25,12,53,36,5,63,43,25,73,45,52,9,30,22,56,15,45) ## other R code etc. Batch <- as.factor(bat) df <- data.frame(fdef,ldef,Batch) len <- length(Batch) xax = “Lab Defect Size” yax = “Field Defect Size” Title =“Alaska Pipeline Ultrasonic Calibration Data” plot(ldef,fdef, xlab=xax,ylab=yax,main=title,col=“blue”) ]\”); /* create JMP data table from the R data frame */ Rdf = R Get (df) ; Rdf << NewDataView << Set Name( “R Data frame Table” ) ; /* set the Value ordering and label properties for the Batch variable so that the Graph Builder plot from JMP matches the Trellis Plot displayed from R */ Rdf:Batch << Set Property (“Value Ordering”, Eval( {4,5,6,1,2,3} ) ) << Value Labels (1, “Batch: 1”, 2, “Batch: 2”, 3, “Batch: 3”, 4, “Batch: 4”, 5, “Batch: 5”, 6, “Batch: 6” ) << Use Value Labels(1) ; /* other JSL and R code */
9
Open in JMP® and Use Alaskan Pipeline Data in R (cont)
/* submit another block of R code to get Trellis plot form R into a JMP Window */ R Submit( “\[ # load package to produce trellis plot library (lattice) ## Generate conditionl plot trellis.device(new = TRUE, col = FALSE) FIG = xyplot(fdef ~ ldef | Batch, data=df, main = title, layout=c(3,2), col=4, xlab=list(xax,cex=1.1), ylab=list(yax, cex=1.1), strip=function(…) strip.default(…,strip.names=c(T,T), FIG ]\”); Picture = R Get( “png” ) ; New Window( “Alaskan Pipeline Ultrasonic Calibration Data from R into JMP”, picture ) ; Wait(10); /** Use Graph Builder to produce reproduce Trellis plot in JMP**/ Rdf = R Get (df) ; Rdf << Graph Builder( Size( 457, 408), Show Control Panel( 0 ), Variables( X ( :ldef ), Y( :fdef ), Wrap( :Batch, Levels per Row( 3 ) ) ), Elements( Point( X, Y, Legend( 3 ) ) ), SendToReport( Dispatch( {}, “graph title”, TextEditBox, {Set Text( “Alaska Pipeline Ultrasonic Calibration Data – JMP” )} ), Dispatch( {}, “X title”, TextEditBox, {Set Text( “Lab Defect Size “ )} ), Dispatch( {}, “Y title”, TextEditBox, {Set Text( “ln(Field Defect Size” )} ) ) ) ; /* other JSL and R code */
10
Selected Results written to JMP Log that would appear in the R Console
Note: The TKIntRJMP.R version message establishes successful connection to R. Contents in the JMP Log are the returned output that would be written in the R Console. The 0 at the end terminates the R session) Selected Results written to JMP Log that would appear in the R Console TKIntRJMP.R version 5.05 $`1` Call: lm(formula = y ~ x, data = x) Residuals: Min Q Median Q Max Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) * x e-08 *** --- Signif. codes: 0 '***' '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: on 17 degrees of freedom Multiple R-squared: , Adjusted R-squared: F-statistic: on 1 and 17 DF, p-value: 1.798e-08 Call: lm(formula = fdef ~ ldef) Residuals: Min Q Median Q Max Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) e-05 *** ldef < 2e-16 *** --- Signif. codes: 0 '***' '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: on 105 degrees of freedom Multiple R-squared: , Adjusted R-squared: F-statistic: on 1 and 105 DF, p-value: < 2.2e-16
11
/* Create JMP data table from the R data frames */
Rdf = R Get(df) ; Rdf << NewDataView << Set Name("R Data frame Table") ;
12
/* Produce plots and regression fits with
JMP Analysis platforms */ /* Get the FIG graph from R and display in JMP */ R Submit( "\[ ## Generate conditional plot trellis.device(new = TRUE, col = FALSE) FIG = xyplot(fdef ~ ldef | Batch, data=df, main = title, layout=c(3,2), col=4, xlab=list(xax,cex=1.1), ylab=list(yax,cex=1.1), strip=function(...) strip.default(...,strip.names=c(T,T))) FIG ]\" ); picture = R Get Graphics( "png" ); New Window("Alaska Pipeline Ultrasonic Calibration Data from R into JMP", picture) ; Wait( 10 );
13
/*Set the Value ordering property for the Batch column so that it matched displaying the Trellis Plot in R Value Lables() property matches the FIG labeling from R */ Rdf:Batch << Set Property( "Value Ordering", Eval ( {4, 5, 6, 1, 2, 3} ) ) << Value Labels( {1 = "Batch: 1", 2 = "Batch: 2", 3 = "Batch: 3", 4 = "Batch: 4", 5 = "Batch: 5", 6 = "Batch: 6"} ) << Use Value Labels( 1 ) ;
14
Rdf << Graph Builder(Size( 457, 408 ),Show Control Panel( 0 ),Variables( X( :ldef ), Y( :fdef ), Wrap( :Batch, Levels per Row( 3 ) ) ), Elements( Points( X, Y, Legend( 3 ) ) ),SendToReport( Dispatch({},"graph title",TextEditBox,{Set Text( "Alsaka Pipeline Ultrasonic Calibration Data - JMP" )} ), Dispatch( {}, "X title", TextEditBox, {Set Text( "Lab Defect Size " )} ), Dispatch({},"Y title",TextEditBox,{Set Text( "ln(Field Defect Size)" )} ) ) );
15
/* Box-Cox linearity plot */
R Submit( "\[ ## Transformations of predictor variable lnldef = log(ldef) sqrtldef = sqrt(ldef) invldef = 1/ldef ## Box-Cox linearity plot for (i in (0:100)){ alpha = *i/100 if (alpha != 0){ tx = ((ldef**alpha) - 1)/alpha temp = lm(lnfdef~tx) temps = summary(temp) if(i==0) {rsq = temps$r.squared alp = alpha} else {rsq = rbind(rsq,temps$r.squared) alp = rbind(alp,alpha)} }} rcor = sqrt(rsq) par(mfrow=c(1,1),cex=1.25) plot(alp,rcor,type="l",xlab="Alpha",ylab="Correlation", main="Box-Cox Linearity Plot ln(Field) Lab", ylim=c(.6,1), col="blue") #creaate Correlation and Alpha vectors into BCP data frame Corr <- as.vector(rcor) Alpha <- as.vector(alp) BCP <- data.frame(Corr,Alpha) ]\" ); RBCP = R Get(BCP); RBCP << NewDataView << Set Name("R Data Frame of Alpha-Correlation Table") ;
16
Why JMP® and R ? “JMP is a wonderful complement to R. The integration with R is surfaced with several new JSL commands that allow you to connect to an install of R on your desktop, send data to and from R, and submit R routines available through the R packages. JMP dialogs can easily be built for parameter input to R as a front-end, and more significantly, JMP’s interactive and dynamic statistical platforms and graphics make for a perfect back-end to R functions.” --Kelci Miclaus, JMP® Life Sciences R&D Manager,
17
References NIST/SEMATECH e-Handbook of Statistical Methods (2012), “ Alaska Pipeline” , (accessed 08/24/2017). Miclaus, K. (2010), “JMP into R!,” (accessed 08/24/2017). Miclaus, K. ( 2010 ), “On-Demand Webcast: JMP and R Integration,” (accessed 08/24/2017). Stephan, D. (2017), “Experiences with and Recommendations for using R for Statistics/Analytics Instruction: Using JMP with R,” (accessed 08/24/2017). Gong, J. (2016), “Getting Started with the JMP to R Interface,” (accessed 09/12/2017). REFERENCES
18
Disclaimer The views expressed in this presentation are those of the presenter and do not necessarily represent the views of the Social Security Administration(SSA) or SAS Institute, Inc. Disclaimer
19
Questions? Contact: Melvin.Alexander@ssa.gov
JMP, 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.
20
Acknowledgements (Many Thanks to the following for their help with this presentation and support)
JMP® Division of SAS® (Cary, NC) Anna-Christina De La Iglesia Gail Massari Robin Moran Robyn Godfrey Tom Donnelly US Bureau of Labor Statistics (Washington, DC) Josh Klick Acknowledgements
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.