## What does this MATLAB code do?

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

Moderators: phlip, Moderators General, Prelates

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

### What does this MATLAB code do?

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/

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

### Re: What does this code do?

Which language?

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

### Re: What does this MATLAB code do?

Matlab
http://officeofstrategicinfluence.com/spam/

Flumble
Yes Man
Posts: 2248
Joined: Sun Aug 05, 2012 9:35 pm UTC

### Re: What does this MATLAB code do?

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.

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

### Re: What does this MATLAB code do?

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).

Aha, I found it: Wilson score interval.

Code: Select all

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