comf : An R Package for Thermal Comfort Studies

The field of thermal comfort generated a number of thermal comfort indices. Their code implementation needs to be done by individual researchers. This paper presents the R package, comf, which includes functions for common and new thermal comfort indices. Additional functions allow comparisons between the predictive performance of these indices. This paper reviews existing thermal comfort indices and available code implementations. This is followed by the description of the R package and an example how to use the R package for the comparison of different thermal comfort indices on data from a thermal comfort study.


Introduction
Since the 1960's, researchers in the field of thermal comfort generated a number of thermal comfort indices (see 44.1.1 for details).The three most common indices are the predicted mean vote (PMV) introduced by Fanger (1970), the standard effective temperature (SET) by Gagge et al. (1986), and the adaptive comfort equation as presented e.g. in DIN EN 15251 (2012) and ASHRAE (2013).The latter is based on the work of Auliciems (1981a), de Dear et al. (1997), Nicol and Humphreys (2002) and others.
The purpose of these indices is the prediction of a) thermally acceptable indoor conditions or b) the evaluation of indoor conditions by a group of persons.The calculation procedures and/or equations for the indices are described in the literature they are introduced.However, in most cases the code implementation needs to be done by each researcher individually.Such process is a source for errors; chances are high that the codes of two researchers do not lead to the same outcome given identical input parameters.Therefore, I introduce the R package, comf, that enables the calculation of the most common thermal comfort indices and several new indices.The objective is to create a publicly available reference for comparisons and benchmarking.
Additional functions of this package allow a comparison between the outcome of those indices compared to subjective evaluations obtained by a given sample of occupants in a building.Such evaluation of the indices performance is seldom found in thermal comfort research.Given the increasing number of indices, such comparison needs to be done more often in order to judge under which circumstances which index performs best (Schweiker andWagner, 2015, 2016).
In this paper, existing thermal comfort indices are reviewed together with available tools and code implementations for their calculation.This is followed by the introduction of the R package, comf, and an example application to an existing dataset.

