Correlation Analysis, Polynomial Fit, and Scatter Plot in Matlab

Scatter plots

Whether you are an engineering student, economics, medical, or a social science student, you obviously would need to plot data points at some point or the other in your analysis. One of the graphs that you would need to plot is scatter plots. However, have you ever cared to ask why you are using a scatter plot for a certain application? What the statement meant is that the plots that you have drawn all throughout your life have their own use. Most probably you drew them just to have some general knowledge. There is probably a lot that you do not know about scatter plots. This article will help you know about these kind of graphs.

What is a scatter plot?

Once in your lifetime, you must have plotted a graph that looks the same as the one explained below. If you surely did, that is a scatter plot.

A scatter plot is defined as a graph that shows a relationship between two data points. It could be between price and demand, price and supply, and weight and height. There must always be the x and y variables in the graph, just as in a plot.

It’s normally used when one of the parameters under the experiment can be controlled by the other one. That is, a change in one variable could cause a proportional change in the other variable. In short, there must be a dependent and independent variable.

What is the purpose of the scatter plot?

Why should you use a scatter plot in the first place? There are so many different types of plotting that you could use. But somehow many people prefer to use a scatter plot. First, scatter plots are used to plot continuous datasets. For this case, if you have a continuous dataset, you could use it.

Whenever you plot a scatter plot, the first goal is to check the relationship between two variables. This is very important if you want to know how a certain commodity is affected by the variation in the other one

Scatter plots could be used as a test of normality. Here we know what shape a normally distributed dataset should take. If the datasets are congregated at the middle and few at the ends, this could show that it’s normally distributed. If data is congregated at one end, we say that the data is normally distributed and it’s right-skewed or left-skewed.

Scatter plots have also been deployed to identify the correlation between different data points. A correlation is a measure of how a change in one variable affects another one. Statistically, correlation can be positive, negative, weak, strong, linear, and non-linear.

We can also use it in real life to identify anomalies. Anomalies in the graph can be construed as the outliers. This is the case when dataset is far away from most of the points.  The issue of anomalies is an important feature, especially in artificial intelligence.

Problems that might be found with scatter plots.

As a method of plotting, it has its challenges too. These are:

1. Over plotting.

Perhaps you must have heard most of the statisticians complaining about this very often.  What is it? Over plotting is the problem that is caused when too many data points overlap,which makes it difficult to differentiate what it is. In other graphs, such as pie charts, overplotting could be in the labels. Overplotting is something that is undesirable which makes the reading of the values difficult.

There are several factors that cause overplotting. The most common culprit is the large amount of data having a lot of similar values that you might have. However, the solution to this problem is by reducing the number of data points that you want to plot.

2. Confusing correlation and causal relationship

In some other cases, the challenge could arise from not plotting the data values.  It could be due to faulty interpretation of the values. A scatter plot usually gives you the impression that a change in one variable causes a change in the other. Thus it’s very easy to think that the change in one commodity is caused by the variation in other commodity. But it’s entirely possible that the correlation experience in the graph could be driven by another variable, not necessarily the one plotted. This is a common statistical phrase which says that correlation does not imply causality.

Scatter plots in Matlab

Matlab is a programming tool that is specifically meant to help data analysts, researchers, and scientists. It is equipped with nearly all what they would require. Besides, it’s easier to develop Matlab code than a code in other languages. Its documentation is simple and straightforward which will getyou started with making basic code within no time. It’s a tool that you must use to advance in your career.

If you want to draw very high quality and highly appealing scatter plots, then you should try Matlab. It has all the features that you would want to use whiledrawing a graph. Here are some of the things that you could apply while drawing ascatter plot in Matlab.

  1. Trend line. A trend line is important, especially if you want to identify the relationship in the data and use it for predictive purposes. The trend line is the line that most people commonly refer to as the line of best fit.
  2. Adding a third variable. Matlab enables you to add either a third categorical variable or a numeric variable. The third categorical variable can be encoded in the graph by using color. By categorical data, we mean the data sets that are like gender values and geographical values. Using a hue, we can show each point’s membership to a certain category. Or we could use shape to denote a point’s membership to a certain category. For a third numerical value, we can apply a hue or change the points.
  3. Highlighting a point of interest. If we want to highlight points, Matlab allows us to highlight the points by making them bold, adding labels to the points.
  4. Labeling the points in the graph. Sometimes to show our prowess, we would like the data points to have their names labeled beside them. This is very efficient when the data points in the graph are not many.

Matlab assignment experts.

We at Matlab assignment experts are well versed in Matlab. We can help you with any assignment related to Matlab with ease. We have a team of Matlab assignment experts who are well trained and passionate about using Matlab. They also have attained the best academic qualifications. Our diligent experts will help you in plotting attractive scatter plots. If needed we will even incorporate some of the features that we have stated above.

To get our services, contact us via email at info@matlabassignmentexperts.com. Use the subject line ‘help with scatter plots assignment.’ As soon as we get the email, we shall contact you with what you are supposed to do to get one of our experts working on the assignment solution. Once we have settled everything with you, we begin preparing the assignment solutions. You can wait for us to submit the assignment to your inbox. We always meet the deadline, so you should not worry about this. Be sure that you will score a high grade.

Contact us if you want to get the highest quality assignment help. We have helped students across the globe to score high grades. You, too, could be a beneficiary of our accomplished service if you contact us. We also help with homework and projects.

Here,the expert is trying to demonstrate to students the creation of a Matlab file for Correlation Analysis, Polynomial Fit, and Scatter Plot in Matlab. In this example loading of the data set is being done directly from excel. Here, variables are named in Matlab and names have been used in program. Correlation analysis has been done and the result is exported to excel.

