2011_cap_02_03_proc_freq
Post on 09-Sep-2014
231 Views
Preview:
TRANSCRIPT
Statistical Analysis System PROC
- 1 -
Procedimiento FREQ
El procedimiento FREQ genera tablas de frecuencias de diferentes tipos, calcula medidas de
asociación y realiza el test de la Ji-cuadrado. Se emplea con variables nominales y ordinales y
en variables intervalo o razón previamente discretizadas.
La sintaxis general del PROC FREQ es:
Sentencia Descripción BY Calcula las frecuencias o las tablas para cada grupo definido por las
variables de BY.
EXACT Utiliza el cálculo exacto de los estadísticos especificados.
OUTPUT Especifica el DataSet que contendrá el resultado de los estadísticos especificados.
TABLES Se especifican las variables a las que se aplica el procedimiento y los test y medidas de asociación.
TEST Especifica los test para las medidas de asociación. Estos test se calculan asintóticamente.
WEIGHT Especifica la variable de ponderación de cada observación.
PROC FREQ < options > ; BY variables ;
EXACT statistic-options < / computation-options > ;
OUTPUT < OUT=SAS-data-set > options ;
TABLES requests < / options > ;
TEST options ;
WEIGHT variable < / option > ;
Statistical Analysis System PROC
- 2 -
PROC FREQ <opciones>;
Opciones Descripción DATA = Especifica el fichero de datos SAS que se utiliza en el procedimiento. COMPRESS La tabla se escribe en la página actual (de la ventana OUTPUT) FORMCHAR = Especifica el carácter para dibujar la tabla.
NLEVELS Muestra el número de niveles para todas las variables de las TABLAS NOPRINT Suprime todas las salidad. ORDER = Especifica el orden en el que se mostraran los resultados. PAGE Muestra una tabla por página.
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 opción NOTSORTED o DESCENDING . La opción NOTSORTED no significa
que los datos estén desordenados, sino que están organizados en grupos (en función de los
valores de las variables de BY) y que estos grupos pueden no estar ordenados en orden
alfabético decreciente de valores numéricos.
EXACT statistic-options < / computation-options > ;
Calcula los test exactos especificados en la opción de estadísticos.
OUTPUT Especifica el DataSet que contendrá el resultado de los
estadísticos especificados.
TABLES variables 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,
según los diferentes valores de z.
TEST Permite especificar los test y las medidas de asociación.
WEIGHT Determina la variable de ponderación.
Statistical Analysis System PROC
- 3 -
Sentencia TABLES
La instrucción TABLES permite crear tablas de diferentes formas,
Escribir Equivale a
tables a*(b c); tables a*b a*c;
tables (a b)*(c d); tables a*c b*c a*d b*d;
tables (a b c)*d; tables a*d b*d c*d;
tables a--c; tables a b c;
tables (a--c)*d; tables a*d b*d c*d;
Opciones de TABLES
Alguna de las más interesantes son:
Para hacer Utilice la opción
Control statistical analysis
Request tests and measures of classification agreement AGREE
Request tests and measures of association produced by
CHISQ, MEASURES, and CMH
ALL
Set the confidence level for confidence limits ALPHA=
Request Tarone's adjustment in the Breslow-Day test for
homogeneity of odds ratios
BDT
Request binomial proportion, confidence limits, and test for
one-way tables
BINOMIAL
Request binomial proportion, confidence limits, and test, and BINOMIALC
Statistical Analysis System PROC
- 4 -
include a continuity correction
Request BINOMIAL statistics, and include a continuity
correction in the asymptotic confidence limits and test
CHISQ
Request confidence limits for the MEASURES statistics CL
Request all Cochran-Mantel-Haenszel statistics, adjusted
relative risks, and odds ratios
CMH
Request adjusted relative risks and odds ratios and CMH
correlation statistic
CMH1
Request adjusted relative risks and odds ratios, CMH
correlation, and row mean scores (ANOVA) statistic
CMH2
Specify convergence criterion to compute polychoric
correlation
CONVERGE=
Request Fisher's exact test for tables larger than 2×2 FISHER
Request Jonckheere-Terpstra test JT
Specify maximum number of iterations to compute
polychoric correlation
MAXITER=
Request measures of association and their asymptotic
standard errors
MEASURES
Treat missing values as nonmissing MISSING
Request polychoric correlation PLCORR
Request relative risk measures for 2×2 tables RELRISK
Request risks and risk differences for 2×2 tables RISKDIFF
Request risks and risk differences and include a continuity RISKDIFFC
Statistical Analysis System PROC
- 5 -
correction
Specify the type of row and column scores SCORES=
Specify expected frequencies for a one-way table chi-square
test
TESTF=
Specify expected proportions for a one-way table chi-square
test
TESTP=
Request Cochran-Armitage test for trend TREND
Control additional table information
Report each cell's contribution to the total Pearson chi-
square statistic
CELLCHI2
Display the cumulative column percentage in each cell CUMCOL
Display the deviation of the cell frequency from the expected
value for each cell
DEVIATION
Display the expected cell frequency for each cell EXPECTED
Display missing value frequencies MISSPRINT
List all possible combinations of variable levels even when a
combination does not occur
SPARSE
Display percentage of total frequency on n-way tables when
n>2
TOTPCT
Statistical Analysis System PROC
- 6 -
Control displayed output
Specify the HTML contents link for crosstabulation tables CONTENTS=
Format the frequencies in crosstabulation tables FORMAT=
Display two-way to n-way tables in list format LIST
Suppress the column percentage for each cell NOCOL
Suppress the cumulative frequencies and the cumulative
percentages in one-way frequency tables and in list format
NOCUM
Suppress the frequency count for each cell NOFREQ
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
NOPERCENT
Suppress the display of tables but report the statistics NOPRINT
Suppress the row percentage for each cell NOROW
Suppress a log warning message for the asymptotic chi-
square test
NOWARN
Display the kappa coefficient weights PRINTKWT
Display the row and the column scores SCOROUT
Use a field 8 positions wide to display the cell frequencies
between 1.E7 and 1.E8
V5FMT
Statistical Analysis System PROC
- 7 -
Create an output data set
Specify an output data set to contain variable values and
frequency counts
OUT=
Include the cumulative frequency and cumulative percent for
one-way tables in the output data set
OUTCUM
Include the expected frequency of each cell in the output
data set
OUTEXPECT
Include the percentage of column frequency, row frequency,
and two-way table frequency in the output data set
OUTPCT
Statistical Analysis System PROC
- 8 -
Ejemplo1.
Supongamos que del siguiente conjunto de datos se quiere obtener una tabla de
frecuencia (la distribución empírica) para cada variable del archivo.
Solución
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
Statistical Analysis System PROC
- 9 -
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;
Ejemplo 3.
Para obtener la tabla 2x2 de dos variables la sintaxis es:
proc freq data=uno;
tables x*y; /* Los valores de x están en fila y los de y en
columna */
run;
Procedimiento FREQ
Frequencia Porcentaje
x Frecuencia Porcentaje acumulada acumulado
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
1 4 50.00 4 50.00
2 4 50.00 8 100.00
Procedimiento FREQ
Tabla de x por y
x y
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
Statistical Analysis System PROC
- 10 -
Ejemplo 4.
Para obtener la tabla 2x2 de dos variables en función 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; /* Para cada valor de z se obtiene una tabla 2x2
de x e y */
run;
Sistema SAS
Procedimiento FREQ
Tabla 1 de x por y
Controlando para z=A
x y
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
Statistical Analysis System PROC
- 11 -
Tabla 2 de x por y
Controlando para z=B
x y
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
Procedimiento FREQ
Tabla 3 de x por y
Controlando para z=C
x y
Frequencia‚
Porcentaje‚
Pct fila ‚
Pct col ‚ 2‚ 3‚ 4‚ Total
ƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆ
1 ‚ 0 ‚ 1 ‚ 0 ‚ 1
‚ 0.00 ‚ 50.00 ‚ 0.00 ‚ 50.00
‚ 0.00 ‚ 100.00 ‚ 0.00 ‚
‚ 0.00 ‚ 100.00 ‚ . ‚
ƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆ
2 ‚ 1 ‚ 0 ‚ 0 ‚ 1
‚ 50.00 ‚ 0.00 ‚ 0.00 ‚ 50.00
‚ 100.00 ‚ 0.00 ‚ 0.00 ‚
‚ 100.00 ‚ 0.00 ‚ . ‚
ƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆ
Total 1 1 0 2
50.00 50.00 0.00 100.00
Statistical Analysis System PROC
- 12 -
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.
Statistical Analysis System PROC
- 13 -
DataSet dos
OBS X Y COUNT PERCENT
1 1 2 1 12.5
2 1 3 1 12.5
3 1 4 2 25.0
4 2 2 1 12.5
5 2 3 3 37.5
proc freq data=uno; Aplica el PROC FREQ al DataSet ‘work.uno’
tables x*y / chisq expected
out=dos;
1. Crea la table x (filas) * y (columnas) 2. Calcula el p-value para los estadísticos
asociados a la opción 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’
top related