Review of thermal comfort indices
Table 1 gives an overview of the indices dealt with in this article or included in the R package, comf.Thereby, this list is not exclusive given the high number of additional comfort indices.
The indices can be grouped according to their outcome in those predicting • a mean vote on the 7-point thermal sensation scale, • a neutral or comfortable temperature, or • other values related to the perception of the thermal indoor environment.
The 7-point thermal sensation scale is the standard scale for the assessment of thermal perception given to subjects and is coded −3 cold, −2 cool, −1 slightly cool, 0 neither cold nor warm, +1 slightly warm, +2 warm, +3 hot (ISO 7726, 1998).Traditionally, this scale was used as categorical scale, but recent studies are using either a categorical or a continuous version (Schweiker et al., 2016a).
The neutral temperature is a set of operative temperatures evaluated in average as neutral (neither cold nor warm) on the 7-point thermal sensation scale (Auliciems, 1981b;Humphreys, 1978).Sometimes, this is also referred to as comfortable temperature (Schweiker et al., 2016a).Additional members of this group of indices are the adaptive comfort temperatures (Brager and de Dear, 2001;Nicol and Humphreys, 2010) The other values are e.g.related to the thermal strain of an individual due to the indoor thermal environment (Gagge et al., 1986), the exergy consumption rate of the human body (Shukuya, 2009) the distance of observed operative temperature or mean skin temperature to the thermoneutral zone (Kingma et al., 2016) and will be explained below.
The first group of indices predicting a mean vote on the thermal sensation scale consists of the PMV-index and its alterations (s.below) together with the predicted thermal sensation (PTS) based on the SET-index and corresponding adjusted versions.
The PMV index is based on the assumption that comfortable conditions are perceived when there is a balance between the heat generated by the metabolism and the heat lost or gained through convection, radiation, and evaporation (Fanger, 1970).
Alterations to the PMV-index are • the adjusted PMV (PMV adj ), which modifies the PMV model for elevated air velocities (ASHRAE, 2013;Schiavon et al., 2014), • the ePMV, which uses the expectancy factor, e, to account for variations in the expectation of people (Fanger and Toftum, 2002), • the aPMV, which alters the PMV based on an adaptive coefficient, λ, which represents the sum of behavioural, physiological, and psychological adaptation (Yao et al., 2009), and • the ATHB pmv , which adjusts the input values for clothing level and metabolic rate based on individual equations for the three just mentioned adaptive processes (Schweiker and Wagner, 2015).
In order to calculate the PTS it is necessary to calculate the SET first (s.below).Then, PTS can be calculated through the equation (McIntyre, 1980): (1) Adjusted versions of the PTS are parallel to the alterations to PMV, • the PTSe using the expectancy factor (Gao et al., 2015), • the PTSa using the adaptive coefficient (Gao et al., 2015), and • the ATHB pts changing the input values of clothing level and metabolic rate for the calculation of SET (Schweiker and Wagner, 2016).
The second group of indices consists of the adaptive comfort equations given e.g. in DIN EN 15251 (2012) and Brager and de Dear (2001) as well as the equations for the neutral temperatures by Auliciems (1981b) and Humphreys (1978).Both types of equations calculate the indoor environmental temperature to be evaluated as neutral on the 7-point thermal sensation scale or as comfortable.
The third group consists of the predicted percentage of dissatisfied (PPD), the SET, the distance to the thermoneutral zone (dTNZ), and the exergy consumption rate (Ex).
The predicted percentage of dissatisfied (PPD) is calculated based on the PMV value as described in Fanger (1970) by The SET is "the temperature of an imaginary environment at 50% relative humidity, <0.1 m/s average air speed, and mean radiant temperature equal to average air temperature, in which total heat loss from the skin of an imaginary occupant with an activity level of 1.0 met and a clothing level of 0.6 clo is the same as that from a person in the actual environment, with actual clothing and activity level" (ASHRAE, 2013) and is based on the work by Gagge and his group (Gagge et al., 1986).
The dTNZ was introduced by Kingma et al. (2016) and presents a biophysical approach to predict thermal sensation.Similar to the ATHB, the dTNZ is a new concept and still needs to be further evaluated.The same is true for the concept of Ex.A lower Ex was shown to be related to conditions regarded as thermally comfortable.Schweiker et al. (2016b); Simone et al. (2011) demonstrated that there is a relationship between Ex, thermal sensation, and thermal acceptance.

Existing software and tools
Only few of the thermal comfort indices can be calculated with existing tools.7730 (2005) for the calculation of PMV and PPD and a FORTRAN code for the calculation of SET was presented in Gagge et al. (1986).Recently a JavaScript-version for SET calculation was included in ASHRAE (2013).However, this version does not use the full code for calculation of SET by Gagge et al. (1986) or Fountain and Huizenga (1995), but a modified version.The difference is that for the SET-code used in ASHRAE (2013), the part related to convection from metabolically-generated air movement has been removed.This was done in order to have a smooth transition from original PMV values up to .15 m/s of air velocity to the adjusted PMV values starting above this air velocity.
Another source for code implementations is the source code of the CBE comfort tool, which is available at https://github.com/CenterForTheBuiltEnvironment/comfort_tool.This includes code in JavaScript and Python for the calculation of PMV, PMV adj , the adaptive comfort temperature and range, and the modified SET calculation as described in ASHRAE (2013).

Introduction to the package comf
The idea behind the R package, comf is to support researchers in the field of thermal comfort not only through publicly available code implementations for the calculation of comfort indices in R, but also through additional functions.Therefore, the main functions of this package can be grouped into those related to • the preparation of a dataset and transformation of physical variables, • the calculation of one or more comfort indices (see Table 1), and • the evaluation of the performance of a comfort index.

