Learn R Programming

desk (version 1.1.2)

makedata.corr: Generate Exogenous Normal Data with Specified Correlations

Description

This command generates a data frame of exogenous normal regression data with given correlation between the variables. This can, for example, be used for analyzing the effects of autocorrelation.

Usage

makedata.corr(n = 10, k = 2, CORR, sample = FALSE)

Value

The generated data frame of exogenous variables.

Arguments

n

number of observations to be generated.

k

number of exogenous variables to be generated.

CORR

(k x k) Correlation matrix that specifies the desired correlation structure of the data to be generated. If not specified a random positive definite covariance matrix will be used.

sample

logical value indicating whether the correlation structure is applied to the population (false) or the sample (true).

Examples

Run this code
## Generate desired correlation structure
corr.mat <- cbind(c(1, 0.7),c(0.7, 1))

## Generate 10 observations of 2 exogenous variables
X <- makedata.corr(n = 10, k = 2, CORR = corr.mat)
cor(X) # not exact values of corr.mat

## Same structure applied to a sample
X <- makedata.corr(n = 10, k = 2, CORR = corr.mat, sample = TRUE)
cor(X) # exact values of corr.mat

Run the code above in your browser using DataLab