Fit experimental volumes and heat capacities using regression equations. Possible models include the HelgesonKirkhamFlowers (HKF) equations of state, or other equations defined using any combination of terms derived from the temperature, pressure and thermodynamic and electrostatic properties of water and/or userdefined functions of temperature and pressure.
1 2 3 4 5 6 7 
exptdata 
dataframe, experimental data 
var 
character, name(s) of variables in the regression equations 
T.max 
numeric, maximum temperature for regression, in degrees Kelvin 
T 
numeric, temperature in degrees Kelvin 
P 
numeric, pressure in bars 
... 
arguments defining additional properties which variables are a function of 
T.plot 
numeric, upper limit of temperature range to plot 
fun.legend 
character, where to place legend on plot 
coefficients 
dataframe, coefficients to use to make line on plot 
coeff 
numeric, value of equation of state parameter for plot legend 
species 
character, name of aqueous species 
property 
character, Cp or V 
EOSregress
uses lm
to regress the experimental heat capacity or volume data in exptdata
, which is a data frame with columns T (temperature in degrees Kelvin), P (pressure in bars), and Cp or V (heat capacity in cal/mol.K or volume in cm3/mol).
Only data below the temperature of T.max
are included in the regression.
The regression formula is specified by a vector of names in var
.
The names of the variables can be any combination of the following (listed in the order of search): variables listed in the following table, any available property of water
(e.g. V, alpha, QBorn), or the name of a function that can be found using get
in the default environment (e.g. a function defined by the user in the global environment; the arguments of the function should be T
and P
; see example).
T  T (temperature) 
P  P (pressure) 
TTheta  (TTheta) (Theta = 228 K) 
invTTheta  1/(TTheta) 
TTheta2  (TTheta)^2 
invTTheta2  1/(TTheta)^2 
invPPsi  1/(P+Psi) (Psi = 2600 bar) 
invPPsiTTheta  1/((P+Psi)(TTheta)) 
TXBorn  TX (temperature times X Born function) 
drho.dT  drho/dT (temperature derivative of density of water) 
V.kT  V.kT (volume times isothermal compressibility of water) 
EOSvar
calculates the value of the variable named var
(defined as described above) at the specified T
(temperature in degrees Kelvin) and P
(pressure in bars).
This function is used by EOSregress
to get the values of the variables used in the regression.
EOScalc
calculates the predicted heat capacities or volumes using coefficients provided by the result of EOSregress
, at the temperatures and pressures specified by T
and P
.
EOSplot
takes a table of data in exptdata
, runs EOSregress
and EOScalc
and plots the results.
The experimental data are plotted as points, and the calculated values as a smooth line.
The point symbols are filled circles where the calculated value is within 10% of the experimental value; open circles otherwise.
EOSlab
produces labels for the variables listed above that can be used as.expression
s in plots.
The value of coeff
is prefixed to the name of the variable (using substitute
, with a multiplication symbol).
For the properties listed in the table above, and selected properties listed in water
, the label is formatted using plotmath
expressions (e.g., with italicized symbols and Greek letters).
If var
is a userdefined function, the function can be given a label attribute to provide plotmath
style formatting; in this case the appropriate multiplication or division symbol should be specified (see example below).
EOScoeffs
retrieves coefficients in the HelgesonKirkhamFlowers equations from the thermodynamic database (thermo$obigt
) for the given aqueous species
.
If the property
is Cp, the resulting data frame has column names of (Intercept), invTTheta2 and TX, respectively holding the coefficients c1, c2 and omega in the equation Cp = c1 + c2/(TTheta)^2 + omega*TX.
If the property
is V, the data frame has column names of (Intercept), invTTheta and Q, respectively holding the coefficients sigma, xi and omega in V = sigma + xi/(TTheta)  omega*Q.
Here, sigma and xi are calculated from a1, a2, a3 and a4 in thermo$obigt
at the pressure indicated by P
(default 1 bar).
The motivation for writing these functions is to explore alternatives or possible modifications to the revised HelgesonKirkhamFlowers equations applied to aqueous nonelectrolytes. As pointed out by Schulte et al., 2001, the functional forms of the equations do not permit retrieving values of the solvation parameter (omega) that closely represent the observed trends in both heat capacity and volume at high temperatures (above ca. 200 °C).
For EOSregress
, an object of class “lm”. EOSvar
and EOScalc
both return numeric values. EOScoeffs
returns a data frame.
Schulte, M. D., Shock, E. L. and Wood, R. H. (1995) The temperature dependence of the standardstate thermodynamic properties of aqueous nonelectrolytes. Geochim. Cosmochim. Acta 65, 3919–3930. http://dx.doi.org/10.1016/S00167037(01)007177
See lm
for the details of the regression calculations.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69  ## fit experimental heat capacities of CH4
## using revised HelgesonKirkhamFlowers equations
# read the data from Hnedkovsky and Wood, 1997
f < system.file("extdata/cpetc/Cp.CH4.HW97.csv", package="CHNOSZ")
d < read.csv(f)
# have to convert J to cal and MPa to bar
d$Cp < convert(d$Cp, "cal")
d$P < convert(d$P, "bar")
# specify the terms in the HKF equations
var < c("invTTheta2", "TXBorn")
# perform regression, with a temperature limit
EOSlm < EOSregress(d, var, T.max=600)
# the result is within 10% of the accepted
# values of c1, c2 and omega for CH4(aq)
CH4coeffs < EOScoeffs("CH4", "Cp")
dcoeffs < EOSlm$coefficients  CH4coeffs
stopifnot(all(abs(dcoeffs/CH4coeffs) < 0.1))
## make plots comparing the regressions
## here with the accepted EOS parameters of CH4
par(mfrow=c(2,2))
EOSplot(d, T.max=600)
title("Cp of CH4(aq), fit to 600 K")
legend("bottomleft", pch=1, legend="Hnedkovsky and Wood, 1997")
EOSplot(d, coefficients=CH4coeffs)
title("Cp from EOS parameters in database")
EOSplot(d, T.max=600, T.plot=600)
title("Cp fit to 600 K, plot to 600 K")
EOSplot(d, coefficients=CH4coeffs, T.plot=600)
title("Cp from EOS parameters in database")
# continuing from above, with userdefined variables
invTTTheta3 < function(T, P) (2*T)/(TT*thermo$opt$Theta)^3
invTX < function(T, P) 1/T*water("XBorn", T=T, P=P)[,1]
# print the calculated values of invTTTheta3
EOSvar("invTTTheta3", d$T, d$P)
# use invTTTheta and invTX in a regression
var < c("invTTTheta3", "invTX")
EOSregress(d, var)
# give them a "label" attribute for use in the legend
attr(invTTTheta3, "label") <
quote(phantom()%*%2*italic(T)/(italic(T)italic(T)*Theta)^3)
attr(invTX, "label") < quote(phantom()/italic(T*X))
# uncomment the following to make the plot
#EOSplot(d, var)
## model experimental volumes of CH4
## using HKF equation and an exploratory one
f < system.file("extdata/cpetc/V.CH4.HWM96.csv", package="CHNOSZ")
d < read.csv(f)
d$P < convert(d$P, "bar")
# the HKF equation
varHKF < c("invTTheta", "QBorn")
# alpha is the expansivity coefficient of water
varal < c("invTTheta", "alpha")
par(mfrow=c(2,2))
# for both HKF and the expansivity equation
# we'll fit up to a temperature limit
EOSplot(d, varHKF, T.max=663, T.plot=625)
legend("bottomright", pch=1, legend="Hnedkovsky et al., 1996")
title("V of CH4(aq), HKF equation")
EOSplot(d, varal, T.max=663, T.plot=625)
title("V of CH4(aq), expansivity equation")
EOSplot(d, varHKF, T.max=663)
title("V of CH4(aq), HKF equation")
EOSplot(d, varal, T.max=663)
title("V of CH4(aq), expansivity equation")
# note that the volume regression using the HKF gives
# a result for omega (coefficient on Q) that is
# not consistent with the highT heat capacities

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.
Please suggest features or report bugs with the GitHub issue tracker.
All documentation is copyright its authors; we didn't write any of that.