testRegs: Test regression methods on sampled data

Description Usage Arguments Details Value Examples

View source: R/CBregression.R

Description

This function samples data and applies standard, orthogonal and case based linear regression. Standard deviation of the error between estimated and true values for the slopes are given.

Usage

1
testRegs(m,n,A,sig1,sig2,generator=runif)

Arguments

m

Number of samples that are drawn.

n

The size of each sample.

A

The true slope value.

sig1

Standard deviation of the measurement error for x.

sig2

Standard deviation of the measurement error for y.

generator

A function such that generator(n) gives the random vector of true values of X.

Details

The vectors x=X+d and y=A*x+e are then constructed as the simulated measured values where d,e are normally distributed errors with mean 0 and standard deviations sig1, sig2. For these vectors the slope estimates by standard regression, orthogonal regression and case based latent regression are calculated.

Value

A vector with the standard deviations of the slope estimates of standard regression, orthogonal regression and case based latent regression in this order.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
testRegs(100,50,0.6,0.2,0.4);
# this prints standard deviations of errors, e.g. 0.4014260 0.3478160 0.2742257 which shows that in this sampling CBregress performed best
    
# a more ambitous use is the following simulation study
print("Simulations with uniform distribution")
print(c("Std reg.","Ortho.","Case based"))
for(A in c(0.5,1.0,1.5)) {
  res=c(0,0,0)
  print("")
  print(paste("Data simulation for a=",toString(A)))
  for(sigx in c(0.2,0.4)) for(sigy in c(0.2,0.4)) {
    print(paste("sig error x=",toString(sigx),"sig error y=",toString(sigy)))
    res=res+testRegs(10,100,A,sigx,sigy,generator=runif)
  } 
  print(c("Total errors",sqrt(res/4)))
}
    

ROldenburg/CBregress documentation built on Jan. 5, 2021, 12:12 a.m.