Preparation of a dataset and conversion of physical variables
Each thermal comfort index requires different input parameters.Therefore, the R package, comf, offers two procedures in order to prepare a dataset to be used as input to the calculation of one or more thermal comfort indices.
The first procedure starts with calling the function createCond.This function creates a list with standard values for the variables required for all comfort indices included in this package.Own data or further adjustments to these values could be done as follows: install.packages("comf_0.1.6.tar.gz",repos=NULL, type="source") library(comf) lsCond <-createCond() lsCond$ta <-21:30 lsCond$rh <-51:60 lsCond$met <-1.0 It is important that the length of vectors assigned to the elements of this list are either 1 or do have the same length.In above example, it is not possible to assign a vector with 11 items to ta, the indoor air temperature, and a vector with 10 items to rh, the relative humidity indoors.
The second procedure starts with a dataframe containing all variables to be used for the calculation.This procedure requires the user to know the required variables.This dataframe can then be transferred into a list or used directly.
ta <-21:30 rh <-51:60 met <-1.0 dfCond <-data.frame(ta,rh, met) lsCond2 <-as.list(dfCond) In addition, comf offers a variety of small functions to convert variables from one type to another.This includes among others • calcDewp, which calculates the dew point temperature, given air temperature and relative humidity, • calcEnth, which calculates the enthalpy of the air, given air temperature, relative humidity, and barometric pressure, • calcRH, which calculates the relative humidity of air, given air temperature, mixing ratio, and barometric pressure, • calcTroin, which calculates the operative and radiant temperature for standard globe measurements according to ISO 7726 (1998), given air temperature, globe temperature, air velocity, and metabolic rate.

Calculating one or more comfort indices
Before the preparation of a dataset, it is important to know that the structure of the input to functions for the calculation of one specific index such as calcATHB differs to that of the main function, calcComfInd.
The latter requires a list or data frame with variables as described below, while the former works with vectors or data frames.
There are again two possibilities to calculate one or more comfort indices.
The first one uses the main function of this package, calcComfInd.This function requires a list or data frame of variables together with a vector of comfort indices to be calculated, e.g.request="all" to calculate all indices or request=c("ATHBpmv","pmv") to calculate these two.The list of variables can consist of one item per variable or several items per variable, i.e. one value for each input parameter, or for some parameters 234 values and for the others one parameter.The rationale behind this is that very often, variables such as age, gender, or metabolic rate do not differ in a given dataset, while others like the indoor air temperature are different for each case.A complete list of indices to be calculated can be found in the help file of calcComfInd or obtained calling listOfRequests().
The function calcComfInd checks whether there is only one or more values for each variable and whether all variables required for the thermal comfort index to be calculated exist in the list.In case one or more required variables do not exist, the index is calculated using pre-defined standard values for these variables.In such case a warning is given at the end of the calculation in order to inform the user about the missing variable(s) and the value(s) used for the calculation.
The R Journal Vol.8/2, December 2016 ISSN 2073-4859 # using lsCond from above does not produce a warning calcComfInd(lsCond, request="all") # using lsCond2 from above displays 31 warnings which report # the corresponding standard values used calcComfInd(lsCond2, request="all") warnings() # the results however are identical Individual functions, e.g.calcSET to calculate SET, can be used for the second possibility to calculate one or more comfort indices.With this procedure, one can use a data frame or a list of vectors to calculate a specific thermal comfort index.The list of required variables as well as information about the standard values used when a variable is missing is included in each helpfile, e.g.?calcSET.

Evaluating the performance of one or more comfort indices
Due to the number of new or adjusted indices being presented in the scientific literature, the comparison between the performance of them will be an important aspect in future studies.The R package, comf, includes functions for different performance criteria.
The function calcBias calculates the mean bias, its standard deviation, and standard error between the actual (observed) thermal sensation vote (ASV) and the predicted thermal sensation vote (PSV) (Humphreys and Nicol, 2002).This is calculated according to where i denotes the individual vote.
The true positive rate (TPR) is the proportion of true predicted cases, where the categorical ASV is equal to the categorical PSV (Schweiker and Wagner, 2015).This can be calculated using the function calcTPRTSV, which calculates where k denotes the category of the sensation scale (e.g.cold), n the total number of votes, and tp the true positive cases, where the categorical PSV is equal to the categorical ASV.
The function calcAvgAcc calculates the average accuracy between PSV and ASV according to Sokolova and Lapalme (2009) by where l denotes the number of categories of the sensation scale, tp, tn, f n, and f p the number of true positives, true negatives, false positives, and false negatives for the corresponsing class.Note that the value of the average accuracy depends strongly on the distribution of ASV, i.e. in case most of the ASV's are in the same category, e.g.neutral, the average accuracy is very high due to the fact that for all other categories the number of true negative predicted votes is high as well. The

