What does this MATLAB code do?

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

blademan9999
Posts: 43
Joined: Sun May 01, 2011 5:18 am UTC

What does this MATLAB code do?

Postby blademan9999 » Wed Oct 24, 2018 12:05 am UTC

n=input('Please enter your choice: n= ');
negative=input('Please enter your choice: negative= ');
confidence=input('Please enter your choice: confidence= ');
pos=n-negative;
z = norminv(1-(1-confidence)/2);
phat = 1.0*pos/n;
value=(phat + z*z/(2*n) - z * sqrt((phat*(1-phat)+z*z/(4*n))/n))/(1+z*z/n);
kill=1-value;
fprintf('%.8f ', kill);

I made this code in MATLAB some time ago but I’ve forgotten what it does and can’t figure it out. What does it do.
Last edited by blademan9999 on Wed Oct 24, 2018 10:19 am UTC, edited 1 time in total.
http://officeofstrategicinfluence.com/spam/
That link kills spam[/size][/b][/u]

theoriok
Posts: 10
Joined: Fri Sep 30, 2016 12:27 pm UTC

Re: What does this code do?

Postby theoriok » Wed Oct 24, 2018 9:45 am UTC

Which language?

blademan9999
Posts: 43
Joined: Sun May 01, 2011 5:18 am UTC

Re: What does this MATLAB code do?

Postby blademan9999 » Wed Oct 24, 2018 10:19 am UTC

Matlab
http://officeofstrategicinfluence.com/spam/
That link kills spam[/size][/b][/u]

User avatar
Flumble
Yes Man
Posts: 2082
Joined: Sun Aug 05, 2012 9:35 pm UTC

Re: What does this MATLAB code do?

Postby Flumble » Wed Oct 24, 2018 7:08 pm UTC

Could you make some 3D plots of kill for a chosen n with negative=[0..n] (best be integers) and confidence=[-0.9..0.9]?

I have no idea. All I can see is that for large values of z (confidence approaching 1) kill approaches 1 (0 for large negative values) and for values near 0 kill approaches negative/n. So some conditional probability based on the confidence parameter, but no idea if it has a name or is written down correctly in the first place.

User avatar
phlip
Restorer of Worlds
Posts: 7557
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: What does this MATLAB code do?

Postby phlip » Thu Oct 25, 2018 2:11 am UTC

Judging mostly based on the variable names, I'm guessing it's some sort of confidence interval calculation...

Like, say you do a test 100 times, and get 75 successes. The thing you're testing probably has a probability of success somewhere around 3/4, but you can't be sure exactly where. But if you run that code and enter, for instance, 100; 75; -0.9 and then 100; 75; +0.9 you get the results 0.673 and 0.814... so you can be 90% sure that the real probability is somewhere between 67.3% and 81.4%.

At least, that's my half-remembered understanding of the theory. I don't recognise the actual formula, though. It's been a long time since I've done any stats (and even when I did, I didn't really understand the actual formulae... if you say the words "student's t test" to me, my eyes reflexively glaze over).

[edit]
Aha, I found it: Wilson score interval.

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 11 guests