Documente Academic
Documente Profesional
Documente Cultură
PROC
Procedimiento FREQ El procedimiento FREQ genera tablas de frecuencias de diferentes tipos, calcula medidas de asociacin y realiza el test de la Ji-cuadrado. Se emplea con variables nominales y ordinales y en variables intervalo o razn previamente discretizadas. La sintaxis general del PROC FREQ es:
PROC FREQ < options > ; BY variables ; EXACT statistic-options < / computation-options > ; OUTPUT < OUT=SAS-data-set > options ; TABLES requests < / options > ; TEST options ; WEIGHT variable < / option > ;
Sentencia
BY EXACT OUTPUT TABLES TEST WEIGHT
Descripcin
Calcula las frecuencias o las tablas para cada grupo definido por las variables de BY. Utiliza el clculo exacto de los estadsticos especificados. Especifica el DataSet que contendr el resultado de los estadsticos especificados. Se especifican las variables a las que se aplica el procedimiento y los test y medidas de asociacin. Especifica los test para las medidas de asociacin. Estos test se calculan asintticamente. Especifica la variable de ponderacin de cada observacin.
-1-
PROC
Opciones
DATA = COMPRESS FORMCHAR = NLEVELS NOPRINT ORDER = PAGE
Descripcin
Especifica el fichero de datos SAS que se utiliza en el procedimiento. La tabla se escribe en la pgina actual (de la ventana OUTPUT) Especifica el carcter para dibujar la tabla. Muestra el nmero de niveles para todas las variables de las TABLAS Suprime todas las salidad. Especifica el orden en el que se mostraran los resultados. Muestra una tabla por pgina.
BY variables;
Calcula las frecuencias o las tablas para cada grupo definido por las variables de BY. El fichero debe estar ordenado por las variables que aparecen en BY, en caso contrario debe especificarse en BY la opcin NOTSORTED o DESCENDING . La opcin NOTSORTED no significa que los datos estn desordenados, sino que estn organizados en grupos (en funcin de los valores de las variables de BY) y que estos grupos pueden no estar ordenados en orden alfabtico decreciente de valores numricos.
OUTPUT
Especifica el DataSet que contendr el resultado de los estadsticos especificados. En variables se especifican las variables a las que se aplica el procedimiento. Permite varios casos: variables x y z Calcula la tabla de frecuencias para las variables especificadas. variables x*y Calcula la tabla 2x2 de las variables x e y. Los valores de x definen las filas y los de y en las columnas. variables z*x*y Calcula la tabla 2x2 de las variables x e y, segn los diferentes valores de z.
TABLES variables
TEST WEIGHT
Permite especificar los test y las medidas de asociacin. Determina la variable de ponderacin.
-2-
PROC
Sentencia TABLES La instruccin TABLES permite crear tablas de diferentes formas, Escribir tables a*(b c); tables (a b)*(c d); tables (a b c)*d; tables a--c; tables (a--c)*d; Equivale a tables a*b a*c; tables a*c b*c a*d b*d; tables a*d b*d c*d; tables a b c; tables a*d b*d c*d;
Opciones de TABLES Alguna de las ms interesantes son: Para hacer Control statistical analysis Request tests and measures of classification agreement Request tests and measures of association produced by CHISQ, MEASURES, and CMH Set the confidence level for confidence limits Request Tarone's adjustment in the Breslow-Day test for homogeneity of odds ratios Request binomial proportion, confidence limits, and test for one-way tables Request binomial proportion, confidence limits, and test, and AGREE ALL Utilice la opcin
ALPHA= BDT
BINOMIAL
BINOMIALC
-3-
PROC
include a continuity correction Request BINOMIAL statistics, and include a continuity correction in the asymptotic confidence limits and test Request confidence limits for the MEASURES statistics Request all Cochran-Mantel-Haenszel statistics, adjusted relative risks, and odds ratios Request adjusted relative risks and odds ratios and CMH correlation statistic Request adjusted relative risks and odds ratios, CMH correlation, and row mean scores (ANOVA) statistic Specify convergence criterion to compute polychoric correlation Request Fisher's exact test for tables larger than 22 Request Jonckheere-Terpstra test Specify maximum number of iterations to compute polychoric correlation Request measures of association and their asymptotic standard errors Treat missing values as nonmissing Request polychoric correlation Request relative risk measures for 22 tables Request risks and risk differences for 22 tables Request risks and risk differences and include a continuity CHISQ
CL CMH
CMH1
CMH2
CONVERGE=
FISHER JT MAXITER=
MEASURES
-4-
PROC
correction Specify the type of row and column scores Specify expected frequencies for a one-way table chi-square test Specify expected proportions for a one-way table chi-square test Request Cochran-Armitage test for trend SCORES= TESTF=
TESTP=
TREND
Control additional table information Report each cell's contribution to the total Pearson chisquare statistic Display the cumulative column percentage in each cell Display the deviation of the cell frequency from the expected value for each cell Display the expected cell frequency for each cell Display missing value frequencies List all possible combinations of variable levels even when a combination does not occur Display percentage of total frequency on n-way tables when n>2 CELLCHI2
CUMCOL DEVIATION
TOTPCT
-5-
PROC
Control displayed output Specify the HTML contents link for crosstabulation tables Format the frequencies in crosstabulation tables Display two-way to n-way tables in list format Suppress the column percentage for each cell Suppress the cumulative frequencies and the cumulative percentages in one-way frequency tables and in list format Suppress the frequency count for each cell Suppress the percentage, row total percentage, and column total percentage in crosstabulation tables, or percentages and cumulative percentages in one-way frequency tables and in list format Suppress the display of tables but report the statistics Suppress the row percentage for each cell Suppress a log warning message for the asymptotic chisquare test Display the kappa coefficient weights Display the row and the column scores Use a field 8 positions wide to display the cell frequencies between 1.E7 and 1.E8 CONTENTS= FORMAT= LIST NOCOL NOCUM
NOFREQ NOPERCENT
-6-
PROC
Create an output data set Specify an output data set to contain variable values and frequency counts Include the cumulative frequency and cumulative percent for one-way tables in the output data set Include the expected frequency of each cell in the output data set Include the percentage of column frequency, row frequency, and two-way table frequency in the output data set OUT=
OUTCUM
OUTEXPECT
OUTPCT
-7-
PROC
Ejemplo1. Supongamos que del siguiente conjunto de datos se quiere obtener una tabla de frecuencia (la distribucin emprica) para cada variable del archivo. Solucin
data uno; input x y; cards; 2 3 1 4 1 2 1 3 2 2 2 3 1 4 2 3 ; proc freq data=uno; run;
Se obtiene la salida,
Procedimiento FREQ Frequencia Porcentaje x Frecuencia Porcentaje acumulada acumulado 1 4 50.00 4 50.00 2 4 50.00 8 100.00
Frequencia Porcentaje y Frecuencia Porcentaje acumulada acumulado 2 2 25.00 2 25.00 3 4 50.00 6 75.00 4 2 25.00 8 100.00
-8-
PROC
Ejemplo 2. Para obtener la tabla de frecuencias de una sola variable, por ejemplo x, la sintaxis es:
proc freq data=uno; tables x; run;
Procedimiento FREQ Frequencia Porcentaje x Frecuencia Porcentaje acumulada acumulado 1 4 50.00 4 50.00 2 4 50.00 8 100.00
Frequencia Porcentaje Pct fila Pct col 2 3 4 Total 1 1 1 2 4 12.50 12.50 25.00 50.00 25.00 25.00 50.00 50.00 25.00 100.00 2 1 3 0 4 12.50 37.50 0.00 50.00 25.00 75.00 0.00 50.00 75.00 0.00 Total 2 4 2 8 25.00 50.00 25.00 100.00
-9-
PROC
Ejemplo 4. Para obtener la tabla 2x2 de dos variables en funcin de una tercera la sintaxis es:
data uno; input x y z $; cards; 2 3 A 1 4 A 1 2 B 1 3 C 2 2 C 2 3 B 1 4 B 2 3 A ; proc freq data=uno; tables z*x*y; de x e y */ run;
Frequencia Porcentaje Pct fila Pct col 2 3 4 Total 1 0 0 1 1 0.00 0.00 33.33 33.33 0.00 0.00 100.00 . 0.00 100.00 2 0 2 0 2 0.00 66.67 0.00 66.67 0.00 100.00 0.00 . 100.00 0.00 Total 0 2 1 3 0.00 66.67 33.33 100.00
- 10 -
PROC
Frequencia Porcentaje Pct fila Pct col 2 3 4 Total 1 1 0 1 2 33.33 0.00 33.33 66.67 50.00 0.00 50.00 100.00 0.00 100.00 2 0 1 0 1 0.00 33.33 0.00 33.33 0.00 100.00 0.00 0.00 100.00 0.00 Total 1 1 1 3 33.33 33.33 33.33 100.00
Frequencia Porcentaje Pct fila Pct col 2 3 4 1 0 1 0 0.00 50.00 0.00 0.00 100.00 0.00 0.00 100.00 .
Total 1 50.00
100.00 100.00
- 11 -
PROC
Ejemplo 5
data uno; input x y; cards; 2 3 1 4 1 2 1 3 2 2 2 3 1 4 2 3 ; proc freq data=uno; tables x*y / chisq expected out=dos; proc print data=dos; run;
TABLE OF X BY Y X Y
Frequency| Expected | Percent | Row Pct | Col Pct | 2| 3| 4| Total ---------+--------+--------+--------+ 1 | 1 | 1 | 2 | 4 | 1 | 2 | 1 | | 12.50 | 12.50 | 25.00 | 50.00 | 25.00 | 25.00 | 50.00 | | 50.00 | 25.00 | 100.00 | ---------+--------+--------+--------+ 2 | 1 | 3 | 0 | 4 | 1 | 2 | 1 | | 12.50 | 37.50 | 0.00 | 50.00 | 25.00 | 75.00 | 0.00 | | 50.00 | 75.00 | 0.00 | ---------+--------+--------+--------+ Total 2 4 2 8 25.00 50.00 25.00 100.00
STATISTICS FOR TABLE OF X BY Y Statistic DF Value Prob -----------------------------------------------------Chi-Square 2 3.000 0.223 Likelihood Ratio Chi-Square 2 3.819 0.148 Mantel-Haenszel Chi-Square 1 0.875 0.350 Phi Coefficient 0.612 Contingency Coefficient 0.522 Cramer's V 0.612 Sample Size = 8 WARNING: 100% of the cells have expected counts less than 5. Chi-Square may not be a valid test.
- 12 -
PROC
DataSet dos
OBS 1 2 3 4 5
X 1 1 1 2 2
Y 2 3 4 2 3
COUNT 1 1 2 1 3
Aplica el PROC FREQ al DataSet work.uno 1. Crea la table x (filas) * y (columnas) 2. Calcula el p-value para los estadsticos asociados a la opcin CHISQ que son: a. Pearson chi-square b. likelihood-ratio chi-square c. Mantel-Haenszel chi-square tests 3. 4. Guarda el resultado el DataSet work.dos
- 13 -