Author Topic: Totals and formulas don't take sigfig values into account?  (Read 5835 times)

D.

  • Professor
  • ****
  • Posts: 45
Totals and formulas don't take sigfig values into account?
« on: August 08, 2013, 03:10:30 AM »
Dear John,

I analyzed a bunch of pyroxenes. I noticed that when analytical results are displayed (and copied from the log or Analyze windows) with significant figures enabled, the wt% totals as well as calculated mineral formula values do not use the displayed elemental sigfig values....they appear to use the full precision values. So while you see the sigfig-applied elements/oxides, the totals and mineral formulas are not calculated from them.

The mineral formula values (and totals) output by the software thus cannot be directly published along with the sigfig-applied analyses, because the reviewer will find be a discrepancy (in some cases) if they tried to calculate the formula manually from the sigfig values. This obviously makes the formula output by the software less useful.

Is something on the cards in the future to have the sigfigs taken into account in the calculations? Or is there something I'm missing (which is ALWAYS possible)?

Thanks & cheers,
Deon.

John Donovan

  • Administrator
  • Emeritus
  • *****
  • Posts: 3304
  • Other duties as assigned...
    • Probe Software
Re: Totals and formulas don't take sigfig values into account?
« Reply #1 on: August 09, 2013, 01:37:47 PM »
Hi Deon,
You are correct.

Propagating the error to the totals is more difficult and I had not taken that extra effort as yet. The same goes for the formula values.

Since the formula values are normalized I think you could just apply the same number of significant digits. What do you think?
John J. Donovan, Pres. 
(541) 343-3400

"Not Absolutely Certain, Yet Reliable"

D.

  • Professor
  • ****
  • Posts: 45
Re: Totals and formulas don't take sigfig values into account?
« Reply #2 on: August 09, 2013, 05:23:41 PM »
I have an example where I am calculating Mg# for a set of analyses to plot zoning profiles. If I calculate the Mg# from the oxide sigfig-applied data I get 83.2 for the 1st analysis. If I use the output formula values I get Mg# 83.7, and applying the sigfigs to the formula values doesn't make it better. In the end the two zoning profiles look different (ignoring uncertainties). Some output values are fine, but some aren't. Likewise, it might be that in some cases your strategy will work fine, but there will probably be cases where it won't.

Thanks,
Deon.

John Donovan

  • Administrator
  • Emeritus
  • *****
  • Posts: 3304
  • Other duties as assigned...
    • Probe Software
Re: Totals and formulas don't take sigfig values into account?
« Reply #3 on: August 09, 2013, 06:09:33 PM »
I think the crucial point in your question is:

"(ignoring uncertainties)"

The last significant digit is going to have some uncertainty < 1.  So what fraction of the data will show a variance from the average significant digits? It should be a gaussian distribution. Correct?
john
John J. Donovan, Pres. 
(541) 343-3400

"Not Absolutely Certain, Yet Reliable"

D.

  • Professor
  • ****
  • Posts: 45
Re: Totals and formulas don't take sigfig values into account?
« Reply #4 on: August 11, 2013, 01:39:58 AM »
In conclusion, I think the important thing if you don't plan to incorporate the calculations into the software, is to indicate to users via the software manual that the totals and formula values are not publication ready. The intuitive expectation from my perspective as a user is that these specific values are publishable after processing in the software, but this is not the case, as we've discussed. Perhaps I missed a note already in one of the manuals?

Cheers,
Deon.

John Donovan

  • Administrator
  • Emeritus
  • *****
  • Posts: 3304
  • Other duties as assigned...
    • Probe Software
Re: Totals and formulas don't take sigfig values into account?
« Reply #5 on: August 11, 2013, 09:27:13 AM »
Hi Deon,
I see where you are going now.  Actually the sig fig calculation was originally added as a demonstration for students to show them that just because a computer prints a long line of digits one should not just accept them as is.

For publication in tables, I generally include 3 decimals and the standard deviations along with the detection limits and let the reader see the variance and sensitivity outright. I have never thought the sig fig printout suitable for publishing, though it could be with some additional work.

John J. Donovan, Pres. 
(541) 343-3400

"Not Absolutely Certain, Yet Reliable"

John Donovan

  • Administrator
  • Emeritus
  • *****
  • Posts: 3304
  • Other duties as assigned...
    • Probe Software
Re: Totals and formulas don't take sigfig values into account?
« Reply #6 on: August 11, 2013, 09:32:43 AM »
Actually, if you are interested, here is the code I'm using to calculate these significant figures. I'm sure it could be improved.

Function AnalyzeFormatAnalysisResult(row As Integer, chan As Integer, avalue As Single, analysis As TypeAnalysis, sample() As TypeSample) As String
' Format the value based on UseAutomaticFormatForResultsType (0=maximum decimals, 1=significant decimals)

