Questions tagged [lm]

The lm function is used to fit linear models in R. It can be used to carry out regression, single stratum analysis of variance and analysis of covariance.

lm is an R function to fit linear models. It can be used to carry out regression, single stratum analysis of variance and analysis of covariance.

Usage

lm(formula, data, subset, weights, na.action,
   method = "qr", model = TRUE, x = FALSE, y = FALSE, qr = TRUE,
   singular.ok = TRUE, contrasts = NULL, offset, ...)

For further help, see Section 11 (Statistical models in R), especially Section 11.2 Linear Models in the introductory manual: An Introduction to R

1912 questions
0
votes
1 answer

How do I select two factors and perform regression

I have a dataset like this: library(tidyverse) set.seed(123) Data <- data.frame( X = sample(c("A", "B", "C"), 20, replace = TRUE), Y = sample(1:20) ) Data%>% arrange(X) I would like to run series of regressions such that DV is Y but…
0
votes
1 answer

Error in model.frame.default(formula = y ~ ., data = Peak_data, drop.unused.levels = TRUE) : variable lengths differ (found for 'GSP')

It is an error related to variable lengths differing. I have read previous forums in regards to this but I am not too sure if they apply to me. I have 6 independent variables and TCMD as my dependent variable and a samples size of 10. I am trying to…
rgwings
  • 15
  • 1
  • 4
0
votes
2 answers

Combining lapply and lm to run a regression for each date of panel-dataset

I´m trying to run a cross-sectional regression for each date of my panel-dataset in R. My dataset contains several observations for each date: Date ISIN Return SIZE 31.03.2010 DE44444 0,5 0,3 30.04.2010 DE44444 0,3 …
Timo
  • 3
  • 2
0
votes
1 answer

Inconsistent lm() output between R script and RMD file

Issue: The following code: lm(mpg ~ factor(am), data = mtcars) Should produce the following output (let's call it output 1), which I do get when running it from an r script in R Studio: Call: lm(formula = mpg ~ factor(am), data =…
LouJay
  • 1
  • 1
0
votes
0 answers

Fixed effect model - using plm and lm, different R2 values

I tried to do fixed effect model using plm and lm + factor(countries). And I got the same values for estimators, but I got different values for R2, residual standard error and F-statistic. Why? And the second question - can I get the coefficients…
Sylwia
  • 3
  • 1
0
votes
1 answer

R: How to identify mistake in bivariate linear regression in r

I am new to linear regression. I am running a simple linear regression using two variables with lm. The issue is that I generating different results. I have done the coding twice to see if the model's output it the same. It isn't, suggesting I have…
0
votes
0 answers

What does the error message mean when using lm linear regression command - error in the model.frame.default... variable lengths differ?

I tried to run a bivariate regression. I want to examine the association between level of education (IV) with views on immigration (DV). The DV is an interval level variable and the IV a dummy variable. I label the regression as reg. The code is as…
0
votes
0 answers

How to add regression equation to scatterplot in r

I am trying to make a basic scatterplot that displays the regression equation and r2 values in the top left of the plot panel. Below is the code to generate an initial figure with just the r2 value. plot(OverlapInner$PR1Max, OverlapInner$PR4Max,…
user12150823
0
votes
0 answers

The linear model in R ignores entirely one value in the interaction estimation

I am running a linear model on the impact of a particular team composition on the performance of teams. I have included the region as a separate variable since I plan to compare the coeeficients afterwards. I run the model with interactions between…
Emmerling
  • 11
  • 1
0
votes
2 answers

Trying to use lm() in r with the year

My data set: structure(list(year = 2010:2019, pop = c(9574323, 9657592, 9749476, 9843336, 9932887, 10031646, 10154788, 10268233, 10381615, 10488084 ), ye = 1:10), row.names = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10"), class =…
DaCrDg
  • 25
  • 3
0
votes
2 answers

Plotting multiple variable lm() in same plot

How can I create plot same this picture ? enter image description here When the red one is ddf of type blue one is def and black one is all data of type. I would like to plot of all in the same plot as picture above. I would like to evaluate…
0
votes
0 answers

Phantom missingness in R lm() model

I have a data frame of ~100 observations of 38 demographic variables, as well as pre- and post-test scores in six domains (var1:var6). I fitted a linear model using lm() such that test.lm <- lm(var1_post ~ var1_pre + dem1 + dem2 + ... + dem38,…
lrankin07
  • 1
  • 2
0
votes
1 answer

R: how do I run a regression on a table with NA values?

Currently, my error statement looks like this: NAs introduced by coercionError in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : NA/NaN/Inf in 'x' This is the code that I'm using: model <- lm(merged$Country.or.region ~ ., data =…
Anders Zhou
  • 89
  • 1
  • 8
0
votes
1 answer

R function with separating data and finding linear regression

I want to calculate the impact that height has on earnings given the gender. I divided my data into data for male and female but when I run the lm(earnings~height+education+age, data = data_female) function it gives me an error saying: Error in…
smn
  • 1
  • 1
0
votes
1 answer

R - Running a regression for tibbles identified by an id out of a dataframe in long format

I would like to loop over a dataframe data_all_long in long format that has time-series tuples identified by a stockID. With unique() I stored all the different IDs in the data frame "uniqueIDs". "Numberofrows" is the length of the list containing…
Rbeginner
  • 29
  • 5