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
2 answers

lines() simply doesn't show linear prediction of my non-linear regression

I was having trouble with plotting lines with my non-linear regression because the lengths of the plotting variables were different because the regression was omitting some observations. I fixed that using na.action=na.exclude. Now the "lengths…
luka1156
  • 181
  • 1
  • 8
0
votes
1 answer

R: variable lengths differ error when using lm

I am new to R and I'm working on a project, where we have to do some experiments with generating linear regression models. Here is my code: # regression coefficients beta1 = 1 beta2 = 0 beta3 = 5 beta4 = 1 beta5 = 1 # generated data df <-…
francosy
  • 173
  • 3
  • 12
0
votes
1 answer

Obtaining fitted values with control variables set at their means in R

I have a multivariate lm model in R for which I want to obtain predicated values/fitted values for each category of a factor variable, setting the control variables at their means. So for example, using the mtcars dataset: data(mtcars) fit <-…
Ella Wind
  • 121
  • 12
0
votes
1 answer

How to change generic lm() coefficient names in a list of lm objects for use in predict()?

I'm trying to write a function that creates a list of lm objects from a dataframe, with a different lm for each unique date in my data set. I would then like to be able to pass these lms into predict() with a new dataframe to generate predicted…
0
votes
0 answers

Error: invalid type(list) for variable when using lm() in looping

I'm trying to loop linear regression but I got an error invalid type (list) for variable 'uji[1]' this my sample data looks like obs 1 2 3 4 5 1 20.6 25.56560 26.10068 26.58787 26.79679 26.83781 2 23.2 25.69174…
ExHunter
  • 307
  • 4
  • 11
0
votes
1 answer

Can one use lm() to hold other variables at their mean and plot the regression line on a bivariate scatter plot?

I'm just wondering if it is possible to plot the regression line for a particular variable from a multivariate regression (using lm()), while holding other variables at their mean, and fit the regression line on a bivariate scatter plot? There's a…
Chris T.
  • 1,699
  • 7
  • 23
  • 45
0
votes
0 answers

R apply linear regression by ID and date, and extract slope parameters for each ID x date

I have data organised by the following columns: ID, Date, Time, Reading Each ID has a series of readings (measurements) per date. E.g. ID 149 on 1/1/2020 has readings at times 1,2,3,4... ID 149 on 2/1/2020 (or possibly 1/2/2020 if you're in the…
l_dan
  • 1
0
votes
1 answer

did modeling in R - right set up of data in staggered model

I appreciated any insights into staggered did (difference-in-differences) models. I wanted to ask if I use the correct function to set-up the model for a did (data structure provided below): did=time*treated didreg = lm(y ~ time + treated + did + x…
0
votes
2 answers

Factor Levels and Modelling in R

The following code runs a very simple lm() and tries to summarise the results (factor level, coefficient) in a small data frame: df <- data.frame(star_sign = c("Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo", "Libra", "Scorpio", "Sagittarius",…
Alan
  • 619
  • 6
  • 19
0
votes
0 answers

Difference between lm and dynlm

I am trying to decide between using lm and dylm for some regressions and have done some tests to see if I have reliable results using the lag operator. However, I found a result that seemed unusual to me. First, I did the estimation with the…
HenriqueP.
  • 13
  • 4
0
votes
0 answers

How to set default Project Properties in NetBeans?

I create projects using C99 in NetBeans. But when I try to include the library math.h, sqrt() and cbrt() won't work. I am on Ubuntu and using Apache NetBeans IDE 11.2. It is updated to NetBeans 8.2 Patch 2. The steps I do are : File > New Project >…
0
votes
1 answer

glmmTMB with beta family

I am trying to model the photosynthetic response (fvfm) that takes values from 0 to 0.7, I am using the beta distribution since I have zero inflation, and I consider a dispersion model because my values move away from the average as they pass days,…
0
votes
2 answers

R linear model function (lm) doesn't exclude predicted variable from predictors

I have a dataframe where I want to predict all variables from the other variables, so I construct a loop like this one: df = iris df$Species <- NULL mods = list() for (i in 1:ncol(df)) { mods[[i]] <- lm(df[, i] ~ ., df) } But, to my surprise,…
Eudald
  • 358
  • 3
  • 12
0
votes
0 answers

how can I use the stargazer package in R to report the lm.cluster()

alldata5 is my data and OROA,IROA,UROA,X2Y,PGR,LTA,gcode are different variables in this…
XUN ZHANG
  • 83
  • 11
0
votes
0 answers

Forecasting with TLSM function from forecast package

I am foresting with combination of datasets from fpp2 package and tslm function from the forecast package. # CODE library(fpp2) # required for the data library(dplyr) library(forecast) MY_DATA<-uschange[,1:4] head(MY_DATA) …
silent_hunter
  • 2,224
  • 1
  • 12
  • 30
1 2 3
99
100