The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Help: Sum or average of Y on sub X range
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

redman

UK
59 Posts

Posted - 07/13/2016 :  07:07:38 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): Originpro 2016 sr2
Operating System: Win10 x64

I just wonder if there is a way to get the sum or average of Y according to a sub range of X (bin number of X)? For example, I have two types of data, [time (X, in min) - Temperature (Y)] and [azimuthal angle (X, in degree) - number of objects (Y)], how can I get the average temperature ever 5 (or 10, 15 etc.) min, or the total number of objects ever 5 or 10 deg of the azimuthal angle? Another complicated example is that If we have a student list of a school with name, grade, age, gender, etc. How can we obtain the total students in different grades, sub-age ranges etc.?
The aim is to achieve statistics of a column (or row) according to the bin size/number of another column (or row)
Thanks in advance!

Edited by - redman on 07/13/2016 12:24:08 PM

Hideo Fujii

USA
1582 Posts

Posted - 07/14/2016 :  1:41:14 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi redman,

> If we have a student list of a school with name, grade, age, gender, etc. How can we obtain
> the total students in different grades, sub-age ranges etc.?

So, you want to make the group descriptive statistics by a script instead of from menu
("Stats> Descriptive Stats> Stats on Columns"), right?

Unfortunately, the x-command colstats for the column descriptive statistics seems lacking
the options for group variables. If so, there is currently no straightforward way for that.

Then, how about the work-around by utilizing an Analysis Template like following?:
1) Determine how many nesting levels of group variables you want to have, and make a sample 
  worksheet with appropriate number of columns. 
2) Run the descriptive statistics of columns with the group variables setting the 
  recalculation mode to "Auto".
3) Save the workbook as an analysis template, say with name "myGroupStatsBook.ogw". 
  ("File> Save Workbook as Analysis Template" menu)
4) From your script, open the analysis template by:
    doc -o "C:\mydata\myGroupStatsBook.ogw";
  If desired you can put the names of group variables into their column's long names.
5) Copy the data into the opened workbook, and you get the aggregated statistics automatically.

There might be straightforward, and nicer solutions.

Hope this work-around helps.

--Hideo Fujii
OriginLab

Edited by - Hideo Fujii on 07/14/2016 5:20:07 PM
Go to Top of Page

yuki_wu

896 Posts

Posted - 07/15/2016 :  06:00:49 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi redman,

As Hideo said, there is currently no straightforward way for that, but I think you can use the functions of sumif, averageif and countif with loop by labtalk.

Here is an example.

It is supposed that you have a data of azimuthal angle in col(A) from 1 to 20 and a data of number of objects in col(B), you can get the total number of objects ever 5 deg of the azimuthal angle in col(C) by the scripts below:


//define a range to store the results
range nn=[Book1]1!3;
for(ii=1; ii<=4; ii++)  
{
//define the sum variable
double aa;
//calculate the end and start of each bin
double bb=(ii-1)*5; 
//calculate the sum value of each bin
aa=sumif(col(B),"col(A) > bb && col(A) <= (bb+5)"); 
nn[ii]=aa;
}




If you want get the average or count of each bin, you can replace sumif with averageif or countif. More details can be found in these pages:
http://www.originlab.com/doc/LabTalk/ref/Sumif-func
http://www.originlab.com/doc/LabTalk/ref/Averageif-func
http://www.originlab.com/doc/LabTalk/ref/Countif-func
Go to Top of Page

redman

UK
59 Posts

Posted - 07/15/2016 :  09:20:26 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks a lot for Yuki and Hedio's replies. Yuki's method is good enough for me. Wish this feature can be included in the future version.
Go to Top of Page

AmandaLu

439 Posts

Posted - 08/03/2016 :  05:14:58 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Please try X-Function reducexy. set subgroup = inc so you can calculate mean or sum of Y values in different X subranges. Here is the detailed document of reducexy:

http://www.originlab.com/doc/X-Function/ref/reducexy

Thanks,
Amanda
OriginLab Technical Service
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000