Android Application: GraphPlot

A Graphics App With Plotting and Regression

**GraphicPlot examples saved directly from the app as png files (equivalent to screen shots) and reduced 25% or 50% per dimension.**

GraphicPlot allows you to input data directly in comma separated pairs of data (x,y), pairs separated by semicolor or from a text file of comma separated values. Data is plotted and then linear or quadratic regression can be performed. Alternatively, an exponential fit can be attempted. A normal type curve can be plotted based on a set of data whose standard deviation and mean is calculated for you. This is a visual picture of the data distribution assuming it is normally distributed. Each data x is given a frequency of 1 for data that is not binned and shows up at y = 1.

Acknowledgments:

Some dialog Code adapted from:

http://code.google.com/p/afiledialog/

https://github.com/iPaulPro/aFileChooser

https://code.google.com/p/dialogfragmentdemo/

Tutorials:

http://www.mybringback.com/series/android-basics/

http://www.newthinktank.com/author/admin/

and many other sites

IDE: https://netbeans.org/ 7.3

**1. ** How do you get started? Input five pairs of real or makeup data on the input dialog or in a .csv file and open it and let the app plot them for you. Then select linear or quadratic fit to see how the fit looks. Play with different data sets to get a feel for the app.

**2. ** How do I get a larger size plot? Choose Menu Scaler and set to 0, 1, or 2 for available sizes.

**3. ** How do I set axes labels and graph title? Select the Menu item for each of these and input the text.

**4. **How do I adjust the X or Y Limits? Select the Menu item X,YLimits and input the values as 10, 25; for the X and Y limits.

**5. ** What if I want force through zero fit? The Force 0 label shows the slope of a force 0 fit.

**6. **What is the AF? The AF is the Hamilton agreement factor or crystallographic goodness of fit statistic that is the sum of the squares of the calculated minus observed over the observed squared then take the square root. It is a good measure of the model versus the data and should be 0.05 or less for a good fit with good quality data.

**7. ** How does the normal plot work? In most cases, a data set is obtained that is assumed to be normally distributed. The mean and the standard deviation are calculated and this determines the normal distribution. Select Menu then NormalFit and input the suggested 1.0,1.0,1.0;. The data points are shown along the x axis with a frequency of 1 since the data are collected as unique points. Alternatively, if the data were placed in "bins", frequency data would be added to the plot (see the example above where this was done). Nevertheless, the plot gives a visual picture of the measurements and their distribution about the mean. By "bins" I mean that certain ranges of x data could be lumped together to form a frequency of occurrence probably plotted at the mean of the range of the bin. How do you choose the bin size? There are rules of thumb to guide the choice such as twice the cube root of the number of data points, adjusted for the case at hand. For small data sets, the shape of the distribution is hard to verify. If you already have normalized data and know the mean,sigma, and a scale factor for your data then input these values and a plot shows the data with the curve defined by your values. In the case of binned data, the scale factor compensates for the lack of a data point at the mean so the normalized data is fitted by allowing the calculated curve to exceed 1.0 max by a small amount, e.g., 1.06. It can be determined interatively.

**8. ** How do you save the graphic plot canvas as an image? Select Menu Save As PNG and a new view will appear; then select the menu item to save the image.

**9.**Why does the app only show data in the first quadrant? The app features results for real data so positive numbers are the rule.

**10. **Do you include a weighted linear least squares fit? Now I have included one. The weighted fit is advantageous when there is a wide range of values of x that includes some small x and some large x especially when data spans three orders of magnitude or more. Weighting levels the relative importance of data points because otherwise large values will dominate the fit errors (because the absolute errors will be larger) and will be preferentially minimized whereas the interest might be in points closer to 0 such as using a calibration curve near the limit of detection. Using weighted fits helps to insure the smaller absolute measurements are given appropriate influence in determining the best fit. The weights are often the reciprocal of the variance for that measurement. Suppose each measurement had about a 10% error. A weighting factor of 1 over that error (1 / 0.1 * obsval) would give a smaller weight for the large value x and a larger weight for the small value x thus boosting the influence of small x values in the fit relative to large x values. The AF would also need to be redone using the weighting factors.
A useful approach is to try different fits and assess them in order to determine what result is appropriate and most useful. Never use a weighted regression without also evaluating the unweighted version to check for reasonableness. Weighting factors are either obtained by estimate or measurements and therefore also contain errors. Note that when the intercept is nonzero, the plot becomes unuseable somewhere in the region where x approaches zero in a situation like a calibration plot or whenever the logical inference is valid that a zero x implies a zero y. It is not unusual for an apparently linear plot to take on nonlinear character as it approaches zero. Results are strengthened if there are at least two data points below the point where an inference is made.

**11. **Where is the r squared statistic in the linear regressions? I prefer the AF but now I have added the statistic labeled RSQ to the output. The importance placed on a fit with r squared equal to 0.999 versus 0.997 seems disproportionate to me. There are a number of ways to assess goodness of fit and using the old eyeball should not be neglected. Use of weighting factors and introduction of additional parameters because of nonlinearity may be considered.

**11. **How about sample data? The app begins with sample data and a plot. Choose Menu Linear Fit and get the statistics for this one. Try weighted linear fit. For a couple more data examples, see http://www.lvdesignunlimited.com/bc/android/data.html.

Last updated: 10 January 2014