93 views (last 30 days)

Hi.

I know how to get a variance in matlab, but I want it to be written as a percentage.

how do I convert the variance that I got to percentage writting way?

Cameron B
on 19 Jan 2020

Edited: Cameron B
on 19 Jan 2020

You would probably use the coefficient of variation. Coefficient of variation is the standard deviation divided by the mean and it’s units are in percent. And because variance is just the standard deviation squared, we only need to calculate the average now. So for you it would be something like this

%lets assume you calculated the variance of some variable x called var_x

CoV_x = 100*sqrt(var_x)/mean(x);

Cameron B
on 19 Jan 2020

I’d use

%assuming x is your variable

CoV_x = 100*std(x)/mean(x); %this is in units of percentage

John D'Errico
on 19 Jan 2020

Edited: John D'Errico
on 19 Jan 2020

A percentage of what? Percentage always implies you are comparing one number to another. That is, suppose you have some variable X, where X has units U_x (whatever are the units on X, perhaps feet or meters, etc.). The variance of X has units of U_x^2, thus feet^2, meters^2, etc. As such, you cannot compare the variance of X to X directly as a percentage.

Why cannot you do that? Because percentages must always be unit-less. That is, lacking any units at all. This is important, because you could always do a unit conversion on X, converting meters to centimeters, perhaps. The result of doing so is the ratio of var(X)/X now has units, and that ratio will depend on the units of X. Again, that would be meaningless.

What can you do? You might compare two variances. Thus compare the variance of X to the variance of Y, where both X and Y have the same units. Now it makes sense to consider the two in comprison, and I could talk about var(X)/var(Y)*100. So now we would indeed have a true percentage.

But my point is, you need to remember that a valid percentage always lacks units.

What else can you do? You can think of a standard deviation in a percentage sense. Thus, it makes sense to think about the standard deviation of X relative to the value of X itself (or perhaps, the mean of X.) That is, something like std(X)/mean(X)*100 is a unitless parameter, where we can talk about how large that standard deviation is compared to X itself. Why does this work, when it fails with the variance? It works, because that percentage stays identically the same under a change of units. That is, change the units on X from meters to centimeters, and the ratio std(X)/mean(X)*100 will be mathematically the same value. This is why things like a coefficient of variation make sense mathematically. For that matter, a correlation coefficient is already in a ratio form, lacking any units at all.

Just for kicks, lets try an example:

Xm = rand(1,10); % assume that Xm has units of meters.

Xcm = Xm*100; % Xcm has units of centimeters

std(Xcm)./mean(Xcm)*100

ans =

50.1117

std(Xm)./mean(Xm)*100

ans =

50.1117

The percentage here is thus an invariant under change of units, as it should be. That will not be true if we look at a ratio of the variance to the mean. And no such computation should ever vary, regardless if we used a ruler to make our measurements based on meters, inches, or for that matter, furlongs.

As I suggested above, variance ratios still work nicely in this context. That is, suppose Xm and Ym were measured in meters. But had we changed the ruler to read out in centimeters, then the computations:

var(Xm)/var(Ym)*100

var(Xm*100)/var(Ym*100)*100

are mathematically the same. It matters not what variation of ruler we use. Percentage is a unitless parameter.

Opportunities for recent engineering grads.

Apply TodayFind the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
## 0 Comments

Sign in to comment.