Confidence Interval (CI) for a proportion (p) inside a table

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Confidence Interval (CI) for a proportion (p) inside a table

mils
Hi everyone,

I'm looking for a syntax/script that will allow me to calculate the confidence interval for a proportion inside a ctable.

I have the following data:

data list list / brand (f3.0) country (f8.0).
begin data
101       1
101       2
101       3
101       1
102       2
102       3
102       1
102       2
102       3
101       1
101       2
103       3
103       1
104       2
104       3
104       1
102       2
102       3
end data.

I've run the following table:

* Custom Tables.
CTABLES
  /VLABELS VARIABLES=brand country DISPLAY=LABEL
  /TABLE brand [C] BY country [COUNT F40.0, COLPCT.COUNT PCT40.1]
  /CATEGORIES VARIABLES=brand country ORDER=A KEY=VALUE EMPTY=EXCLUDE.

Ideally, I will like to end up with something like this

Count Column N % Inferior limit Superior Limit
      3 50.0%                 -6.6% 106.6%
      1 16.7%                -56.4% 89.7%
      1 16.7%                -56.4% 89.7%
      1 16.7%                 -56.4% 89.7%

inside the table show above.

Thanks in advance.


mils
Reply | Threaded
Open this post in threaded view
|

Re: Confidence Interval (CI) for a proportion (p) inside a table

Jon K Peck
You could do this with the STATS TABLE CALC extension command with a little work.  It allows you to add or replace columns in the table with arbitrary formula values.  (Adding new columns requires V21 or later, but for older versions you can create the columns with the TABLES command and overwrite their values and labels.)


Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
phone: 720-342-5621




From:        mils <[hidden email]>
To:        [hidden email]
Date:        10/31/2014 12:50 PM
Subject:        [SPSSX-L] Confidence Interval (CI) for a proportion (p) inside a table
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Hi everyone,

I'm looking for a syntax/script that will allow me to calculate the
confidence interval for a proportion inside a ctable.

I have the following data:

data list list / brand (f3.0) country (f8.0).
begin data
101       1
101       2
101       3
101       1
102       2
102       3
102       1
102       2
102       3
101       1
101       2
103       3
103       1
104       2
104       3
104       1
102       2
102       3
end data.

I've run the following table:

* Custom Tables.
CTABLES
 /VLABELS VARIABLES=brand country DISPLAY=LABEL
 /TABLE brand [C] BY country [COUNT F40.0, COLPCT.COUNT PCT40.1]
 /CATEGORIES VARIABLES=brand country ORDER=A KEY=VALUE EMPTY=EXCLUDE.

Ideally, I will like to end up with something like this

Count                 Column N %                 Inferior limit                 Superior Limit
     3                 50.0%                                  -6.6%                 106.6%
     1                 16.7%                                 -56.4%                 89.7%
     1                 16.7%                                 -56.4%                 89.7%
     1                 16.7%                                  -56.4%                 89.7%

inside the table show above.

Thanks in advance.






-----
mils
--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Confidence-Interval-CI-for-a-proportion-p-inside-a-table-tp5727755.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD


===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Confidence Interval (CI) for a proportion (p) inside a table

Jon K Peck
Here is an example using your table.  I put the CI surrounding the percentage, but that can be changed by adjusting the subscripts appropriately.
I used the simplest formula, which gives some impossible values with the very small counts in your example (you could add min/max functions if this is a problem for your real data), and there are many different ways to define proportion CIs, but this should give you the general idea.

Inserting the new columns requires Statistics 21 or later, but as I said before, you can create dummy columns and use replace mode for earlier versions.

* Custom Tables.
CTABLES
 /VLABELS VARIABLES=brand country DISPLAY=LABEL
 /TABLE brand [C] BY country [COUNT F40.0, COLPCT.COUNT PCT40.1]
 /CATEGORIES VARIABLES=brand country ORDER=A KEY=VALUE EMPTY=EXCLUDE.

STATS TABLE CALC SUBTYPE="customtable"  
/TARGET FORMULA="x[0] + (1.96 *math.sqrt((x[0]/100)*(1-(x[0]/100))/x[-1]))*100"  
    LOCATION="Column N %" REPEATLOC=YES LABEL="Upper Conf Int" MODE=AFTER
/FORMAT CELLFORMAT="##.#%" DECIMALS=2  INVALID="".

STATS TABLE CALC SUBTYPE="customtable"  
/TARGET FORMULA="x[0] - (1.96 *math.sqrt((x[0]/100)*(1-(x[0]/100))/x[-1]))*100"  
    LOCATION="Column N %" REPEATLOC=YES LABEL="Lower Conf Int" MODE=BEFORE
/FORMAT CELLFORMAT="##.#%" DECIMALS=2  INVALID="".


Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
phone: 720-342-5621




From:        Jon K Peck/Chicago/IBM@IBMUS
To:        [hidden email]
Date:        11/01/2014 06:23 AM
Subject:        Re: [SPSSX-L] Confidence Interval (CI) for a proportion (p) inside a table
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




You could do this with the STATS TABLE CALC extension command with a little work.  It allows you to add or replace columns in the table with arbitrary formula values.  (Adding new columns requires V21 or later, but for older versions you can create the columns with the TABLES command and overwrite their values and labels.)


Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
phone: 720-342-5621





From:        
mils <[hidden email]>
To:        
[hidden email]
Date:        
10/31/2014 12:50 PM
Subject:        
[SPSSX-L] Confidence Interval (CI) for a proportion (p) inside a table
Sent by:        
"SPSSX(r) Discussion" <[hidden email]>




Hi everyone,

I'm looking for a syntax/script that will allow me to calculate the
confidence interval for a proportion inside a ctable.

I have the following data:

data list list / brand (f3.0) country (f8.0).
begin data
101       1
101       2
101       3
101       1
102       2
102       3
102       1
102       2
102       3
101       1
101       2
103       3
103       1
104       2
104       3
104       1
102       2
102       3
end data.

I've run the following table:

* Custom Tables.
CTABLES
/VLABELS VARIABLES=brand country DISPLAY=LABEL
/TABLE brand [C] BY country [COUNT F40.0, COLPCT.COUNT PCT40.1]
/CATEGORIES VARIABLES=brand country ORDER=A KEY=VALUE EMPTY=EXCLUDE.

Ideally, I will like to end up with something like this

Count                 Column N %                 Inferior limit                 Superior Limit
    3                 50.0%                                  -6.6%                 106.6%
    1                 16.7%                                 -56.4%                 89.7%
    1                 16.7%                                 -56.4%                 89.7%
    1                 16.7%                                  -56.4%                 89.7%

inside the table show above.

Thanks in advance.






-----
mils
--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Confidence-Interval-CI-for-a-proportion-p-inside-a-table-tp5727755.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD


===================== To manage your subscription to SPSSX-L, send a message to
LISTSERV@... (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Confidence Interval (CI) for a proportion (p) inside a table

mils
In reply to this post by Jon K Peck
Hi Jon,

Thanks for your email. I've tried to find the extension, but so far I have not succeeded. Could you please point out the right direction/link so I can find it.

Thanks in advance.
mils