linear-regression

Equations for 2 variable Linear Regression

a 夏天 提交于 2019-12-03 22:17:10
We are using a programming language that does not have a linear regression function in it. We have already implemented a single variable linear equation: y = Ax + B and have simply calculated the A and B coefficents from the data using a solution similar to this Stack Overflow answer . I know this problem gets geometrically harder as variables are added, but for our purposes, we only need to add one more: z = Ax + By + C Does anyone have the closed form equations, or code in any language that can solve for A, B and C given an array of x, y, and z's? so you have three linear equations k = aX1 +

Interpreting Alias table testing multicollinearity of model in R

喜你入骨 提交于 2019-12-03 21:36:59
Could someone help me interpret the alias function output for testing for multicollinearity in a multiple regression model. I know some predictor variables in my model are highly correlated, and I want to identify them using the alias table. Model : Score ~ Comments + Pros + Cons + Advice + Response + Value + Recommendation + 6Months + 12Months + 2Years + 3Years + Daily + Weekly + Monthly Complete : (Intercept) Comments Pros Cons Advice Response Value1 UseMonthly1 0 0 0 0 0 0 0 Recommendation1 6Months1 12Months1 2Years1 UseMonthly1 0 1 1 1 3Years1 Daily1 Weekly1 UseMonthly1 1 -1 -1 Value,

Fminsearch Matlab (Non Linear Regression )

喜你入骨 提交于 2019-12-03 21:15:23
Can anyone explain to me how I can apply non linear regression to this equation t find out K using the matlab command window. I = 10^-9(exp(38.68V/k)-1). Screenshot of Equation I have data values as follows: Voltage := [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]: Current:= [0, 0, 0, 0, 0, 0, 0, 0.07, 0.92, 12.02, 158.29]: Screenshot of Equation [NEW]: Now I used FminSearch as an alternative another and another error message appeared. Matrix dimensions must agree. Error in @(k)sum((I(:)-Imodel(V(:),k)).^2) Error in fminsearch (line 189) fv(:,1) = funfcn(x,varargin{:}); I used this

Pandas/Statsmodel OLS predicting future values

和自甴很熟 提交于 2019-12-03 20:14:49
I've been trying to get a prediction for future values in a model I've created. I have tried both OLS in pandas and statsmodels. Here is what I have in statsmodels: import statsmodels.api as sm endog = pd.DataFrame(dframe['monthly_data_smoothed8']) smresults = sm.OLS(dframe['monthly_data_smoothed8'], dframe['date_delta']).fit() sm_pred = smresults.predict(endog) sm_pred The length of the array returned is equal to the number of records in my original dataframe but the values are not the same. When I do the following using pandas I get no values returned. from pandas.stats.api import ols res1 =

How to calculate the 95% confidence interval for the slope in a linear regression model in R

狂风中的少年 提交于 2019-12-03 18:21:57
问题 Here is an exercise from Introductory Statistics with R: With the rmr data set, plot metabolic rate versus body weight. Fit a linear regression model to the relation. According to the fitted model, what is the predicted metabolic rate for a body weight of 70 kg? Give a 95% confidence interval for the slope of the line. rmr data set is in the 'ISwR' package. It looks like this: > rmr body.weight metabolic.rate 1 49.9 1079 2 50.8 1146 3 51.8 1115 4 52.6 1161 5 57.6 1325 6 61.4 1351 7 62.3 1402

Can't get aggregate() work for regression by group

馋奶兔 提交于 2019-12-03 18:12:18
问题 I want to use aggregate with this custom function: #linear regression f-n CalculateLinRegrDiff = function (sample){ fit <- lm(value~ date, data = sample) diff(range(fit$fitted)) } dataset2 = aggregate(value ~ id + col, dataset, CalculateLinRegrDiff(dataset)) I receive the error: Error in get(as.character(FUN), mode = "function", envir = envir) : object 'FUN' of mode 'function' was not found What is wrong? 回答1: Your syntax on using aggregate is wrong in the first place. Pass function

Getting 'ValueError: shapes not aligned' on SciKit Linear Regression

喜夏-厌秋 提交于 2019-12-03 17:47:35
问题 Quite new to SciKit and linear algebra/machine learning with Python in general, so I can't seem to solve the following: I have a training set and a test set of data, containing both continuous and discrete/categorical values. The CSV files are loaded into Pandas DataFrames and match in shape, being (1460,81) and (1459,81). However, after using Pandas' get_dummies, the shapes of the DataFrames change to (1460, 306) and (1459, 294). So, when I do linear regression with the SciKit Linear

“weighted” regression in R

爷,独闯天下 提交于 2019-12-03 17:33:41
问题 I have created a script like the one below to do something I called as "weighted" regression: library(plyr) set.seed(100) temp.df <- data.frame(uid=1:200, bp=sample(x=c(100:200),size=200,replace=TRUE), age=sample(x=c(30:65),size=200,replace=TRUE), weight=sample(c(1:10),size=200,replace=TRUE), stringsAsFactors=FALSE) temp.df.expand <- ddply(temp.df, c("uid"), function(df) { data.frame(bp=rep(df[,"bp"],df[,"weight"]), age=rep(df[,"age"],df[,"weight"]), stringsAsFactors=FALSE)}) temp.df.lm <- lm

Python pandas has no attribute ols - Error (rolling OLS)

点点圈 提交于 2019-12-03 17:24:32
For my evaluation, I wanted to run a rolling 1000 window OLS regression estimation of the dataset found in this URL: https://drive.google.com/open?id=0B2Iv8dfU4fTUa3dPYW5tejA0bzg using the following Python script. # /usr/bin/python -tt import numpy as np import matplotlib.pyplot as plt import pandas as pd from statsmodels.formula.api import ols df = pd.read_csv('estimated.csv', names=('x','y')) model = pd.stats.ols.MovingOLS(y=df.Y, x=df[['y']], window_type='rolling', window=1000, intercept=True) df['Y_hat'] = model.y_predict However, when I run my Python script, I am getting this error:

Errors in segmented package: breakpoints confusion

假如想象 提交于 2019-12-03 16:58:12
Using the segmented package to create a piecewise linear regression I am seeing an error when I try to set my own breakpoints; it seems only when I try to set more than two. (EDIT) Here is the code I am using: # data bullard <- structure(list(Rt = c(0, 4.0054, 25.1858, 27.9998, 35.7259, 39.0769, 45.1805, 45.6717, 48.3419, 51.5661, 64.1578, 66.828, 111.1613, 114.2518, 121.8681, 146.0591, 148.8134, 164.6219, 176.522, 177.9578, 180.8773, 187.1846, 210.5131, 211.483, 230.2598, 262.3549, 266.2318, 303.3181, 329.4067, 335.0262, 337.8323, 343.1142, 352.2322, 367.8386, 380.09, 388.5412, 390.4162, 395