linear-regression

how to create many linear models at once and put the coefficients into a new matrix?

╄→гoц情女王★ 提交于 2019-12-01 14:17:07
I have 365 columns. In each column I have 60 values. I need to know the rate of change over time for each column (slope or linear coefficient). I created a generic column as a series of numbers from 1:60 to represent the 60 corresponding time intervals. I want to create 356 linear regression models using the generic time stamp column with each of the 365 columns of data. In other words, I have many columns and I would like to create many linear regression models at once, extract the coefficients and put those coefficients into a new matrix. First of all, statistically this might not be the

How to do two-dimensional regression analysis in Python?

喜欢而已 提交于 2019-12-01 11:45:17
Firstly, I am not familiar with Python and I still barely understand the mechanism of Python code. But I need to do some statistical analysis through Python. I have tried many many ways to figure out but I failed. Basically, I have 3 arrays of data (assume these arrays are X , Y , Z ). I did some analysis with ( X , Y ) and ( Z , Y ) by making the scatter plot and put the best fit with the data to see the correlation. №1 and №2 are quite easy enough. Now I need to see the edge on view from the graph which is the one with combined X and Z . So, I made the equation (see below). import pylab as

How to do two-dimensional regression analysis in Python?

被刻印的时光 ゝ 提交于 2019-12-01 11:18:19
问题 Firstly, I am not familiar with Python and I still barely understand the mechanism of Python code. But I need to do some statistical analysis through Python. I have tried many many ways to figure out but I failed. Basically, I have 3 arrays of data (assume these arrays are X , Y , Z ). I did some analysis with ( X , Y ) and ( Z , Y ) by making the scatter plot and put the best fit with the data to see the correlation. №1 and №2 are quite easy enough. Now I need to see the edge on view from

Python Sklearn Linear Regression Value Error

主宰稳场 提交于 2019-12-01 11:04:38
问题 Ive been trying out Linear Regression using sklearn. Sometime I get a value error, sometimes it works fine. Im not sure which approach to use. Error Message is as follows: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sklearn/linear_model/base.py", line 512, in fit y_numeric=True, multi_output=True) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages

How can I draw a linear regression line in this graph?

戏子无情 提交于 2019-12-01 10:46:26
enter image description here How can I draw a linear regression line in this graph? here is my code: import numpy as np import pandas_datareader.data as web import pandas as pd import datetime import matplotlib.pyplot as plt #get adjusted close price of Tencent from yahoo start = datetime.datetime(2007, 1, 1) end = datetime.datetime(2017, 12, 27) tencent = pd.DataFrame() tencent = web.DataReader('0700.hk', 'yahoo', start, end)['Adj Close'] nomalized_return=np.log(tencent/tencent.iloc[0]) nomalized_return.plot() plt.show() Pic 1 Jupiter Notebook Pic 2 my Jupiter Notebook You can use scikit

Removing Variables using PCA in R

喜欢而已 提交于 2019-12-01 10:13:24
问题 I tried searching for this but could not find the info. I am conducting a linear regression using 10 variables (1 y variable and 9 x variables). All the variables are correlated. I want to see if I need all 9 variables or not. How do I use the data from PCA to eliminate variables? I conducted PCA on all 10 variables using prcomp() and got the following results: Importance of components: PC1 PC2 PC3 PC4 PC5 PC6 PC7 PC8 PC9 PC10 Standard deviation 0.1021 0.04005 0.03464 0.03114 0.02414 0.02047

Rolling regression and prediction with lm() and predict()

好久不见. 提交于 2019-12-01 09:25:38
I need to apply lm() to an enlarging subset of my dataframe dat , while making prediction for the next observation. For example, I am doing: fit model predict ---------- ------- dat[1:3, ] dat[4, ] dat[1:4, ] dat[5, ] . . . . dat[-1, ] dat[nrow(dat), ] I know what I should do for a particular subset (related to this question: predict() and newdata - How does this work? ). For example to predict the last row, I do dat1 = dat[1:(nrow(dat)-1), ] dat2 = dat[nrow(dat), ] fit = lm(log(clicks) ~ log(v1) + log(v12), data=dat1) predict.fit = predict(fit, newdata=dat2, se.fit=TRUE) How can I do this

Linear regression of same outcome, similar number of covariates and one unique covariate in each model

空扰寡人 提交于 2019-12-01 09:25:33
I want to run linear regression for the same outcome and a number of covariates minus one covariate in each model. I have looked at the example on this page but could that did not provide what I wanted. Sample data a <- data.frame(y = c(30,12,18), x1 = c(7,6,9), x2 = c(6,8,5), x3 = c(4,-2,-3), x4 = c(8,3,-3), x5 = c(4,-4,-2)) m1 <- lm(y ~ x1 + x4 + x5, data = a) m2 <- lm(y ~ x2 + x4 + x5, data = a) m3 <- lm(y ~ x3 + x4 + x5, data = a) How could I run these models in a short way and and without repeating the same covariates again and again? Backlin Following this example you could do this:

How to model polynomial regression in R?

£可爱£侵袭症+ 提交于 2019-12-01 08:45:21
I've a dataset with 70 variables, and I want to try polynomial regression on it. If the number of columns were three/four I could just hand code something like this -- model <- lm(y ~ poly(var1,3) + poly(var2,3) + poly(var4,4) How would we go about this, if we have 70 variables? Should we type in manually names of all the variables or is there a easier method? You could paste the formula, if all variables are named systematically: form <- as.formula(paste("y~", paste0("poly(var", 1:10, ")", collapse="+"))) or (for polynomial of 3rd degree): form <- as.formula(paste("y~", paste0("poly(var", 1

Linear regression of same outcome, similar number of covariates and one unique covariate in each model

半城伤御伤魂 提交于 2019-12-01 06:34:53
问题 I want to run linear regression for the same outcome and a number of covariates minus one covariate in each model. I have looked at the example on this page but could that did not provide what I wanted. Sample data a <- data.frame(y = c(30,12,18), x1 = c(7,6,9), x2 = c(6,8,5), x3 = c(4,-2,-3), x4 = c(8,3,-3), x5 = c(4,-4,-2)) m1 <- lm(y ~ x1 + x4 + x5, data = a) m2 <- lm(y ~ x2 + x4 + x5, data = a) m3 <- lm(y ~ x3 + x4 + x5, data = a) How could I run these models in a short way and and