Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7006705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:30:42+00:00 2026-05-27T21:30:42+00:00

The code below works as intended, but it’s not quite what I need. I

  • 0

The code below works as intended, but it’s not quite what I need. I want to to change c[1] to c[1:] so that I regress against all of the x variables instead of just one. When I make that change (and add the appropriate x labels), I get the following error: ValueError: matrices are not aligned. Can someone explain why this is happening and suggest a modification to the code? Thanks.

from numpy import *
from ols import *

a = [[.001,.05,-.003,.014,.035,-.01,.032,-.0013,.0224,.005],[-.011,.012,.0013,.014,-.0015,.019,-.032,.013,-.04,-.05608],
 [.0021,.02,-.023,.0024,.025,-.081,.032,-.0513,.00014,-.00015],[.001,.02,-.003,.014,.035,-.001,.032,-.003,.0224,-.005],
 [.0021,-.002,-.023,.0024,.025,.01,.032,-.0513,.00014,-.00015],[-.0311,.012,.0013,.014,-.0015,.019,-.032,.013,-.014,-.008],
 [.001,.02,-.0203,.014,.035,-.001,.00032,-.0013,.0224,.05],[.0021,-.022,-.0213,.0024,.025,.081,.032,.05313,.00014,-.00015],
 [-.01331,.012,.0013,.014,.01015,.019,-.032,.013,-.014,-.012208],[.01021,-.022,-.023,.0024,.025,.081,.032,.0513,.00014,-.020015]]


c = column_stack(a)
y = c[0]
m = ols(y, c[1], y_varnm='y', x_varnm=['x1'])
print m.summary()

EDIT: I came up with a partial solution, but still having a problem. The code below works for 8 of the 9 explanatory variables.

c = column_stack(a)
y = c[0]
x = column_stack([c[i] for i in range(1, 9)])
m = ols(y, x, y_varnm='y', x_varnm=['x1','x2','x3','x4','x5','x6','x7','x8'])
print m.summary()

However, when I attempt to include the 9th x variable, I get the following error: RuntimeWarning: divide by zero encountered in double_scalars. Any idea why? Here’s the code (note that len(a) = 10):

c = column_stack(a)
y = c[0]
x = column_stack([c[i] for i in range(1, len(a))])
m = ols(y, x, y_varnm='y', x_varnm=['x1','x2','x3','x4','x5','x6','x7','x8','x9'])
print m.summary()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:30:42+00:00Added an answer on May 27, 2026 at 9:30 pm

    I don’t know anything about the ols module you’re using. But if you try the following with scikits.statsmodels, it should work:

    import numpy as np
    import scikits.statsmodels.api as sm
    
    a = np.array([[.001,.05,-.003,.014,.035,-.01,.032,-.0013,.0224,.005],[-.011,.012,.0013,.014,-.0015,.019,-.032,.013,-.04,-.05608],
     [.0021,.02,-.023,.0024,.025,-.081,.032,-.0513,.00014,-.00015],[.001,.02,-.003,.014,.035,-.001,.032,-.003,.0224,-.005],
     [.0021,-.002,-.023,.0024,.025,.01,.032,-.0513,.00014,-.00015],[-.0311,.012,.0013,.014,-.0015,.019,-.032,.013,-.014,-.008],
     [.001,.02,-.0203,.014,.035,-.001,.00032,-.0013,.0224,.05],[.0021,-.022,-.0213,.0024,.025,.081,.032,.05313,.00014,-.00015],
     [-.01331,.012,.0013,.014,.01015,.019,-.032,.013,-.014,-.012208],[.01021,-.022,-.023,.0024,.025,.081,.032,.0513,.00014,-.020015]])
    
    y = a[:, 0]
    x = a[:, 1:]
    results = sm.OLS(y, x).fit()
    print results.summary()
    

    The output:

         Summary of Regression Results
    =======================================
    | Dependent Variable:            ['y']|
    | Model:                           OLS|
    | Method:                Least Squares|
    | # obs:                          10.0|
    | Df residuals:                    1.0|
    | Df model:                        8.0|
    ==============================================================================
    |                   coefficient     std. error    t-statistic          prob. |
    ------------------------------------------------------------------------------
    | x0                     0.2557         0.6622         0.3862         0.7654 |
    | x1                    0.03054          1.453         0.0210         0.9866 |
    | x2                     -3.392          2.444        -1.3877         0.3975 |
    | x3                      1.445          1.474         0.9808         0.5062 |
    | x4                    0.03559         0.2610         0.1363         0.9137 |
    | x5                    -0.7412         0.8754        -0.8467         0.5527 |
    | x6                    0.02289         0.2466         0.0928         0.9411 |
    | x7                     0.5754          1.413         0.4074         0.7537 |
    | x8                    -0.4827         0.7569        -0.6378         0.6386 |
    ==============================================================================
    |                          Models stats                      Residual stats  |
    ------------------------------------------------------------------------------
    | R-squared:                     0.8832   Durbin-Watson:              2.578  |
    | Adjusted R-squared:          -0.05163   Omnibus:                   0.5325  |
    | F-statistic:                   0.9448   Prob(Omnibus):             0.7663  |
    | Prob (F-statistic):            0.6663   JB:                        0.1630  |
    | Log likelihood:                 41.45   Prob(JB):                  0.9217  |
    | AIC criterion:                 -64.91   Skew:                      0.4037  |
    | BIC criterion:                 -62.18   Kurtosis:                   2.405  |
    ------------------------------------------------------------------------------
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The code below works as expected in FF but not in IEs... $(document).ready(function() {
The code below works but I want to optimize the code using yield or
The code below works insomuch that I can successfully download the directory recursively. But,
The code below works fine in FF3.X and IE7 to 9, but not in
My code below works in firefox perfectly..but not in Safari. When I use the
The code below works. But if I comment out the line Dim objRequest As
the code below works fine but it takes an absolute age to run. How
The code below works great. I have a MySQL database that contains book titles
The code below works great except the email has all the text on one
This code below works in all web browsers except IE: <input type="text" name="passwordLogin" value="Password"

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.