c14-4 (779579), страница 2

Файл №779579 c14-4 (Numerical Recipes in C) 2 страницаc14-4 (779579) страница 22017-12-27СтудИзба
Просмтор этого файла доступен только зарегистрированным пользователям. Но у нас супер быстрая регистрация: достаточно только электронной почты!

Текст из файла (страница 2)

Let Ni·denote the number of events for which the first variable x takes on its ith valueregardless of the value of y; N·j is the number of events with the jth value of yregardless of x. So we have14.4 Contingency Table Analysis of Two Distributions631where I and J are again the numbers of rows and columns, and N is the totalnumber of events. Cramer’s V has the pleasant property that it lies between zeroand one inclusive, equals zero when there is no association, and equals one onlywhen the association is perfect: All the events in any row lie in one unique column,and vice versa. (In chess parlance, no two rooks, placed on a nonzero table entry,can capture each other.)In the case of I = J = 2, Cramer’s V is also referred to as the phi statistic.The contingency coefficient C is defined assC=χ2χ2 + N(14.4.5)It also lies between zero and one, but (as is apparent from the formula) it can neverachieve the upper limit.

While it can be used to compare the strength of associationof two tables with the same I and J, its upper limit depends on I and J. Thereforeit can never be used to compare tables of different sizes.The trouble with both Cramer’s V and the contingency coefficient C is that,when they take on values in between their extremes, there is no very directinterpretation of what that value means. For example, you are in Las Vegas, and afriend tells you that there is a small, but significant, association between the color ofa croupier’s eyes and the occurrence of red and black on his roulette wheel. Cramer’sV is about 0.028, your friend tells you.

You know what the usual odds against youare (because of the green zero and double zero on the wheel). Is this associationsufficient for you to make money? Don’t ask us!#include <math.h>#include "nrutil.h"#define TINY 1.0e-30A small number.void cntab1(int **nn, int ni, int nj, float *chisq, float *df, float *prob,float *cramrv, float *ccc)Given a two-dimensional contingency table in the form of an integer array nn[1..ni][1..nj],this routine returns the chi-square chisq, the number of degrees of freedom df, the significancelevel prob (small values indicating a significant association), and two measures of association,Cramer’s V (cramrv) and the contingency coefficient C (ccc).{float gammq(float a, float x);int nnj,nni,j,i,minij;float sum=0.0,expctd,*sumi,*sumj,temp;sumi=vector(1,ni);sumj=vector(1,nj);nni=ni;nnj=nj;for (i=1;i<=ni;i++) {sumi[i]=0.0;Number of rowsand columns.Get the row totals.Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5)Copyright (C) 1988-1992 by Cambridge University Press.Programs Copyright (C) 1988-1992 by Numerical Recipes Software.Permission is granted for internet users to make one paper copy for their own personal use.

Further reproduction, or any copying of machinereadable files (including this one) to any servercomputer, is strictly prohibited. To order Numerical Recipes books,diskettes, or CDROMsvisit website http://www.nr.com or call 1-800-872-7423 (North America only),or send email to trade@cup.cam.ac.uk (outside North America).the data were drawn. There are several different ways of doing this. Two of themore common are called Cramer’s V and the contingency coefficient C.The formula for Cramer’s V issχ2V =(14.4.4)N min (I − 1, J − 1)632Chapter 14.Statistical Description of Datafor (j=1;j<=nj;j++) {sumi[i] += nn[i][j];sum += nn[i][j];}if (sumi[i] == 0.0) --nni;}Measures of Association Based on EntropyConsider the game of “twenty questions,” where by repeated yes/no questionsyou try to eliminate all except one correct possibility for an unknown object.

Betteryet, consider a generalization of the game, where you are allowed to ask multiplechoice questions as well as binary (yes/no) ones. The categories in your multiplechoice questions are supposed to be mutually exclusive and exhaustive (as are“yes” and “no”).The value to you of an answer increases with the number of possibilities thatit eliminates. More specifically, an answer that eliminates all except a fraction p ofthe remaining possibilities can be assigned a value − ln p (a positive number, sincep < 1). The purpose of the logarithm is to make the value additive, since (e.g.) onequestion that eliminates all but 1/6 of the possibilities is considered as good as twoquestions that, in sequence, reduce the number by factors 1/2 and 1/3.So that is the value of an answer; but what is the value of a question? If thereare I possible answers to the question (i = 1, .

. . , I) and the fraction of possibilitiesconsistent with the ith answer is pi (with the sum of the pi ’s equal to one), then thevalue of the question is the expectation value of the value of the answer, denoted H,H=−IXpi ln pi(14.4.6)i=1In evaluating (14.4.6), note thatlim p ln p = 0p→0(14.4.7)Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5)Copyright (C) 1988-1992 by Cambridge University Press.Programs Copyright (C) 1988-1992 by Numerical Recipes Software.Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copying of machinereadable files (including this one) to any servercomputer, is strictly prohibited.