An example using data from a field experiment
The R package, comf, includes a data set deriving from a field experiment.This field measurement is described in detail in Hawighorst et al. (2016) and Schweiker and Wagner (2016).The data set included in this package contains 156 samples, which is a subset of the original data set with 620 samples, and was drawn with the R function sample.
The original data set was obtained by two field experiments in six office buildings in southern Germany.They were conducted during the summer periods of 2011 and 2012.Data loggers for air temperature and relative humidity were placed in the offices.In addition outdoor air temperature and relative humidity were measured with another data logger on the roof of each building.Subjects were visited up to 4 times during a two week period.The number of votes obtained by each subject differs due to absence periods of subjects.During each visit, subjects were asked about their thermal sensation (7-point categorical scale with the categories −3 cold, −2 cool, −1 slightlqy cool, 0 neutral, +1 slightly warm, +2 warm, +3 hot) together with a set of additional questiqons not relevant for this paper.While the subjects answered the paper-pencil based questionnaire the investigator noted down the clothing level of each subject.Written informed consent was obtained from the subjects prior to the installment of the data loggers.The air velocity included in the data set was estimated based on the state of window(s), door, and table fan and detailed measurements in a single room.
The variables included in the dataset are presented in Table 3. Descriptive statistics of the data set included in the package can be explored using: library(comf) library(psych) data(dfField) describe(dfField) In order to calculate a number of comfort indices for the conditions present in the data, it is recommended to start with the list of standard values and assign the values of the data set to the corresponding items of the list by: # creating a list with standard values lsField <-createCond() # assigning the variables included in the data set to the list variables <-c("ta", "tr", "vel", "rh", "clo", "met", "trm", "asv", "tao") for(i in 1:length(variables)) { lsField [[variables[i]]] <-dfField [[variables[i]]] } For this example, the following 8 thermal comfort indices will be calculated and compared: PMV, PMVadj, ATHBpmv, aPMV, ePMV, PTS, PTSa, PTSe, and ATHBpts.In order to be able to calculate aPMV, ePMV, PTSa, and PTSe, one needs to get an estimate for the adaptive coefficient and expectancy factor.This is done using the corresponding functions of the package by: lsField$epCoeff <-calcepCoeff(lsField)$epCoeff lsField$apCoeff <-calcapCoeff(lsField)$apCoeff The R Journal Vol.8/2, December 2016 ISSN 2073-4859 lsField$esCoeff <-calcesCoeff(lsField)$esCoeff lsField$asCoeff <-calcasCoeff(lsField)$asCoeff Then, the thermal comfort indices are calculated at once using the function calcComfInd.Note that it would be also possible to calculate all eight indices individually by calling their function as described above.

( a )
Mean bias and standard error.(b) True positive rate.

Figure 1 :
Figure 1: True positive rate for eight comfort indices.
Table2gives an overview of existing software, applications, and code implementations.In addition, several building energy performance simulation programs, e.g.Energy+, do offer the option to calculate the PMV value or other value.
1 The source code is available at https://github.com/CenterForTheBuiltEnvironment/comfort_tool 2 + = and other indices 3 A version of SET fit for adjusting PMV to higher air velocities

Table 2 :
Existing applications, software, and code snippets for the calculation of thermal comfort indices Notable exceptions are the calculations of the most common indices: a BASIC code is given in ISO

Table 3 :
Variables included in the dataset together with their derivation