6
$\begingroup$

For the last 2 months, I've been trying to do any kind of multivariate regression, but I haven't had much luck. I hear Octave is simpler and more intuitive for these kinds of tasks, so I thought I'd give it a try.

Here's a simplified version of the kind of data I'm using:

day = [4, 5, 6, 8]
temp = [97, 100, 98, 80]
humidity [62, 46, 50, 55]

I'd like to use this data and extrapolate the temperature for day 7 and day 9.

Are there any tutorials that clearly and concisely explain how to do this with Octave? Or perhaps someone here could tell me which Octave commands to use to do this?

Your help would be greatly appreciated.

$\endgroup$
2
  • 1
    $\begingroup$ Octave is basically Matlab, but slightly different. The regress command in Matlab is one option that works on my version of Octave. You probably need more data to make any decent forecast. Also, the day 7 thing would be more like interpolation than extrapolation (so interp1 would work if you want linear or spline interpolation). $\endgroup$
    – John
    Commented Jul 18, 2012 at 0:05
  • $\begingroup$ I know it's a small data set. Right now I'm mostly looking for a starting point, a way to more than 2 variables to get SOME kind of result. But your comment led me to documentation on one-dimensional interpolation. This is one step in the right direction, I think. Thank you for your reply. $\endgroup$ Commented Jul 18, 2012 at 2:04

1 Answer 1

12
$\begingroup$

It is not clear to me exactly what type of model you hope to fit. Some people say 'multivariate regression' to mean there are multiple dependent variables. For examples, you might want to predict both humidity and temp from day. Other people use it to just mean one outcome but multiple predictors. For example, you could predict temperature from both day and humidity. Here is an instructional solution showing how you could get the parameter estimates, standard errors, and new predicted values from a multiple regression model predicting the outcome, temperature, from day and humidity (as well as the constant term).

# your original data
day = [4, 5, 6, 8]
temp = [97, 100, 98, 80]
humidity = [62, 46, 50, 55]

# create the design matrix
# intercept (1s), day and humidity as predictors
X = [1, 1, 1, 1; day; humidity]'
# linear parameter estimates
b = inv(X'*X)*X'*temp'
# residuals
R = temp' - (X * b)
# residual variance
v = (R'*R)/(4 - 3)
# variance covariance matrix of parameters
Sigma = v * inv(X'*X)
# standard errors of parameters (b vector)
se = sqrt(diag(Sigma))

# new data for prediction, constant
# day is 7 and 9, humidity is 80
newdata = [1, 7, 80; 1, 9, 80]
# predicted values for day 7 and 9
pred = newdata * b

Which gives:

pred =
   70.712
   60.549

In practice, that is recreating the wheel, but since you are new to octave (and maybe regression?) I thought it might be helpful. Here is the simple way using built in functions to directly get the coefficients.

ols(temp', X)

which would be b from above, and you could postmultiply by new data (in your case day 7 and 9) to get predicted ("forecasts") values.

ans =
   156.18467
    -5.08122
    -0.62381
$\endgroup$
2
  • 3
    $\begingroup$ "In practice, that is recreating the wheel, but since you are new to octave (and maybe regression?) I thought it might be helpful." It's extremely helpful. Thank you very much. I'm going to spend some time with this now and do some tests with more data. $\endgroup$ Commented Jul 18, 2012 at 2:10
  • $\begingroup$ Glad to hear it :) Also see this Wikipedia page, which I think is quite good. $\endgroup$
    – Joshua
    Commented Jul 18, 2012 at 2:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.