To order Numerical Recipes books,diskettes, or CDROMsvisit website http://www.nr.com or call 1-800-872-7423 (North America only),or send email to trade@cup.cam.ac.uk (outside North America).Eliminate any zero rows by reducing the num}ber.for (j=1;j<=nj;j++) {Get the column totals.sumj[j]=0.0;for (i=1;i<=ni;i++) sumj[j] += nn[i][j];if (sumj[j] == 0.0) --nnj;Eliminate any zero columns.}*df=nni*nnj-nni-nnj+1;Corrected number of degrees of freedom.*chisq=0.0;for (i=1;i<=ni;i++) {Do the chi-square sum.for (j=1;j<=nj;j++) {expctd=sumj[j]*sumi[i]/sum;temp=nn[i][j]-expctd;*chisq += temp*temp/(expctd+TINY);Here TINY guarantees that any}eliminated row or column will}not contribute to the sum.*prob=gammq(0.5*(*df),0.5*(*chisq));Chi-square probability function.minij = nni < nnj ? nni-1 : nnj-1;*cramrv=sqrt(*chisq/(sum*minij));*ccc=sqrt(*chisq/(*chisq+sum));free_vector(sumj,1,nj);free_vector(sumi,1,ni);14.4 Contingency Table Analysis of Two Distributions633NijNNi·pi· =NN·jp·j =Npij =(outcomes of question x alone)(14.4.8)(outcomes of question y alone)The entropies of the questions x and y are, respectively,H(x) = −XH(y) = −pi· ln pi·iXp·j ln p·j(14.4.9)jThe entropy of the two questions together isH(x, y) = −Xpij ln pij(14.4.10)i,jNow what is the entropy of the question y given x (that is, if x is asked first)?It is the expectation value over the answers to x of the entropy of the restrictedy distribution that lies in a single column of the contingency table (correspondingto the x answer):H(y|x) = −Xpi·iX pijjpi·lnXpijpij=−pij lnpi·pi·i,j(14.4.11)Correspondingly, the entropy of x given y isH(x|y) = −Xjp·jX pijip·jlnXpijpij=−pij lnp·jp·ji,j(14.4.12)We can readily prove that the entropy of y given x is never more than theentropy of y alone, i.e., that asking x first can only reduce the usefulness of askingSample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5)Copyright (C) 1988-1992 by Cambridge University Press.Programs Copyright (C) 1988-1992 by Numerical Recipes Software.Permission is granted for internet users to make one paper copy for their own personal use.

Further reproduction, or any copying of machinereadable files (including this one) to any servercomputer, is strictly prohibited. To order Numerical Recipes books,diskettes, or CDROMsvisit website http://www.nr.com or call 1-800-872-7423 (North America only),or send email to trade@cup.cam.ac.uk (outside North America).The value H lies between 0 and ln I. It is zero only when one of the pi ’s is one, allthe others zero: In this case, the question is valueless, since its answer is preordained.H takes on its maximum value when all the pi ’s are equal, in which case the questionis sure to eliminate all but a fraction 1/I of the remaining possibilities.The value H is conventionally termed the entropy of the distribution given bythe pi ’s, a terminology borrowed from statistical physics.So far we have said nothing about the association of two variables; but supposewe are deciding what question to ask next in the game and have to choose betweentwo candidates, or possibly want to ask both in one order or another.

Suppose thatone question, x, has I possible answers, labeled by i, and that the other question,y, as J possible answers, labeled by j. Then the possible outcomes of asking bothquestions form a contingency table whose entries Nij , when normalized by dividingby the total number of remaining possibilities N , give all the information about thep’s. In particular, we can make contact with the notation (14.4.1) by identifying634Chapter 14.Statistical Description of Datai,j(14.4.13)i,j=1−1=0where the inequality follows from the factln w ≤ w − 1(14.4.14)We now have everything we need to define a measure of the “dependency” of yon x, that is to say a measure of association.

