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
 All Forums
 Origin Forum
 Origin Forum
 weight factor for histograms

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
Michael Sommer Posted - 08/09/2003 : 04:08:36 AM
Hi there,

I would like to calculate histograms with a "weight factor" for each value, which means the counts of identical values should be included in the calculation procedure for a histogram / probability distribution.

Counts are available in an additional column in the worksheet.
Example:

value counts
2 5
3 10
4 4
5 125

Anybody who can help me ?

Michael


3   L A T E S T    R E P L I E S    (Newest First)
Iris_Bai Posted - 05/18/2009 : 11:34:18 PM
Hi Bernhard,

Please regerence to the following function:


void PlotWeightedHistogram()
{
	// assume the active worksheet has two columns, first column contains value data, another column contains counts data.
	Worksheet wks = Project.ActiveLayer(); 
	if( wks )
	{
		DataRange dr;
		dr.Add(wks, 0, "Range1");
		dr.Add(wks, 1, "Range2");
		
		vector 		vValues;
		vector		vCounts;
		dr.GetData(&vValues, 0); // 1st range for Values data
		dr.GetData(&vCounts, 1); // 2nd range for Counts data
		
		vector vData;
		for(int ii=0; ii<vCounts.GetSize(); ii++)
		{
			vector vTemp;
			vTemp.SetSize(vCounts[ii]);
			vTemp = (double)vValues[ii];
			vData.Append(vTemp);			
		}
		
		// add a new column and put data from vData to it
		DataRange dr2;
		dr2.Add(wks, wks.AddCol(), "X");
		dr2.SetData(vData);
		
		// plot histogram
		GraphPage gp;
		gp.Create("HIST"); // HIST is the graph template for histogram plot
		
		GraphLayer gl = gp.Layers(-1); // get active layer
		int index = gl.AddPlot(dr2, IDM_PLOT_HISTOGRAM_TYPE);
		if(index >= 0)
		{
			out_str("Successfully plot histogram");
			gl.Rescale();
		}		
	}
}


Iris
benderrr Posted - 05/11/2009 : 10:33:49 AM
Hi,

I have exactly the same problem of creating a weighted histogram. However, as Greg had already indicated, the script is too slow for my data (and RAM memory on my machine is insufficient). Therefore, and since the problem was discussed more than 5 years ago - is there any faster method, or a routine implemented in newer versions of Origin which can be used to attack the problem?

Thanks in advance,

Bernhard
greg Posted - 08/20/2003 : 5:00:02 PM
Here's a "brute force" approach:

// BEGIN SCRIPT
get %C -e end; // How many "values"?
colnum = wks.c1 + 1; // Which one is the "count" column?
wo -a 1; // Add a new column
row = 1; // Begin with row 1
loop(ii,1,end) { // For each "value"
val = %C[ii]; // Read the current "value"
count = wcol(colnum)[ii]; // Read the "count"
repeat count { // For "count" number of times
wcol(wks.ncols)[row] = val; // Store current "value"
row++; // Increment row
}
}
wo -s; // deselect worksheet
wo -s wks.ncols 0 wks.ncols 0; // Select our new column
run.section(Plot,Histogram); // Run the Plot Histogram script
// END SCRIPT

With your "value" column highlighted (and your "counts" in the next column to the right), run the above script.

For large "counts", the above script may get P - A - I - N - F - U - L - L - Y S - L - O - W, so you might want to go with an OriginC version. (I leave that as an exercise.. )


The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000