SOLUTION : –

%% initialization

clc; clear; close all;

%% b

% reading excel files

m = xlsread(‘data_statistical_analysis_triamicinkids.xlsx’,’data’, ‘B2:F105’);

% setting variables

date = m(:,1);

brand_number = m(:,2);

DOLLLAR_SALES = m(:,3);

UNIT_SALES = m(:,4);

AVG_UNIT_PRICE = m(:,5);

%% c

figure; hold on;

plot(UNIT_SALES(1:52));

plot(UNIT_SALES(53:end));

xlabel(‘weeks’); ylabel(‘UNIT SALES’);

legend(‘Year 1’, ‘Year 2’);

% descriptive statistics

xlswrite(‘data_statistical_analysis_triamicinkids.xlsx’, min(UNIT_SALES(1:52)), ‘desc_stats’, ‘B3’);

xlswrite(‘data_statistical_analysis_triamicinkids.xlsx’, max(UNIT_SALES(1:52)), ‘desc_stats’, ‘B4’);

xlswrite(‘data_statistical_analysis_triamicinkids.xlsx’, mean(UNIT_SALES(1:52)), ‘desc_stats’, ‘B5’);

xlswrite(‘data_statistical_analysis_triamicinkids.xlsx’, var(UNIT_SALES(1:52)), ‘desc_stats’, ‘B6’);

xlswrite(‘data_statistical_analysis_triamicinkids.xlsx’, min(UNIT_SALES(53:end)), ‘desc_stats’, ‘C3’);

xlswrite(‘data_statistical_analysis_triamicinkids.xlsx’, max(UNIT_SALES(53:end)), ‘desc_stats’, ‘C4’);

xlswrite(‘data_statistical_analysis_triamicinkids.xlsx’, mean(UNIT_SALES(53:end)), ‘desc_stats’, ‘C5’);

xlswrite(‘data_statistical_analysis_triamicinkids.xlsx’, var(UNIT_SALES(53:end)), ‘desc_stats’, ‘C6’);

%% d

% correlation analysis of dollar sales

tmp = corrcoef(DOLLLAR_SALES(1:52), DOLLLAR_SALES(53:end));

xlswrite(‘data_statistical_analysis_triamicinkids.xlsx’, tmp, ‘year_corr’, ‘A2:B3’);

tmp = corrcoef(UNIT_SALES(1:52), UNIT_SALES(53:end));

xlswrite(‘data_statistical_analysis_triamicinkids.xlsx’, tmp, ‘year_corr’, ‘D2:E3’);

% yes they are strongly related …

%% e

figure; hold on;

plot(DOLLLAR_SALES(1:52));

plot(DOLLLAR_SALES(53:end));

xlabel(‘weeks’); ylabel(‘DOLLLAR SALES’);

legend(‘Year 1’, ‘Year 2’);

% dollar sales is decreasing in first half of year and then increasing in

% other half

saveas(gcf, ‘dollar sales’, ‘eps’);

%% f

figure;

p = polyfit(date(1:52), UNIT_SALES(1:52), 3);

subplot(121);

plot(date(1:52), polyval(p, date(1:52))); xlabel(‘date’); ylabel(‘UNIT SALES’); title(‘Year 1’);

p = polyfit(date(53:end), UNIT_SALES(53:end), 3);

subplot(122);

plot(date(53:end), polyval(p, date(53:end))); xlabel(‘date’); ylabel(‘UNIT SALES’); title(‘Year 2’);

%% g

figure;

p = polyfit(date, UNIT_SALES, 3);

subplot(121);

plot(date, polyval(p, date)); xlabel(‘date’); ylabel(‘UNIT SALES’); title(‘Degree 3’);

p = polyfit(date, UNIT_SALES, 6);

subplot(122);

plot(date, polyval(p, date)); xlabel(‘date’); ylabel(‘UNIT SALES’); title(‘Degree 6’);

%% h

figure;

subplot(121);

plot(UNIT_SALES(1:52), DOLLLAR_SALES(1:52), ‘*’);xlabel(‘UNIT SALES’); ylabel(‘DOLLLAR SALES’);  title(‘Year 1’);

subplot(122);

plot(UNIT_SALES(53:end), DOLLLAR_SALES(53:end), ‘*’);xlabel(‘UNIT SALES’); ylabel(‘DOLLLAR SALES’);  title(‘Year 2’);

% yes, there is a linear relationship

%% i

figure;

% year 1

x = UNIT_SALES(1:52);

y = DOLLLAR_SALES(1:52);

[x, index] = unique(x);

y = y(index);

p = polyfit(x, y, 1);

subplot(221);

plot(x, polyval(p, x));xlabel(‘UNIT SALES’); ylabel(‘DOLLLAR SALES’); title(‘Degree 1, Year 1’);

p = polyfit(x, y, 2);

subplot(222);

plot(x, polyval(p, x));xlabel(‘UNIT SALES’); ylabel(‘DOLLLAR SALES’); title(‘Degree 2, Year 1’);

% year 2

x = UNIT_SALES(53:end);

y = DOLLLAR_SALES(53:end);

[x, index] = unique(x);

y = y(index);

p = polyfit(x, y, 1);

subplot(223);

plot(x, polyval(p, x));xlabel(‘UNIT SALES’); ylabel(‘DOLLLAR SALES’); title(‘Degree 1, Year 2’);

p = polyfit(x, y, 2);

subplot(224);

plot(x, polyval(p, x));xlabel(‘UNIT SALES’); ylabel(‘DOLLLAR SALES’); title(‘Degree 2, Year 2’);