This measure is sometimes called theuncertainty coefficient of y. We will denote it as U (y|x),H(y) − H(y|x)(14.4.15)U (y|x) ≡H(y)This measure lies between zero and one, with the value 0 indicating that x and yhave no association, the value 1 indicating that knowledge of x completely predictsy. For in-between values, U (y|x) gives the fraction of y’s entropy H(y) that islost if x is already known (i.e., that is redundant with the information in x). In ourgame of “twenty questions,” U (y|x) is the fractional loss in the utility of questiony if question x is to be asked first.If we wish to view x as the dependent variable, y as the independent one, theninterchanging x and y we can of course define the dependency of x on y,H(x) − H(x|y)(14.4.16)U (x|y) ≡H(x)If we want to treat x and y symmetrically, then the useful combination turnsout to beH(y) + H(x) − H(x, y)(14.4.17)U (x, y) ≡ 2H(x) + H(y)If the two variables are completely independent, then H(x, y) = H(x) + H(y), so(14.4.17) vanishes.

Характеристики

Тип файла
PDF-файл
Размер
153,34 Kb
Материал
Тип материала
Высшее учебное заведение

Список файлов книги

Свежие статьи
Популярно сейчас
А знаете ли Вы, что из года в год задания практически не меняются? Математика, преподаваемая в учебных заведениях, никак не менялась минимум 30 лет. Найдите нужный учебный материал на СтудИзбе!
Ответы на популярные вопросы
Да! Наши авторы собирают и выкладывают те работы, которые сдаются в Вашем учебном заведении ежегодно и уже проверены преподавателями.
Да! У нас любой человек может выложить любую учебную работу и зарабатывать на её продажах! Но каждый учебный материал публикуется только после тщательной проверки администрацией.
Вернём деньги! А если быть более точными, то автору даётся немного времени на исправление, а если не исправит или выйдет время, то вернём деньги в полном объёме!
Да! На равне с готовыми студенческими работами у нас продаются услуги. Цены на услуги видны сразу, то есть Вам нужно только указать параметры и сразу можно оплачивать.
Отзывы студентов
Ставлю 10/10
Все нравится, очень удобный сайт, помогает в учебе. Кроме этого, можно заработать самому, выставляя готовые учебные материалы на продажу здесь. Рейтинги и отзывы на преподавателей очень помогают сориентироваться в начале нового семестра. Спасибо за такую функцию. Ставлю максимальную оценку.
Лучшая платформа для успешной сдачи сессии
Познакомился со СтудИзбой благодаря своему другу, очень нравится интерфейс, количество доступных файлов, цена, в общем, все прекрасно. Даже сам продаю какие-то свои работы.
Студизба ван лав ❤
Очень офигенный сайт для студентов. Много полезных учебных материалов. Пользуюсь студизбой с октября 2021 года. Серьёзных нареканий нет. Хотелось бы, что бы ввели подписочную модель и сделали материалы дешевле 300 рублей в рамках подписки бесплатными.
Отличный сайт
Лично меня всё устраивает - и покупка, и продажа; и цены, и возможность предпросмотра куска файла, и обилие бесплатных файлов (в подборках по авторам, читай, ВУЗам и факультетам). Есть определённые баги, но всё решаемо, да и администраторы реагируют в течение суток.
Маленький отзыв о большом помощнике!
Студизба спасает в те моменты, когда сроки горят, а работ накопилось достаточно. Довольно удобный сайт с простой навигацией и огромным количеством материалов.
Студ. Изба как крупнейший сборник работ для студентов
Тут дофига бывает всего полезного. Печально, что бывают предметы по которым даже одного бесплатного решения нет, но это скорее вопрос к студентам. В остальном всё здорово.
Спасательный островок
Если уже не успеваешь разобраться или застрял на каком-то задание поможет тебе быстро и недорого решить твою проблему.
Всё и так отлично
Всё очень удобно. Особенно круто, что есть система бонусов и можно выводить остатки денег. Очень много качественных бесплатных файлов.
Отзыв о системе "Студизба"
Отличная платформа для распространения работ, востребованных студентами. Хорошо налаженная и качественная работа сайта, огромная база заданий и аудитория.
Отличный помощник
Отличный сайт с кучей полезных файлов, позволяющий найти много методичек / учебников / отзывов о вузах и преподователях.
Отлично помогает студентам в любой момент для решения трудных и незамедлительных задач
Хотелось бы больше конкретной информации о преподавателях. А так в принципе хороший сайт, всегда им пользуюсь и ни разу не было желания прекратить. Хороший сайт для помощи студентам, удобный и приятный интерфейс. Из недостатков можно выделить только отсутствия небольшого количества файлов.
Спасибо за шикарный сайт
Великолепный сайт на котором студент за не большие деньги может найти помощь с дз, проектами курсовыми, лабораторными, а также узнать отзывы на преподавателей и бесплатно скачать пособия.
Популярные преподаватели
Добавляйте материалы
и зарабатывайте!
Продажи идут автоматически
7021
Авторов
на СтудИзбе
261
Средний доход
с одного платного файла
Обучение Подробнее