linear-regression

OLS of statsmodels does not work with inversely proportional data?

青春壹個敷衍的年華 提交于 2019-12-12 02:04:46
问题 I'm trying to perform a Ordinary Least Squares Regression with some inversely proportional data, but seems like the fitting result is wrong? import statsmodels.formula.api as sm import numpy as np import matplotlib.pyplot as plt y = np.arange(100, 0, -1) x = np.arange(0, 100) result = sm.OLS(y, x).fit() fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(20, 4), sharey=True) ax.plot(x, result.fittedvalues, 'r-') ax.plot(x, y, 'x') fig.show() 回答1: You're not adding a constant as the

Multiple Regression with math.net

自作多情 提交于 2019-12-12 01:29:29
问题 Hello I am trying to get multiple regression with math.net and I am a little confused. var xdata = new DenseMatrix( new double[,]{{1, 36, 66, 45, 32}, {1, 37, 68, 12, 2}, {1, 47, 64, 78, 34}, {1, 32, 53, 56, 32}, {1, 1, 101, 24, 90}}); var ydata = new double[] { 15, 20, 25, 55, 95 }; var X = DenseMatrix.CreateFromColumns(new[] { new DenseVector(xdata.Length, 1), new DenseVector(xdata) }); var y = new DenseVector(ydata); var p = X.QR().Solve(y); var a = p[0]; var b = p[1]; I guess I don't

R: Automate Extraction of Linear Regression Equation from lm [duplicate]

匆匆过客 提交于 2019-12-12 00:25:20
问题 This question already has answers here : Extract Formula From lm with Coefficients (R) (3 answers) Closed 4 years ago . Does anyone know of an existing function to extract the full linear equation from a lm object? Suppose I have: lm1 = lm(y~x1+x2...xn, data=df) For this course in regression I'm taking, the professor repeatedly wants the resulting regression equation in the form: e(y) = b1 +b2x1 [...] bnx(n-1). Currently, I am doing something like this: (paste("y=", coef(lm1)[1], '+', coef

How I plot the linear regression

牧云@^-^@ 提交于 2019-12-11 23:05:32
问题 I am trying to plot a graph with the calculated linear regression, but I get the error "ValueError: x and y must have same first dimension". This is a multivariate (2 variables) linear regression with 3 samples (x1,x2,x3). 1 - First, I am calculating the linear regression correctly? 2 - I know that the error comes from the plot lines. I just don't understand why I get this error. What is the right dimensions to put in the plot? import numpy as np import matplotlib.pyplot as plt x1 = np.array(

Specifying a Constant in Statsmodels Linear Regression?

回眸只為那壹抹淺笑 提交于 2019-12-11 22:34:21
问题 I want to use the statsmodels.regression.linear_model.OLS package to do a prediction, but with a specified constant. Currently, I can specify the presence of a constant with an argument: (from docs: http://statsmodels.sourceforge.net/devel/generated/statsmodels.regression.linear_model.OLS.html) class statsmodels.regression.linear_model.OLS(endog, exog=None, missing='none', hasconst=None), where hasconst is a boolean. What I want to do is specify explicitly a constant C, and then fit a linear

fullrange = TRUE ignored in stat_smooth

亡梦爱人 提交于 2019-12-11 19:38:12
问题 In the following code, fullrange=TRUE appears to be ignored. Any ideas what's wrong? df <- data.frame("x"=c(119,118,144,127,78.8,98.4,108,50,74,30.4, 50,72,99,155,113,144,102,131,105,127,120,85,153,40.6,133), "y"=c(1.56,2.17,0.81,1.07,1.12,2.03,0.90,1.48,0.64, 0.91,0.85,0.41,0.55,2.18,1.49,1.56,0.82,0.93,0.84,1.84, 0.78,1.15,3.85,3.30,0.94)) library(ggplot2) library(MASS) ggplot(df,aes(x=x,y=y))+geom_point(size=3,colour="black")+ stat_smooth(method="rlm",alpha=0.1,fullrange=TRUE,se=TRUE)+

How to run different multiple linear regressions in R, Excel/VBA on a time series data for all different combinations of Explanatory Variables?

半城伤御伤魂 提交于 2019-12-11 18:25:35
问题 I am new to coding and R and would like your help. For my analysis, I am trying to run regression on a time series data with 1 dependent variable (Y) and 4 Independent Variables (X1, X2, X3, X4). All these variables (Y and X) have 4 different transformations (For example for X1 - X1, SQRT(X1), Square(X1) and Ln(X1)). I want to run the regressions for all the possible combinations of Y (Y, SQRT(Y), Square(Y), Ln(Y)) and all the combinations of X values so that in the end I can decide by

R: Waldtest: “Error in solve.default(vc[ovar, ovar]) : 'a' is 0-diml”

半世苍凉 提交于 2019-12-11 18:17:25
问题 If there is already an answer to my problem, i apologize for asking my question. So far, I couldn't find one. I'm currently doing a regression for financial data of bonds. Objective of my regression is to determine if two portfolios of bonds are showing significant different yields. I´m controlling for 4 variables (V1 to V4) to control for other sources of risk. The regression formula is the following: (one regression for "High-Portfolio", one regression for "Low-Portfolio") 𝑌ield(p)=∝(p)+ 𝛽1

Negative Binomial Regression: coefficient interpretation

半城伤御伤魂 提交于 2019-12-11 15:52:23
问题 How should coefficients (intercept, categorical variable, continuous variable) in a negative binomial regression model be interpreted? What is the base formula behind the regression (such as for Poisson regression, it is $\ln(\mu)=\beta_0+\beta_1 x_1 + \dots$)? Below I have an example output from my specific model that I want to interpret, where seizure.rate is a count variable and treatment categorical (placebo vs. non-placebo). Call: glm.nb(formula = seizure.rate2 ~ treatment2, data =

How to train a Regression model for single input and multiple output?

醉酒当歌 提交于 2019-12-11 15:45:44
问题 I have trained a regression model that approximates the weights for the equation : Y = R+B+G For this, I provide pre-determined values of R, B and G and Y, as training data and after training the model, the model is successfully able to predict the value of Y for given values of R, B and G. I used a neural network with 3 inputs, 1 dense layer (hidden layer) with 2 neurons and the output layer (output) with a single neuron. hidden = tf.keras.layers.Dense(units=2, input_shape=[3]) output = tf