ierror = False
On Error GoTo AnalyzeFormatAnalysisResultError

Dim percenterror As Single, detectionlimit As Single, wtscalratio As Single

' Format for maximum number of decimals
If UseAutomaticFormatForResultsType% = 0 Then
AnalyzeFormatAnalysisResult$ = MiscAutoFormatA$(avalue!)
End If

' Format for significant number of digits, based on counting statistics
If UseAutomaticFormatForResultsType% = 1 And (row% <> 0 And chan% <> 0) Then
percenterror! = ConvertAnalyticalSensitivity2!(row%, chan%, sample())
If ierror Then Exit Function
detectionlimit! = ConvertDetectionLimits2!(row%, chan%, RowUnkZAFCors!(), RowStdAssignsCounts!(), analysis, sample())
If ierror Then Exit Function
wtscalratio! = 1#
If analysis.CalData!(row%, chan%) <> 0# Then
wtscalratio! = analysis.WtsData!(row%, chan%) / analysis.CalData!(row%, chan%)  ' for oxide/atomic scaling
If chan% <= sample(1).LastElm% And sample(1).AtomicNums%(chan%) = 8 And sample(1).HydrogenStoichiometryFlag Then wtscalratio! = 1#      ' turn off scaling for hydrogen stoichiometry on excess oxygen
detectionlimit! = detectionlimit! / wtscalratio!
End If
AnalyzeFormatAnalysisResult$ = MiscAutoFormatQ$(percenterror!, detectionlimit!, avalue!)

' Save precision and detection limits (to module level arrays) for calculation of total (sum) statistics
tPrecision!(chan%) = Abs(percenterror!)
tDetection!(chan%) = detectionlimit!

' Save maximum precision and detection limits (to module level arrays) for calculation of average statistics
If Abs(percenterror!) < aPrecision!(chan%) Or aPrecision!(chan%) = 0# Then aPrecision!(chan%) = Abs(percenterror!)
If detectionlimit! < aDetection!(chan%) Or aDetection!(chan%) = 0# Then aDetection!(chan%) = detectionlimit!
End If

' Cannot format for significant digits, just do normal format
If UseAutomaticFormatForResultsType% = 1 And (row% = 0 Or chan% = 0) Then
AnalyzeFormatAnalysisResult$ = Format$(Format$(avalue!, f83$), a80$)
End If

Exit Function

' Errors
AnalyzeFormatAnalysisResultError:
MsgBox Error$, vbOKOnly + vbCritical, "AnalyzeFormatAnalysisResult"
ierror = True
Exit Function

End Function



Function MiscAutoFormatQ(precision As Single, detectionlimit As Single, treal As Single) As String
' Function to return an automatically formatted real number (based on passed percent precision and detection limit)

ierror = False
On Error GoTo MiscAutoFormatQError

Dim negative As Boolean
Dim nchar As Integer, i As Integer, j As Integer, k As Integer
Dim m As Integer, n As Integer
Dim temp As Single
Dim astring As String, bstring As String

' Check for zero precision or detection limit
If precision! = 0# Or detectionlimit! = 0# Then
MiscAutoFormatQ$ = Format$(Format$(treal!, f83$), a80$)
Exit Function
End If

' Determine number significant digits to save
nchar% = 1
If Abs(precision!) <= 10# Then nchar% = 2
If Abs(precision!) <= 1# Then nchar% = 3
If Abs(precision!) <= 0.1 Then nchar% = 4
If Abs(precision!) <= 0.01 Then nchar% = 5
If Abs(precision!) <= 0.001 Then nchar% = 6
If Abs(precision!) <= 0.0001 Then nchar% = 7

' Add one digit if greater than or equal to 100
If treal! >= 100# Then nchar% = nchar% + 1

' Round the value based on the percent precision
temp! = MiscAutoFormatZ!(precision!, treal!)
If ierror Then Exit Function

' Check greater or less than zero
If temp! < 0 Then negative = True

' Convert to decimal string
astring$ = CStr(temp!)

' Remove leading zero
If Left$(astring$, 1) = "0" Then astring$ = Mid$(astring$, 2)

' Find the decimal point
m% = InStr(astring$, ".")
If m% = 0 Then
astring$ = astring$ & ".000000"
m% = InStr(astring$, ".")
Else
astring$ = astring$ & "000000"
End If

' Find the first significant digit
n% = 1
For i% = 1 To Len(astring$)
If IsNumeric(Mid$(astring$, i%, 1)) Then
If Val(Mid$(astring$, i%, 1)) > 0 Then
n% = i%
Exit For
End If
End If
Next i%

' Set start of string
If m% < n% Then
j% = m%
Else
j% = n%
End If

' Load string starting with decimal point or first significant digit
k% = 0
bstring$ = vbNullString
For i% = j% To Len(astring$)
bstring$ = bstring$ & Mid$(astring$, i%, 1)
If IsNumeric(Mid$(astring$, i%, 1)) Then
If i% >= n% Then k% = k% + 1                    ' count number of significant digits loaded
If k% >= nchar% And k% >= m% Then Exit For
End If
Next i%

' Prefix with sign if necessary
If negative Then bstring$ = "-" & bstring$

' Set to "n.d.", if less than detection limit (scaled to data type)
If treal! < detectionlimit! Then bstring$ = "n.d."

' Format number
MiscAutoFormatQ$ = Format$(bstring$, a80$)

Exit Function

' Errors
MiscAutoFormatQError:
MsgBox Error$, vbOKOnly + vbCritical, "MiscAutoFormatQ"
ierror = True
Exit Function

End Function




Function MiscAutoFormatZ(precision As Single, treal As Single) As Single
' Function to return an automatically rounded real number (based on passed percent error)

ierror = False
On Error GoTo MiscAutoFormatZError

Dim nchar As Integer, exponent As Integer
Dim ntemp As Long
Dim mantissa As Single, temp As Single
Dim astring As String

' Check for zero
If treal! = 0# Then Exit Function

' Determine number significant digits to save
nchar% = 1
If Abs(precision!) <= 100# Then nchar% = 1
If Abs(precision!) <= 10# Then nchar% = 2
If Abs(precision!) <= 1# Then nchar% = 3
If Abs(precision!) <= 0.1 Then nchar% = 4
If Abs(precision!) <= 0.01 Then nchar% = 5
If Abs(precision!) <= 0.001 Then nchar% = 6
If Abs(precision!) <= 0.0001 Then nchar% = 7

If treal! >= 100# Then nchar% = nchar% + 1

' Convert number to normalized format between 0 and 1
astring$ = Format$(treal!, e137$)   ' note: e137$ = "+.0000000e+00;-.0000000e+00"
mantissa! = Mid$(astring$, 1, 9)
exponent% = Mid$(astring$, 11, 3)

' Calculate as integer based on number of significant digits
temp! = mantissa! * 10 ^ nchar%

' Round to nearest integer and truncate (positive and negative numbers)
temp! = temp! + 0.5

ntemp& = Int(temp!)
temp! = ntemp&

' Calculate back from integer significant digits
temp! = temp! / 10 ^ nchar%

' Apply saved exponent from normalization to recover
temp! = temp! * 10 ^ exponent

' Format number
MiscAutoFormatZ! = temp!

Exit Function

' Errors
MiscAutoFormatZError:
MsgBox Error$, vbOKOnly + vbCritical, "MiscAutoFormatZ"
ierror = True
Exit Function

End Function
John J. Donovan, Pres. 
(541) 343-3400

"Not Absolutely Certain, Yet Reliable"

UofO EPMA Lab

  • Professor
  • ****
  • Posts: 52
    • CAMCOR MicroAnalytical Facility
Re: Totals and formulas don't take sigfig values into account?
« Reply #7 on: July 20, 2015, 10:46:50 AM »
Hi John,

When exporting detection limits (i.e. via Output --> Save Specified User Format Output), would I be correct to say that detection limits are always reported in Wt% Elemental, regardless of whether you export the data in Wt% Oxide, Wt% Elemental, Atomic %, etc?

Thanks! (and apologies if I'm posting this in the wrong thread, but I wasn't sure where else to put this)

Hi Owen,
Yes, unless it says otherwise!

In the output file it says:  "Si CDL99"  which means the concentration detection limit at 99% (3 sigma) and the Si means Si elemental weight percent.

It's the same for the output to the log window:

Detection limit at 99 % Confidence in Elemental Weight Percent (Single Line):

ELEM:       Na      Si       K      Al      Mg      Fe      Ca      Mn      Ni       S      Cl      Ti       P       F
    97    .009    .007    .008    .007    .007    .026    .007    .017    .072    .004    .004    .014    .005    .084
    98    .009    .007    .009    .007    .007    .026    .007    .017    .078    .004    .004    .016    .005    .077
    99    .009    .007    .008    .007    .007    .026    .007    .017    .074    .004    .004    .015    .005    .078

AVER:     .009    .007    .008    .007    .007    .026    .007    .017    .075    .004    .004    .015    .005    .080
SDEV:     .000    .000    .000    .000    .000    .000    .000    .000    .003    .000    .000    .001    .000    .004
SERR:     .000    .000    .000    .000    .000    .000    .000    .000    .002    .000    .000    .000    .000    .002
« Last Edit: July 20, 2015, 10:51:14 AM by UofO EPMA Lab »
UofO MicroAnalytical Facility