📄 greg1b.gss
字号:
/*
*************************************************************************
* (C) Copyright 1999, Peter Lenk. All Rights Reserved.
* GREG1.GSS
* Generates data for linear regression
*************************************************************************
*/
new;
nobs = 100; @ number of observations @
@ Define true regression parametes @
betat = { .5,
2.5
};
@ Enter vector or matrices by rows, separated by commas @
sigmat = 4; @ true error std @
rankx = rows(betat); @ rows(x) = number of rows for x @
xdim = rankx-1; @ number of dependent variables @
xnames = 0 $+ "X" $+ ftocv(seqa(1,1,xdim),1,0);
@ Makes a character string that is X1, X2, ... @
ynames = "Y";
xynames = xnames|ynames;
xdata = rndn(nobs,xdim); @ rndn -> N(0,1) random numbers @
xmat = ones(nobs,1)~xdata; @ design matrix @
@ ~ pastes two matrics side-by-side @
@ Generate depenent observations @
ydata = xmat*betat + sigmat*rndn(nobs,1);
@ rndn(r,c) generates a r x c matric of N(0,1) random deviates @
xydata = xdata~ydata;
/*
**************************************************************************
* Create a Gauss file. f1 is the file handle.
* The Gauss file will be called "XYDATA."
* The column will be named by the strings in the character array xyname.
* ^xyname means use the names in the character string.
* 0, 8 gives double precision real numbers.
**************************************************************************
*/
create f1 = xydata with ^xynames, 0, 8;
/*
**************************************************************************
* Next read data into the Gauss file by using the writer command.
* f1 is the file handle defined in previous command.
* xydata is the data matrix that we just created.
* writer returns the number of rows read to f1.
* If it is not rows(xydata), something bad happended.
**************************************************************************
*/
if writer(f1,xydata) /= rows(xydata);
errorlog "Conversion of XYDATA to Gauss File did not work";
endif;
closeall f1;
@ Plot Y versus X_i @
_plctrl = -1; @ Plot symbols and no lines @
for i0 (1,xdim,1); i = i0;
title(ynames $+ " versus " $+ xnames[i]);
xy(xdata[.,i],ydata); @ Plot y versus x_i @
endfor;
graphset; @ Return to default graphs @
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -