Plotpage: Y on X Regression: Use Default parameter set
This is a plot of three curves:
Yexact is the dash blue line. It graphs the exact relationship
between x and Yexact.
y are the circles connected by black lines. These are the
Yexact values perturbed by noise (error). The noise is
proportional Gaussian noise, i.e.
y = Yexact*(1+Fraction*G(0,1)) where G(0,1) is Gaussian noise with
mean 0 and variance 1. Fraction scales the noise and gives it a
variance of Fraction*Fraction. Fraction is usually chosen to be
greaterthan 0 and less than 0.25.
Yfit is the red line. This is a plot of the regression.
/* MODEL NUMBER:
// MODEL NUMBER: 0362
MODEL NAME: YonXregression
SHORT DESCRIPTION: Compute Y on X regression. Assumes
y(i) = slope*x(i) +error(i) (all the error is in y.)
*/
import nsrunit; unit conversion on;
math YonXregression{
// INDEPENDENT VARIABLE ERROR FREE
realDomain x; x.min=0; x.max=4; x.delta=0.1;
real Noise(x), // The noise to be included in Y=y
Yexact(x), // The value of y without noise
y(x), // Combines Yexact with Noise
Yfit(x); // Fitted value for Y
// SET NOISE PARAMETERS
choice RandomNoise("Gaussian","Uniform")=1;
choice TypeNoise("Proportional","Additive")=1;
private real rn = RandomNoise; // Type of noise
private real tn = TypeNoise; // Proportional or Additive
real Fraction = 0.2; // Standard deviation of noise
Noise = Fraction * ( if(rn<1.5) randomg() else sqrt(12)*(random()-0.5) );
real estNoiseVar = sum(Noise^2@x)/(x.ct-1); // Estimated
// variance of the Noise
// SET ACTUAL SLOPE AND INTERCEPT
real slope = 3, // Actual slope
intercept=1; // Actual intercept
Yexact = slope*x+intercept;
y = Yexact * (if(tn<1.5) (1+Noise) else 1) // Proportional Noise
+ (if(tn>1.5) Noise else 0); // or Additive Noise
// CALCULATE REGRESSION SLOPE, INTERCEPT, AND CORRELATION COEFFICIENT
real Sx=sum(x@x);
real Sy=sum(y@x);
real Sxx=sum(x*x@x);
real Sxy=sum(x*y@x);
real Syy=sum(y*y@x);
private real denom=x.ct*Sxx-Sx*Sx;
real regSlope =( x.ct*Sxy-Sx*Sy)/denom;
real regIntercept =( -Sx*Sxy+Sxx*Sy)/denom;
real Correlation = (Sxy-Sx*Sy/x.ct)/
( sqrt(Sxx-Sx*Sx/x.ct)*sqrt(Syy-Sy*Sy/x.ct) );
// CALCULATE REGRESSION LINE
Yfit(x) = regSlope*x+regIntercept;
}
/*
DETAILED DESCRIPTION:
This program calculates a Y on X regression. The x values are considered exact.
Only the Y values contain error (noise). The added noise can be proportional,
i.e.,
y=Yexact*(1+Fraction*Noise), where Fraction is usually chosen 0<=Fraction<=0.25,
or additive
y=Yexact+Fraction*Noise,
where Noise is either Gaussian or Uniform with mean 0 and variance 1.
KEY WORDS:
linear regression, Y on X,
REFERENCES:
REVISION HISTORY:
JSim SOFTWARE COPYRIGHT AND REQUEST FOR ACKNOWLEDGMENT OF USE:
JSim software was developed with support from NIH grants HL088516,
and HL073598. Please cite these grants in any publication for which
this software is used and send one reprint of published abstracts or
articles to the address given below. Academic use is unrestricted.
Software may be copied so long as this copyright notice is included.
Copyright (C) 1999-2009 University of Washington.
Contact Information:
The National Simulation Resource,
Director J. B. Bassingthwaighte,
Department of Bioengineering,
University of Washington, Seattle, WA
98195-5061
*/