Learn R Programming

hcc (version 0.54)

simer: Simulation of simple linear regression with hidden correlation

Description

Simulates n observations, (y, x) from a simple linear regression, y = a+b*x+e, where x is uniformly distributed on (0, n), e are normally distributed with mean 0 and variance 1. The parameeters a and b are zero. The error term is not independent but has an exponential correlation with parameter r so that observations close together in the x-space are positively correlated. When r=0, the correlation is zero but as r increases the correlation gets stronger.

Usage

simer(n, r)

Arguments

n
number of observations
r
correlation parameter

Value

A data frame with components:
x
input variable
y
output variable

Examples

Run this code
data <- simer(50, 5)

Run the code above in your browser using DataLab