Appendix A — Custom functions
This section contains additional information about the custom functions.
A.1 Custom functions for Q.6
The following custom functions are used to simulate the data.
-
logistic(). This function takes as an input the valuexand returns the probabilityp.
-
dordlogit(). This function takes as an input the vector of categoriesx, the linear predictoreta, the vector of threshold parameterstauand returns a vector of probabilitiespi(one for each categoryx). Iflog = TRUE, log probabilities are computed.
dordlogit <- function(x, eta, tau, log = FALSE) {
tau <- cbind(tau, Inf)
gamma <- logistic(tau[, x] - eta)
n.tau <- cbind(-Inf, tau)
n.gamma <- logistic(n.tau[, x] - eta)
pi <- gamma - n.gamma
if (log == TRUE) pi <- log(pi)
as.data.frame(pi)
}-
sim.multinom(). This function takes as a vector of probabilitiespand return a multinomially distributed random number.
sim.multinom <- function(y, p) {
for(i in 1:nrow(p)) {
x <- rmultinom(1, size = 1, prob = p[i,])*(1:ncol(p))
y[i] <- x[x > 0]
}
return(as.data.frame(y))
}-
sim_TSV.ord(). This function simulate ordinal thermal sensation vote (vote) of individuals from biological sex (sex), indoor air temperature (temp) and clothing insulation (clo). The other input values are the sample sizen(yet to be defined), the coefficient for the interceptb_int(yet to be defined), the coefficient for biological sexb_sex(yet to be defined), the coefficient for indoor air temperatureb_temp(yet to be defined), and the coefficient for clothing insulationb_clo(yet to be defined).
sim_TSV.ord <- function(n, sex, temp, clo, b_int, b_sex, b_temp, b_clo) {
#Define the threshold parameters
tau <- c(4.45, 5.65, 7.45, 9.85, 11.65, 12.85)
m <- matrix(tau, ncol = length(tau), nrow = n, byrow = TRUE) #Create a matrix
#Calculate linear predictor
eta <- b_int + b_temp*temp + b_clo*clo + ifelse(sex == '1', b_sex[1], b_sex[2])
#Calculate probability
prob <- dordlogit(x = 1:7, eta = eta, tau = m)
colnames(prob) = c('1', '2', '3', '4', '5', '6', '7') #Rename columns (1 = 'cold', ..., 7 = 'hot')
#Calculate thermal sensation vote (TSV)
vote0 <- matrix(0, ncol = 1, nrow = nrow(prob)) #Create a matrix
vote <- sim.multinom(vote0, prob) #Simulate (TSV)
colnames(vote) = c('V') #Rename column
return(vote) #Return the simulated votes
}A.2 Custom functions for Q.7
The following custom functions are used to simulate the data.
-
logistic(). This function takes as an input the valuexand returns the probabilityp.
-
dordlogit(). This function takes as an input the vector of categoriesx, the linear predictoreta, the vector of threshold parameterstauand returns a vector of probabilitiespi(one for each categoryx). Iflog = TRUE, log probabilities are computed.
dordlogit <- function(x, eta, tau, log = FALSE) {
tau <- cbind(tau, Inf)
gamma <- logistic(tau[, x] - eta)
n.tau <- cbind(-Inf, tau)
n.gamma <- logistic(n.tau[, x] - eta)
pi <- gamma - n.gamma
if (log == TRUE) pi <- log(pi)
as.data.frame(pi)
}-
sim.multinom(). This function takes as a vector of probabilitiespand return a multinomially distributed random number.
sim.multinom <- function(y, p) {
for(i in 1:nrow(p)) {
x <- rmultinom(1, size = 1, prob = p[i,])*(1:ncol(p))
y[i] <- x[x > 0]
}
return(as.data.frame(y))
}-
sim_TSV.ord(). This function simulate ordinal thermal sensation vote (vote) of individuals from biological sex (sex), indoor air temperature (temp) and clothing insulation (clo). The other input values are the sample sizen(yet to be defined), the coefficient for the interceptb_int(yet to be defined), the coefficient for biological sexb_sex(yet to be defined), the coefficient for indoor air temperatureb_temp(yet to be defined), and the coefficient for clothing insulationb_clo(yet to be defined).
sim_TSV.ord <- function(n, sex, temp, clo, b_int, b_sex, b_temp, b_clo) {
#Define the threshold parameters
tau <- c(4.45, 5.65, 7.45, 9.85, 11.65, 12.85)
m <- matrix(tau, ncol = length(tau), nrow = n, byrow = TRUE) #create a matrix
#Calculate linear predictor
eta <- b_int + b_temp*temp + b_clo*clo + ifelse(sex == '1', b_sex[1], b_sex[2])
#Calculate probability
prob <- dordlogit(x = 1:7, eta = eta, tau = m)
colnames(prob) = c('1', '2', '3', '4', '5', '6', '7') #rename columns (1 = 'cold', ..., 7 = 'hot')
#Calculate thermal sensation vote (TSV)
vote0 <- matrix(0, ncol = 1, nrow = nrow(prob)) #create a matrix
vote <- sim.multinom(vote0, prob) #simulate (TSV)
colnames(vote) = c('V') #rename column
return(vote) #return the simulated votes
}-
truth.sim_TSV.ord(). This function simulate ordinal thermal sensation vote (vote) and return the propbability of each vote (prob) of individuals from biological sex (sex), indoor air temperature (temp) and clothing insulation (clo). The other input values are the sample sizen(yet to be defined), the coefficient for the interceptb_int(yet to be defined), the coefficient for biological sexb_sex(yet to be defined), the coefficient for indoor air temperatureb_temp(yet to be defined), and the coefficient for clothing insulationb_clo(yet to be defined).
truth.sim_TSV.ord <- function(n, sex, temp, clo, b_int, b_sex, b_temp, b_clo) {
#Define the threshold parameters
tau <- c(4.45, 5.65, 7.45, 9.85, 11.65, 12.85)
m <- matrix(tau, ncol = length(tau), nrow = n, byrow = TRUE) #Create a matrix
#Calculate linear predictor
eta <- b_int + b_temp*temp + b_clo*clo + ifelse(sex == '1', b_sex[1], b_sex[2])
#Calculate probability
prob <- dordlogit(x = 1:7, eta = eta, tau = m)
colnames(prob) = c('1', '2', '3', '4', '5', '6', '7') #Rename columns (1 = 'cold', ..., 7 = 'hot')
#Calculate thermal sensation vote (TSV)
vote0 <- matrix(0, ncol = 1, nrow = nrow(prob)) #Create a matrix
vote <- sim.multinom(vote0, prob) #Simulate (TSV)
colnames(vote) = c('V') #Rename column
return(data.table(vote, prob)) #Return the simulated votes and the probability of each vote
}A.3 Custom functions for Q.8
The following custom functions are used to simulate the data.
-
logistic(). This function takes as an input the valuexand returns the probabilityp.
-
inv_logit(). This function function is equivalent to thelogistic()function.
inv_logit <- function(x) 1 / (1 + exp(-x))-
sim_TSV.beta(). This function simulate continuous but bounded (with interval \((0, 1)\)) thermal sensation vote (vote) of individuals from biological sex (sex), indoor air temperature (temp) and clothing insulation (clo). The other input values are the sample sizen(yet to be defined), the coefficient for the interceptb_int(yet to be defined), the coefficient for biological sexb_sex(yet to be defined), the coefficient for indoor air temperatureb_temp(yet to be defined), the coefficient for clothing insulationb_clo(yet to be defined) and the precision parameterphi(yet to be defined).
sim_TSV.beta <- function(n, sex, temp, clo, b_int, b_sex, b_temp, b_clo, phi) {
#Calculate linear predictor
eta <- b_int + b_temp*temp + b_clo*clo + ifelse(sex=='1', b_sex[1], b_sex[2])
#Calculate mean
mu <- logistic(eta)
#Calculate variance
var = mu*(1-mu)/(phi +1)
#Re-parametrise mean and variance
alpha <- ((1 - mu) / var - 1 / mu) * mu ^ 2
beta <- alpha * (1 / mu - 1)
#Calculate thermal sensation vote (TSV)
vote <- rbeta(n = n, shape1 = alpha, shape2 = beta)
return(vote) #return the simulated votes
}A.4 Custom functions for Q.9
The following custom functions are used to simulate the data.
-
logistic(). This function takes as an input the valuexand returns the probabilityp.
-
sim_TSV.beta(). This function simulate continuous but bounded (with interval \((0, 1)\)) thermal sensation vote (vote) of individuals from biological sex (sex), indoor air temperature (temp), clothing insulation (clo) and the random effect for the building (build). The other input values are the sample sizen(yet to be defined), the coefficient for the interceptb_int(yet to be defined), the coefficient for biological sexb_sex(yet to be defined), the coefficient for indoor air temperatureb_temp(yet to be defined), the coefficient for clothing insulationb_clo(yet to be defined) and the precision parameterphi(yet to be defined).
sim_TSV.beta <- function(n, sex, temp, clo, b_int, b_sex, b_temp, b_clo, build, phi) {
#Calculate linear predictor
eta <- b_int + b_temp*temp + b_clo*clo + ifelse(sex=='1', b_sex[1], b_sex[2]) + build
#Calculate mean
mu <- logistic(eta)
#Calculate variance
var = mu*(1-mu)/(phi +1)
#Re-parametrise mean and variance
alpha <- ((1 - mu) / var - 1 / mu) * mu ^ 2
beta <- alpha * (1 / mu - 1)
#Calculate thermal sensation vote (TSV)
vote <- rbeta(n = n, shape1 = alpha, shape2 = beta)
return(vote) #return the simulated votes
}A.5 Custom functions for Q.10
The following custom functions are used to simulate the data.
-
logistic(). This function takes as an input the valuexand returns the probabilityp.
-
sim_TSV.beta(). This function simulate continuous but bounded (with interval \((0, 1)\)) thermal sensation vote (vote) of individuals from biological sex (sex), indoor air temperature (temp) and clothing insulation (clo). The other input values are the sample sizen(yet to be defined), the coefficient for the interceptb_int(yet to be defined), the coefficient for biological sexb_sex(yet to be defined), the coefficient for indoor air temperatureb_temp(yet to be defined), the coefficient for clothing insulationb_clo(yet to be defined) and the precision parameterphi(yet to be defined).
sim_TSV.beta <- function(n, sex, temp, clo, b_int, b_sex, b_temp, b_clo, phi) {
#Calculate linear predictor
eta <- b_int + b_temp*temp + b_clo*clo + ifelse(sex=='1', b_sex[1], b_sex[2])
#Calculate mean
mu <- logistic(eta)
#Calculate variance
var = mu*(1-mu)/(phi +1)
#Re-parametrise mean and variance
alpha <- ((1 - mu) / var - 1 / mu) * mu ^ 2
beta <- alpha * (1 / mu - 1)
#Calculate thermal sensation vote (TSV)
vote <- rbeta(n = n, shape1 = alpha, shape2 = beta)
return(vote) #return the simulated votes
}