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
2
votes
1 answer

How to convert text to image in R other than texplot?

I did linear regression in R and extracted the significant variables together with their p-values. I need to import those variables to be imported in Power BI. However, Power BI only supports visuals from R and the regression result is in text. Is…
Katherine
  • 33
  • 1
  • 1
  • 7
2
votes
1 answer

python pandas dataframe predict values based on date

I have a python pandas dataframe df: Group date Value A 01-02-2016 16 A 01-03-2016 15 A 01-04-2016 14 A 01-05-2016 17 A 01-06-2016 19 A 01-07-2016 20 B 01-02-2016 …
jeangelj
  • 4,338
  • 16
  • 54
  • 98
2
votes
1 answer

Why is drop1 ignoring linear terms for mixed models?

I have six fixed factors: A, B, C, D, E and F, and one random factor R. I want to test linear terms, pure quadratic terms and two-way interactions using language R. So, I constructed the full linear mixed model and tried to test its terms with…
Milos
  • 518
  • 7
  • 22
2
votes
1 answer

Plotting rules as a tree for Cubist package in R

Is there any way I can plot the rules obtained from a Cubist model in a decision tree format? I can visualize the rules in text format (in console) by viewing the model summary, but I am unable to obtain a graphical tree presentation of the same. I…
2
votes
2 answers

Standard error and confidence interval for nonlinear function of least squares regression coefficients

I am running an OLS regression in R from which I get a couple of coefficients. Here's part of the code: Attacks <- Treat.Terr.Dataset$Attacks[2:30] Attackslag <- Treat.Terr.Dataset$Attacks[1:29] TreatmentEffect <-…
Gonzalo M.
  • 21
  • 1
2
votes
1 answer

How can I extract the number of lines and the corresponding equations from a linear fit

I have data and I expect several linear correlations of the form y_i = a_i + b_i * t_i, i = 1 .. N where N is a priori unknown. The short version of the question is: Given a fit how can I extract N? how can I extract the equations? In the…
Christoph
  • 6,841
  • 4
  • 37
  • 89
2
votes
1 answer

I don't know what's wrong with my linear regression code

I tried normal equation, and the result was correct. However, when I used gradient descent, the figure turned out to be wrong. I referred to online resources, but I failed to find out what's wrong. I don't think there's anything special in the…
K.WANG
  • 71
  • 1
  • 2
  • 5
2
votes
2 answers

Differences in Linear Regression in R and Python

I was trying to match the linear regression R results with that of python Matching the coefficients for each of independent variable and below is the code: Data is…
maddy kemen
  • 67
  • 2
  • 9
2
votes
1 answer

Coefficient table does not have NA rows in rank-deficient fit; how to insert them?

library(lmPerm) x <- lmp(formula = a ~ b * c + d + e, data = df, perm = "Prob") summary(x) # truncated output, I can see `NA` rows here! #Coefficients: (1 not defined because of singularities) # Estimate Iter Pr(Prob) #b …
Gotmadstacks
  • 359
  • 6
  • 20
2
votes
1 answer

Analysis using linear regression based on subgroups

Assume I have data (t,y), where I expect a linear dependency y(t). Furthermore, there exist attributes to each observation par1, par2, par3. Is there an algorithm or technique to decide, if (one or both or all of the parameters) are relevant for the…
Christoph
  • 6,841
  • 4
  • 37
  • 89
2
votes
2 answers

How do I get regression coefficients from a variance covariance matrix in R?

I want to work out a multiple regression example all the way through using matrix algebra to calculate the regression coefficients. #create vectors -- these will be our columns y <- c(3,3,2,4,4,5,2,3,5,3) x1 <- c(2,2,4,3,4,4,5,3,3,5) x2 <-…
adkane
  • 1,429
  • 14
  • 29
2
votes
1 answer

Why is my gradient descent for regression in R failing?

I have adapted the following gradient descent algorithm for regressing the y-variable stored in data[:,4] on the x-variable stored in data[:,1]. However, the gradient descent seems to be diverging. I would appreciate some help in identifying where I…
2
votes
1 answer

Fitting a bias in a weight decay regression using least-squares

I'm calcualting the weights for a linear regression with weight-decay, i.e. normally I am trying to find beta = (X'X + lambda I)^-1 X'Y where X has n rows of D features each and Y is a vector of outputs for each row of X. I've been fitting without a…
Jaxter
  • 23
  • 3
2
votes
1 answer

Applying lm() and predict() to multiple columns in a data frame

I have an example dataset below. train<-data.frame(x1 = c(4,5,6,4,3,5), x2 = c(4,2,4,0,5,4), x3 = c(1,1,1,0,0,1), x4 = c(1,0,1,1,0,0), x5 = c(0,0,0,1,1,1)) Suppose I want to create separate models for column x3, x4, x5 based on…
SRB
  • 35
  • 1
  • 1
  • 6
2
votes
1 answer

Arrange monte carlo p-value into a matrix for different sample size and variance estimators

The following code works out quite well (based on my previous question). But I have to change the variance estimator (ols, hc0, hc1, hc2, hc3) every time before I run the code. I would like to solve this problem with a loop. Hereafter, I briefly…
targa
  • 47
  • 6