I am trying to code up some examples in Julia and have some questions regarding arrays and scalars. Here is Matlab code that works:
%==============================
clc; clear;
vY = randn(100, 1); % outcome variable
mX = randn(100, 4); % design matrix
iN = size(vY, 1); % sample size
vBeta = (vY\mX)'; % estimated coefficients
vE = vY - mX*vBeta; % residuals
dSigmaSq = vE'*vE/iN; % residual variance
mV = dSigmaSq.*(inv(mX'*mX)); % covariance matrix
vStdErr = diag(mV); % std. err.
vT = (sqrt(iN)*vBeta)./vStdErr; % t-statistics
[vBeta, vStdErr, vT]
%==============================
On line 7, Matlab understands that the object "dSigmaSq" is a real scalar.
However, Julia needs this value to be explicitly dealt out of the 1x1 array,
#===============================
vY = randn(100, 1); # outcome variable
mX = randn(100, 4); # design matrix
iN = size(vY, 1); # sample size
vBeta = (vY\mX)'; # estimated coefficients
vE = vY - mX*vBeta; # residuals
dSigmaSq = vE'*vE/iN; # residual variance
mV = dSigmaSq[1,1].*(inv(mX'*mX)); # covariance matrix; dSigmaSq.*
vStdErr = diag(mV) # std. err.
vT = (sqrt(iN).*vBeta)./vStdErr # t-statistics
println([vBeta'; vStdErr'; vT']')
#===============================
Is this an intended design feature? I am wondering if my expectations are skewed by Matlab's behaviour.
Thanks.
--