The following Igor code will produce the HMC menu and supply the commands Fix Graph and Add ChiSq Info. To install this in your experiment, copy the code and paste it in the default Procedure window of your experiment (you can bring this window forward with Control-M).
Alternatively, you can copy the text into a new procedure file, save it in the appropriate place, and then it will be available every time you run Igor. To do this,
| Macintosh, Igor Pro ≥ 6.1.0 | ~/Library/Application Support/Wavemetrics/Igor Pro 6 User Files/Igor Procedures/ |
|---|---|
| Macintosh, Igor Pro 6.0.x | There isn't a standard location; any folder will do, but you then need to create an alias to the folder from within the Igor Pro application folder. For forward compatibility, I recommend putting your procedure files in the same folder given above: ~/Library/Application Support/Wavemetrics/Igor Pro 6 User Files/Igor Procedures/ Then create an alias to this folder in the folder /Applications/Igor Pro Folder/Igor Procedures/ If Igor Pro is already running, you will need to quit and restart it for the menu to appear. |
| Windows, Igor Pro ≥ 6.1.0 | <My Documents>\WaveMetrics\Igor Pro 6 User Files\ | Windows, Igor Pro 6.0.x | There isn't a standard location; any folder will do, but you then need to create an shortcut to the folder from within the Igor Pro application folder. For forward compatibility, I recommend putting your procedure files in the same folder given above: <My Documents>\WaveMetrics\Igor Pro 6 User Files\ Then create a shortcut to this folder in the folder C:\Program Files\Wavemetrics\Igor Pro Folder\Igor Procedures\ If Igor Pro is already running, you will need to quit and restart it for the menu to appear. |
#pragma rtGlobals=1 // Use modern global access method.
// File: HMC.ipf
// Created: 22 January 2009
// Author: Peter N. Saeta
// Purpose: Provides some utility functions to make it easier to produce
// properly formatted graphs that contain necessary fitting information.
Menu "HMC"
"Fix Graph", HMCFixGraph()
"Add ChiSq Information", HMCAddChiSqInfoToPlot()
End
// HMCFixGraph()
//
// Adjust a graph to produce mirrored axes and symbols for data
Function HMCFixGraph()
ModifyGraph mirror=1,tick=2,standoff=0,mode=3,marker=19
SetAxis/A/N=2 left
SetAxis/A/N=2 bottom
End
// HMCAddChiSqInfoToPlot()
//
// Append chi-square information about a fit to
// a plot. This function assumes that you have just performed a fit,
// that you used error bars properly, that your wave holding the errors
// has a name that ends in "err" or "error", and that you asked for a textbox
// to display fit results. If you also requested a residual trace, it will attempt
// to add the error bars to the residuals.
Function HMCAddChiSqInfoToPlot()
NVAR/Z V_chisq
if ( ! NVAR_Exists( V_chisq ) )
DoAlert 0, "Call this function immediately after executing a fit"
return -1
endif
NVAR V_nheld, V_npnts, V_numNaNs, V_numINFs
WAVE W_coef
Variable DoF = V_npnts - V_numNaNs - V_numINFs
DoF -= ( numpnts( W_coef ) - V_nheld )
String al = AnnotationList(""), theAnnotation
Variable n, gotit = 0
// Look for the auto-generated annotation holding the fit description
for ( n = 0; n < ItemsInList( al ); n += 1 )
if ( cmpstr( "CF_", StringFromList( n, al )[0,2] ) == 0 )
gotit = 1
break
endif
endfor
if ( ! gotit )
return -1
endif
theAnnotation = StringFromList( n, al )
Variable probWorse
probWorse = 1-StatsChiCDF( V_chisq, DoF )
TextBox /C /N=$theAnnotation /F=0/B=1
String chisqText
sprintf chisqText, "\t\\F'Symbol'c\\]0\\S2\\M\t= %.03g (%.3g / DoF)", V_chisq, V_chisq/DoF
AppendText /N=$theAnnotation chisqText
sprintf chisqText, "\t\\f02P\\f00(>)\t= %.3g", probWorse
AppendText /N=$theAnnotation chisqText
// Set a zero line for the residuals axis
try
ModifyGraph zero(Res_left)=1, lblPos(Res_Left)=50,lblLatPos=0
catch
endtry
// Now try to add error bars to the residuals
try
GetWindow kwTopWin, wavelist // make a W_WaveList text wave
WAVE/T w = W_WaveList
Variable i, errWave = -1, resWave = -1
for (i = 0; i < DimSize( w,0 ); i += 1 )
if ( StringMatch( w[i][0], "*err" ) || StringMatch( w[i][0], "*error" ) )
errWave = i
elseif ( StringMatch( w[i][0], "Res_*" ) )
resWave = i
endif
endfor
if ( resWave >= 0 && errWave >= 0 )
String cmd
sprintf cmd, "ErrorBars %s,Y wave=(%s,%s)", w[resWave][0], w[errWave][0],w[errWave][0]
Execute cmd
endif
catch
endtry
End