Find x from user-input probability

3 views (last 30 days)
Matthew Piccolo
Matthew Piccolo on 18 Apr 2017
Answered: Mukul Rao on 24 Apr 2017
I am writing a script as part of a final project for one of my classes. This script allows a user to input a data array that is normally distributed, and writes back out lots of descriptive statistics, including mean, mode, variance, standard deviation, etc. At one point in the program, I am required to output x based on a user-input probability. I am not sure what x is, and the rubric and project description do not explain what x is. I am hoping someone here knows more about statistics than I do.
Right before the script to output x, I am required to output a z value based on a user-input probability. I'm assuming they are somehow related but I don't know what x is exactly. Here is the script for that:
prompt5={'Please enter a probability between 0 and 1.'};
name5 = 'Find Z with P';
defaultans5 = {'0.50'};
options.Interpreter = 'tex';
answer5 = inputdlg(prompt5,name5,[1 50],defaultans5,options);
p2_input = answer5{1};
p2_input = str2num(p2_input);
%code to find z with p goes here
if p2_input > 1
msgbox('Your probability value needs to be between 0 and 1.',...
'Error','warn')
elseif p2_input < 0
msgbox('Your probability value needs to be between 0 and 1.',...
'Error','warn')
else
z_p = @(p) -sqrt(2) * erfcinv(p*2);
zscore_p = z_p([p2_input]);
fprintf('The z score of probability %f is %f.\n',p2_input,zscore_p) %fprintf output
%allows user to input probability and then
%find a z value
So I understand z values well enough, but I'm not sure what x is or how it is related to the original data that the user inputs. I took statistics a long time ago, so I'm pretty fuzzy on the topics that aren't fairly obvious like z scores and probability.

Answers (1)

Mukul Rao
Mukul Rao on 24 Apr 2017
Hello,
Since it is unclear what "x" stands for, I can only take a guess. Most likely what you want to do is given an input value "P", output the value of a point "x" in your dataset for which "P" percent of the cases lie between [-inf,x]. This is the inverse of the distribution and can be computed with the "norminv" function for a normal distribution. Please refer the following link:

Products

Community Treasure Hunt

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

Start Hunting!