optimStrat (version 2.1)

simulatey: Simulate the Study Variable

Description

Simulate values for the study variable based on the auxiliary variable x and the parameters of a superpopulation model.

Usage

simulatey(x, b0, b1, b2, b4, rho=NULL, b3=NULL)

Arguments

x

a positive numeric vector giving the values of the auxiliary variable.

b0

a number giving the intercept of the trend term in the superpopulation model.

b1

a number giving the scale of the trend term in the superpopulation model.

b2

a number giving the shape of the trend term in the superpopulation model.

b4

a number giving the shape of the spread term in the superpopulation model.

rho

a number giving the absolute value of the desired correlation between x and the vector to be simulated.

b3

a nonnegative number giving the scale of the spread term in the superpopulation model. Ignored if rho is given (see ‘Details’).

Value

A numeric vector giving the simulated value of y associated to each value in x.

Details

The values of the study variable y are simulated using a superpopulation model defined as follows: $$Y_{k}=\beta_{0}+\beta_{1}x_{k}^{\beta_{2}}+\epsilon_{k}$$ with \(\epsilon_{k} ~ N(0,\beta_{3}x_{k}^{\beta_{4}})\).

Note that b3 defines the degree of association between x and y: the larger b3, the smaller the correlation, rho, and vice versa. For this reason only one of them should be defined. If both are defined, b3 will be ignored.

The sign of the correlation should be given through b1 (see ‘Examples’).

Depending on the value of b2, some correlations cannot be reached, e.g. if b2=2 it is pointless to set rho=1. In those cases, b3 will automatically be set to zero and rho will be ignored (see ‘Examples’).

Examples

Run this code
# NOT RUN {
#Linear trend and homocedasticity
x<- 1 + sort( rgamma(5000, shape=4/9, scale=108) )
y<- simulatey(x, b0=0, b1=1, b2=1, b4=0, rho=0.90)
plot(x, y)

#Linear trend and heterocedasticity
y<- simulatey(x, b0=0, b1=1, b2=1, b4=1, rho=0.90)
plot(x, y)

#Quadratic trend and homocedasticity
y<- simulatey(x, b0=0, b1=1, b2=2, b4=0, rho=0.80)
plot(x, y)

#Correlation of minus one
y<- simulatey(x, b0=0, b1=-1, b2=1, b4=0, rho=1)
cor(x, y)
plot(x, y)

#Desired correlation cannot be attained
y<- simulatey(x, b0=0, b1=1, b2=3, b4=0, rho=0.99)
cor(x, y)
plot(x, y)
# }

Run the code above in your browser using DataCamp Workspace