statistics using awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting statistics using awk
# 1  
Old 05-31-2011
statistics using awk

Hi,

I have 3 columns in a file listed below.


X Y X/(X+Y)
Code:
1    1    0.5
1    1    0.5
4    1    0.8
1    1    0.5
6    1    0.857142857
1    1    0.5
23    1    0.958333333


Now I want to find confidence interval using the formula for each row.

Code:
(p-2 sqrt p(1-p)/(x+y), p+2 sqrt p(1-p)/(x+y)) =(a,b)

where p = x/(x+y) already calculated in column 3 of the file..

I want the values(a,b) to be placed in column 4.

Thanks,

Diya

Last edited by vgersh99; 05-31-2011 at 02:55 PM.. Reason: code tags, please!
# 2  
Old 05-31-2011
Code:
 nawk '{a=$3-2*sqrt($3*(1-$3)/($1+$2));b=$3+2 * sqrt($3*(1-$3)/($1+$2)); print $0, a","b}' myFile

# 3  
Old 05-31-2011
Hi,

Thanks for the reply,


Firstly I cannot run using nawk as it says command not found.Probably I have to install it on my Linux machine.

When I ran the command with awk it generated me the following error.


Code:
awk '{a=$3-2*sqrt($3*(1-$3)/($1+$2));b=$3+2 * sqrt($3*(1-$3)/($1+$2)); print $0, a","b}' confi.txt
awk: (FILENAME=confi.txt FNR=1) fatal: division by zero attempted

Thanks,

Last edited by vgersh99; 05-31-2011 at 03:20 PM.. Reason: please start using code tags!
# 4  
Old 05-31-2011
given myFile:
Code:
1    1    0.5
1    1    0.5
4    1    0.8
1    1    0.5
6    1    0.857142857
1    1    0.5
23    1    0.958333333

the following:
Code:
nawk '{a=$3-2*sqrt($3*(1-$3)/($1+$2));b=$3+2 * sqrt($3*(1-$3)/($1+$2)); print $0, a","b}' myFile

produces:
Code:
1    1    0.5 -0.207107,1.20711
1    1    0.5 -0.207107,1.20711
4    1    0.8 0.442229,1.15777
1    1    0.5 -0.207107,1.20711
6    1    0.857142857 0.592623,1.12166
1    1    0.5 -0.207107,1.20711
23    1    0.958333333 0.876755,1.03991

What's your data file look like?
You probably need to cover the case where '$1+$2' results in '0'
# 5  
Old 05-31-2011
Thanks.. It worked.. I was giving the header line so it did not work..
# 6  
Old 05-31-2011
Quote:
Originally Posted by Diya123
Thanks.. It worked.. I was giving the header line so it did not work..
You might want to make the precedences of operators a little bit more explicit - based on YOUR understanding of the formulae:
Code:
a=($3-2)*sqrt($3*(1-$3)/($1+$2))
OR
a=$3-(2*sqrt($3*(1-$3)/($1+$2)))

and the same goes for the 'sqrt' and the others.....
# 7  
Old 05-31-2011
Quote:
Originally Posted by Diya123
Firstly I cannot run using nawk as it says command not found.Probably I have to install it on my Linux machine.
Having Linux means you have GNU awk, meaning nawk isn't necessary. This is why it's always a good idea to say what your OS is when you ask a question...
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Need optimized awk/perl/shell to give the statistics for the Large delimited file

I have a file size is around 24 G with 14 columns, delimiter with "|" My requirement- can anyone provide me the fastest and best to get the below results Number of records of the file First column and second Column- Unique counts Thanks for your time Karti ------ Post updated at... (3 Replies)
Discussion started by: kartikirans
3 Replies

2. Shell Programming and Scripting

Text statistics

Hello every body if I want to get the following statistics from a text file 1- sorted the n frequent words 2- sorted the n frequent characters 3- sorted the n frequent diagrams (tow letter together like th OR he) 4- sorted frequent n trigrams like (the OR all etc. ) 5- any character... (10 Replies)
Discussion started by: khaled79
10 Replies

3. UNIX for Dummies Questions & Answers

Any way to get process statistics?

Hi, Can someone advise what "generic" command can I use to show statistics of a process or a running script/process? For example, I want to know how many hours/minutes it's taken to run or has been running, how much CPU it used and how much memory it used or uses. I want to be able to... (2 Replies)
Discussion started by: newbie_01
2 Replies

4. Shell Programming and Scripting

awk based script to print the "mode(statistics term)" for each column in a data file

Hi All, Thanks all for the continued support so far. Today, I need to find the most occurring string/number(also called mode in statistics terminology) for each column in a data file (.csv type). For one column of data(1.txt) like below Sample 1 2 2 3 4 1 1 1 2 I can find the mode... (6 Replies)
Discussion started by: ks_reddy
6 Replies

5. Shell Programming and Scripting

Awk getting statistics of a grid file,

Hi , I have the following file which is basically a grid (has more than 100000 rows) LLL1 PPP1 LLL1 PPP2 LLL1 PPP3 ............... LLL1 5500 ..... LLL2 PPP1 LLL2 PPP2 LLL2 PPP3 ............... LLL1 5500 ..... L100 PPP1 L100 PPP2 L100 PPP3 ............... 2100 5500... (6 Replies)
Discussion started by: alex2005
6 Replies

6. Shell Programming and Scripting

AWK- extracting values from columns, saving them and gettins statistics

Hello, I am obviously quite new to unix and awk. I need to parse certain columns of a file (delimited by spaces), and somehow save the value of this column somewhere, together with the value of the column just after it (by pairs; so something like ). I'm then supposed to count the times that... (9 Replies)
Discussion started by: acsg
9 Replies

7. Shell Programming and Scripting

Analyze Statistics

I have a file which contains records in the format of 2006-08-25 12:06:13|ABC|93 2006-08-25 12:45:55|ABC|203 2006-08-25 01:48:19|DEF|156 2006-08-25 01:49:09|ABC|12798 2006-08-25 02:49:59|GHL|4109 2006-08-25 03:50:50|DEF|234 where the format is "arrive time"|"message type"|"processing... (3 Replies)
Discussion started by: mpang_
3 Replies

8. Programming

Server Statistics ?

I'm trying to write a C program to view server statistics such as: - server general information - CPU usage - memory usage - running processes Cany anybody gives me hints on those system calls ?? ps: I'm using Tru64 unix (6 Replies)
Discussion started by: Agent007
6 Replies
Login or Register to Ask a Question