Questions tagged [linear-regression]

for issues related to linear regression modelling approach

Linear Regression is a formalization of relationships between variables in the form of mathematical equations. It describes how one or more random variables are related to one or more other variables. Here the variables are not deterministically but stochastically related.

Example

Height and age are probabilistically distributed over humans. They are stochastically related; when you know that a person is of age 30, this influences the chance of this person being 4 feet tall. When you know that a person is of age 13, this influences the chance of this person being 6 feet tall.

Model 1

heighti = b0 + b1agei + εi, where b0 is the intercept, b1 is a parameter that age is multiplied by to get a prediction of height, ε is the error term, and i is the subject

Model 2

heighti = b0 + b1agei + b2sexi + εi, where the variable sex is dichotomous

In linear regression, user data X is modelled using linear functions Y, and unknown model parameters W are estimated or learned from the data. E.g., a linear regression model for a k-dimensional user data can be represented as :

Y = w1 x1 + w2 x2 + ... + wk xk

Reading Statistical Modeling: The Two Cultures http://projecteuclid.org/download/pdf_1/euclid.ss/1009213726

In scientific software for statistical computing and graphics, function lm (see ) implements linear regression.

6517 questions
10
votes
2 answers

How to extract a particular value from the OLS-summary in Pandas?

is it possible to get other values (currently I know only a way to get beta and intercept) from the summary of linear regression in pandas? I need to get R-squared. Here is an extraction from manual: In [244]: model = ols(y=rets['AAPL'],…
Joe
  • 283
  • 2
  • 3
  • 11
10
votes
1 answer

ggplot2; single regression line when colour is coded for by a variable?

I am trying to create a scatterplot in ggplot2 with one regression line even though colour is dependent on the 'Survey Type' variable. I would ideally also like to specify which survey type is which colour (community = red, subnational = green,…
Nadiah
  • 175
  • 2
  • 8
10
votes
1 answer

How to export a linear regression formula out of sklearn LinearRegression

I want to have the formula of the model in order to use it in other languages/projects. Is there a way to export the formula from the model? I will use sklearn linear regression model. What I want to do eventually: given a formula f(), and data set…
MichaelLo
  • 1,289
  • 1
  • 14
  • 26
10
votes
1 answer

Machine learning - Linear regression using batch gradient descent

I am trying to implement batch gradient descent on a data set with a single feature and multiple training examples (m). When I try using the normal equation, I get the right answer but the wrong one with this code below which performs batch gradient…
10
votes
1 answer

lm function in R does not give coefficients for all factor levels in categorical data

I was trying out linear regression with R using categorical attributes and observe that I don't get a coefficient value for each of the different factor levels I have. Please see my code below, I have 5 factor levels for states, but see only 4…
tubby
  • 2,074
  • 3
  • 33
  • 55
10
votes
3 answers

How to return predicted values, residuals, R square from lm()?

this piece of code will return coefficients :intercept , slop1 , slop2 set.seed(1) n=10 y=rnorm(n) x1=rnorm(n) x2=rnorm(n) lm.ft=function(y,x1,x2) return(lm(y~x1+x2)$coef) res=list(); for(i in 1:n){ x1.bar=x1-x1[i] x2.bar=x2-x2[i] …
sacvf
  • 2,463
  • 5
  • 36
  • 54
10
votes
2 answers

How to do gaussian/polynomial regression with scikit-learn?

Does scikit-learn provide facility to perform regression using a gaussian or polynomial kernel? I looked at the APIs and I don't see any. Has anyone built a package on top of scikit-learn that does this?
Jagat
  • 1,392
  • 2
  • 15
  • 25
10
votes
2 answers

Is linear regression the same thing as ordinary least squares in SPSS?

I want to use a linear regression model, but I want to use ordinary least squares, which I think it is a type of linear regression. The software I use is SPSS. It only has linear regression, partial least squares and 2-stages least squares. I have…
user41000
  • 285
  • 1
  • 6
  • 13
10
votes
3 answers

How to put a complicated equation into a R formula?

We have the diameter of trees as the predictor and tree height as the dependent variable. A number of different equations exist for this kind of data and we try to model some of them and compare the results. However, we we can't figure out how to…
donodarazao
  • 2,773
  • 4
  • 26
  • 26
10
votes
5 answers

how to plot the linear regression in R?

I want to make the following case of linear regression in…
Little
  • 3,363
  • 10
  • 45
  • 74
9
votes
3 answers

How can I create a linear regression line on a scatterplot with R?

I tried abline function to create a linear regression line on a scatterplot. x= c (1.0325477, 0.6746901, 1.0845737, 1.1123872, 1.1060822, 0.8595918, 0.8512941, 1.0148842, 1.0722369, 0.9019220 , 0.8809147, 1.0358256, 0.9903858, 1.0715174 , 1.1034405,…
lara
  • 503
  • 5
  • 10
  • 15
9
votes
3 answers

Visual Comparison of Regression & PCA

I'm trying to perfect a method for comparing regression and PCA, inspired by the blog Cerebral Mastication which has also has been discussed from a different angle on SO. Before I forget, many thanks to JD Long and Josh Ulrich for much of the core…
Bryan Hanson
  • 6,055
  • 4
  • 41
  • 78
9
votes
1 answer

models with 'differences from mean' for all coefficients on categorical variables; get 'contrast coding' to do it?

Suppose we want to do a simple 'descriptive model of income.' Suppose we have three groups, North, Central, and South (think US regions). Comparing otherwise similar groups, suppose average income in the North is 130, Central is 80, and South is…
daaronr
  • 507
  • 1
  • 4
  • 12
9
votes
4 answers

Weighted Linear Regression in Java

Does anyone know of a scientific/mathematical library in Java that has a straightforward implementation of weighted linear regression? Something along the lines of a function that takes 3 arguments and returns the corresponding…
C. Reed
  • 2,382
  • 7
  • 30
  • 35
9
votes
3 answers

What is causing this error? Coefficients not defined because of singularities

I'm trying to find a model for my data but I get the message "Coefficients: (3 not defined because of singularities)" These occur for winter, large and high_flow I found…
Laura
  • 177
  • 1
  • 12