Beyond Excel - Enhancing Your Biomedical Data Analysis with MATLAB
Overview
Many technical professionals find that they run into limitations using Excel for their data analysis applications. This webinar will demonstrate how MATLAB can accelerate your biomedical data analysis by providing access to thousands of pre-built mathematical functions, domain-specific interactive apps, versatile visualization tools, and the ability to automate your analysis workflows.
In the webinar you’ll learn how to use MATLAB to:
- Access data from files and Excel spreadsheets
- Visualize data and customize figures
- Perform curve/model fitting using interactive apps
- Automatically generate MATLAB code to automate repetitive tasks
- Share your results by generating reports or creating your own standalone applications
Please allow approximately 45 minutes to attend the presentation and Q&A session. We will be recording this webinar, so if you can't make it for the live broadcast, register and we will send you a link to watch it on-demand.
About the Presenter
Paul Huxel, Ph.D.
Senior Application Engineer, MathWorks Ireland
Paul holds a B.S./M.S. in Aerospace Engineering from The University of Colorado at Boulder and a Ph.D. in Aerospace Engineering from The University of Texas at Austin. Paul has over 8 years of industry experience, which includes extensive design, modeling, and analysis of complex Guidance, Navigation, & Control systems for the US Navy and NASA using MATLAB and Simulink. After a 15-month sabbatical as a volunteer STEM teacher in rural Africa, Paul joined the Application Engineering Group at MathWorks in Galway, Ireland in August 2017. Since then Paul's interests and skills have focused on image processing, computer vision, and machine/deep learning for the medical industry.
Recorded: 18 Nov 2020
Hello, everyone. Thank you for joining us today. My name is Paul Huxel, and I'm a senior application engineer with MathWorks in Ireland. Since joining our Galway office about three years ago, I visited and worked with many medical device and pharmaceutical sites across Ireland to help them use MATLAB to enhance their data analysis. I hope this introductory webinar demonstrates how easily you can get started as well.
But before we get into the how, I want to first show you what we'll be building towards in today's webinar. This is a Web App, an app built in MATLAB that runs in a web browser. The problem we'll be working on today is to load a spreadsheet of drug interaction data, fit a surface to this data to create a model of the drug interactions, and then use this model to determine the minimal dose for the desired anesthetic response.
I'll describe this problem in more detail in a moment. But I encourage you to instead focus on the general workflow itself and how these techniques might be applied to your own data. With that in mind, let's take a quick look at the typical data analysis workflow.
If we're going to perform data analysis, we're going to need access to data. This could be from files, such as spreadsheets and images, other software and web applications, or directly from hardware and scientific instruments. Once we have our data in MATLAB, we'll see how easy it is to begin exploring and discovering various analysis and modeling techniques. In particular, we'll see how a wide range of domain-specific apps will help us quickly get results without writing any code.
But to get the most out of our work, we'll want to share it with colleagues or customers. As you just saw, today we'll be building a Web App, so our end users can access our work without requiring a MATLAB installation or license. But other options include automatic code generation, Cloud deployment, or automatic report generation. We'll return to talk more about these a little bit later. Finally, we'll see how we can use MATLAB to help automate this process.
As I mentioned, to demonstrate this workflow, we'll be working with a table of drug interaction data. This data contains the resulting anesthetic response for several trials of various opioid and sedative concentration pairs. We'll use the equation given here to determine the model parameters that best fit our trial data.
Once we have a working model, we can make predictions of the anesthetic response for concentration pairs that were not included in our trial data. This will then allow us to use the model to determine the minimal drug concentrations that produce a desired anesthetic response. With our problem now defined, let's jump into MATLAB and get started.
When you open MATLAB, you'll see four main areas. The current folder is the first place MATLAB is going to look for scripts and other files. It shows all of the files on the path in the address bar here. The Command Window allows you to immediately execute commands and run scripts. Variables created by these commands or scripts will show up in the workspace.
The workspace shows the variables currently in MATLAB's memory and provides information on their dimensions and data type. These variables are then available for use in other commands or scripts. Finally, the tool strip at the top organizes MATLAB functionality within a series of tabs. I'll talk more about these as we use them.
Recall from the workflow that the first thing we'll need in order to do data analysis is to access data. As you can see in the current folder, we have a spreadsheet of data showing different combinations of sedative and opioid concentrations and the corresponding observed response. We'll use the Import Data button on the Home tab to interactively import this data from Excel.
Once we select a file, we'll be able to preview our data. It appears we have some missing data in our spreadsheet. There are different ways to handle this. In our case, we'll just exclude these rows when we import the data.
Next, instead of having to repeat this interactive process every time we get new data, we'll generate a MATLAB function so that we can automate this step. We can then scroll through this code to learn more about what function MATLAB uses to read tabular data or modify the code if needed.
The first line shows us the syntax to use this function. Once we save this code, we'll see the corresponding files show up in the current folder view. We can then call this function from the command line or another script using the name of our spreadsheet as the input.
Notice that a new variable with 392 rows and three columns appears in the workspace. Double-clicking on the variable, we see that it contains the same three columns contained in the spreadsheet, except the row with the missing data has now been removed. We can extract these columns from the table using dot notation. I'm using tab completion to quickly enter the column names. Again, we see each of these new variables show up in the workspace as they're created.
We can now select these variables from the workspace to quickly explore their interactions using the Plots tab. MATLAB then displays all the relevant plotting options. We'll select a scatter plot to visualize each point separately. Notice that when we did this, MATLAB automatically displayed the corresponding command in the Command Window.
We can interactively customize our plot using the Property Inspector, which will allow us to customize almost any property of our figure. To start, we'll add labels to the x- y- and z-axes and include units of micrograms per milliliter using the Greek character mu.
In our case, because of the order in which we selected the data from the workspace, the x-axis corresponds to the opioid values. The y-axis corresponds to the sedative values. And finally, the z-axis corresponds to the response values.
Next we'll fill in the marker faces with a solid color and change the marker edge color to black. Once we're finished customizing our plot, we can once again automate this interactive process by creating a MATLAB function.
This time, we will make some changes to the code. We can right-click on a command to learn more about it. We see that scatter3 also allows us to color-code our data points. Let's color-code them based on their z-value, which in our case is the response value. We'll also add a color bar.
We'll save our function and we'll again see the corresponding files show up in the current folder view. We can now close the previous figure and quickly recreate it using this function with our opioid, sedative, and response values as inputs.
Some of the response points appear to be greater than 1, which should not be the case. Handling messy data can be a challenge, and the best approach will often be problem-dependent. In this case, we'll return to the Command Window to create a logical variable to find all of the indices where the response is greater than 1. We can then use these indices to saturate these values to 1. We can confirm we did this correctly by replanting our figure using our plotting function.
Now that we visualize and cleaned up our data, we're ready to fit our data and create a drug interaction model. Recall from the slides that we have an underlying equation for our model. We just need to determine the model parameters.
To save time, I've created a live function with this equation. Live scripts and live functions allow us to document our code with rich text formatting, hyperlinks, and equations. We'll use this function with the curve-fitting app. The Apps tab offers many interactive apps to help you get started with capabilities such as machine and deep learning, image and signal processing, test and measurement, computational biology, or, in our case, curve-fitting.
Once we select our x, y, and z data from the workspace, we can quickly try fitting various models. For example, we see that a simple first order polynomial model will not be a good fit for our data. However, in our case, as you saw in the live function, we already have an equation for our model. We just need to determine the model parameters. Recall our x and y values are the opioid and sedative concentrations, respectively. The app then displays the resulting model parameters and 95% confidence bounds.
By now you should be noticing a pattern. We do things interactively the first time and then generate MATLAB code to automate the task for future use. Let's comment out the part of the code that generates the figure so that we can customize our own.
The first line of code, again, shows us how to use our function. Once we save the code, we can then use this syntax to call our function from the command line. Doing so will create a usable model by estimating the model parameters. We can then select the fitted model from the workspace and explore the available plots in the Plots tab. Once again, notice that MATLAB echoed the corresponding commands to the command line.
At this point, we've done quite a bit of work. And if we wanted to reproduce this analysis for a new data file, we'd have to enter all of these commands at the command line again. So instead, I'll use the up arrow and the Control key to gather all of these commands into a live script.
As we saw before, we can then add rich text formatting, images, and even a table of contents to help document our code. In the interest of time, I've already done this in a live script I created earlier. So now if we were starting with a clear and empty workspace, we just need to run this script to reproduce all of the work we've done so far.
As I scroll through this live script, you'll recognize all of the functions and figures we created earlier. Notice code sections are indicated by gray, shaded areas, and all of the figures are embedded in the live script document for easy sharing of results.
We're now ready to use our model to make predictions of new opioid and sedative concentrations, which in this case results in a value of about 0.96. I've added this predicted value to our figure as a red dot. Similarly, by evaluating the model over a grid of concentration pairs, we can instead determine the minimal dose combination of opioid and sedative that still yields the same response value of about 0.96.
The last step in the workflow is to share our work. To do so, we'll create an app using App Designer, like the one I showed at the start. We can begin by creating a new app from the Home tab. App Designer provides several templates to help you get started, including a short interactive tutorial. We'll start from scratch with a blank app.
As you can see in the Component Library on the left, there are many components to choose from. For this example, we'll select an Axis component to plot our data and draw it onto the desired location on the canvas. We'll also drag over a Button component for the user to select their data spreadsheet.
Similar to the figure Property Inspector we used before, the component browser on the right allows us to customize our components. We'll once again label the axes as opioid, sedative, and response. And we'll also add grid lines to the x-, y-, and z-axes. Next we'll add a callback to the Load button to specify what we want to happen when the user interacts with the app.
This brings us to the Code View of our app. MATLAB automatically generates all the code in gray. We just need to add the code we want to run when the button is pushed. In particular, I'm going to paste in pieces of the code we created earlier. However, we still need to make two changes.
First, we want the user to be able to select their own data file. To do so, we'll use the user interface function, uigetfile, and specify that the file type will be an Excel spreadsheet. We can then feed this information to our import function. And second, when plotting within apps, we need to specify that our data should be displayed in the axes that we just added in the Design View.
And that's it. After we save it, we're ready to try running our app. We'll then experience what the end user would see if the app was deployed as a standalone desktop application. This allows us to quickly and easily test and update the functionality and user interface of our app before it's deployed.
We would add additional components using the same process. But in the interest of time, we'll package our app as it is and deploy it as a Web App. We could edit this project to provide details about our app, such as the author, a description, or even an image or logo to be displayed in the App Gallery when launching our app.
Likewise, once you've installed the Web App server, this package can also be configured to automatically copy the resulting CTF archive to the proper folder. This then makes the app visible on your Web Apps home page. And as you saw earlier, the end user can then launch it and interact with the app using just a web browser. As we saw when running this app in MATLAB, the user can again select a spreadsheet of data to load and then interactively visualize the 3D relationship between drug concentrations and the resulting anesthetic response.
I hope this example gave you a feel for just how quickly and easily you can get started using MATLAB to enhance your data analysis. As you can see here, we only covered a very narrow path through this workflow. So I'd like to take a moment to highlight some of the capabilities that we missed.
MATLAB offers a single integrated platform for your entire workflow. Today we imported an Excel spreadsheet. But we also offer interactive tools and hardware support packages to make accessing data easy from other applications, databases, and scientific instruments. For analysis and development, additional capabilities include machine and deep learning, signal and image processing, biological sequence analysis, and simulation in both the time and frequency domains, just to name a few. And as we briefly saw earlier, in each of these domains, MATLAB offers interactive tools and deep solutions to help jumpstart your analysis and development.
But you may have also noticed there are apps to help you share and deploy your work as well. There are two main pathways to do this-- application deployment, like the Web App we just compiled, and automatic code generation. In both cases, you'd once again begin by developing models, algorithms, or applications, in MATLAB. Which sharing pathway you choose then depends on the requirements of your system.
Application deployment allows you to create graphical user interfaces and software libraries that can be integrated with enterprise and Cloud systems. With this option, the functionality of MATLAB is still effectively running behind the scenes, but the end user does not require a MATLAB license. Automatic code generation, on the other hand, allows you to run your analytics on embedded hardware, such as a medical device or manufacturing line. In this case, your MATLAB algorithms are converted to readable, portable code in the language of your specified hardware, such as a real-time target, FPGA, ASIC, PLC, or GPU.
With deployment in mind, one question we often get asked is if MATLAB is validated by the FDA or other regulatory agencies. We've created a Q&A web page and tool validation kit to help guide you through this process. Here you'll also find a summary of the FDA-MathWorks Research and Collaboration Agreement, as well as contact information if you have additional questions or need consulting help.
Today's webinar gave you a quick introduction to what MATLAB has to offer. We saw how easy it is to get started with MATLAB. Thorough documentation with applicable examples mean you don't have to start coding from a blank page. You also have access to product and industry experts via technical support and application engineers, as well as an expansive user community via the MATLAB Answers and File Exchange sites on our web page.
We saw how apps can be used for interactive algorithm development and automatic MATLAB code generation, which boost productivity and allow for rapid prototyping. Furthermore, once you're ready to deploy your algorithms to embedded devices, hardware-targeted code generation can be used to save time and reduce coding errors.
You can get started today with our free, self-paced Onramp tutorial. This online, interactive tutorial uses hands-on exercises with automated assessments and feedback to teach you the essentials of MATLAB in just a couple of hours. From there you can build your skills with several other free, self-paced Onramps, with popular topics such as deep learning, image processing, and control design with Simulink.
If you'd like to dive deeper than the Onramps, we also offer a wide variety of self-paced trainings and instructor-led courses. These courses have typically been a mix of in-person online offerings. But this year, we've expanded our instructor-led online trainings, which have been very well received. These courses can also be customized to meet your specific needs.
And when time is critical, we also have consulting services available around the world. Our consulting is very white box, with the goal that your team owns and operates the resulting work. We customize services based on your needs to optimize your investment and ensure your success. Our consulting has helped many customers jumpstart their projects by applying our proven best practices, deep product knowledge, and broad technical experience.
You can learn more about our products and solutions on our website at mathworks.com. Thank you for your time and attention today.