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 to do a regression of a log-return on date

I am a total R newbie So pardon me for this silly question I want to do a regression of the stock log return on time But I don't know how to extract the date as the X variable Here is the R…
Stephen
  • 7
  • 3
0
votes
0 answers

How to get summary output with tslm

Here is my model: mymodel <- tslm(activations ~ season + I((sold)) + I((sold1)) + I((sold2)) + trend, data = my_df_ts_all) I can see all the coefficients fine. But when I run summary(mymodel) I get the following error and not sure…
ali.hash
  • 106
  • 1
  • 1
  • 11
0
votes
1 answer

lm with an interaction term using the pipe %>% operator

I have a tibble with three columns, y, x1, and x2. I can do a regular regression lm(y ~ x1 + x2) using %>% by simply doing dat %>% select(y, x1, x2) %>% lm() However if I want to do lm(y ~ x1*x2), how do I go about doing it? The only way that…
wrahool
  • 1,101
  • 4
  • 18
  • 42
0
votes
1 answer

How to estimate a lm dummy regression avoiding multicollinearity?

I have a problem regression with lm on dummy variables. I want to figure out of the seasonal influence (seasonalities) change as time passes by. I established the following regression to do so: AT.trendinseason.lm <-…
Leon
  • 37
  • 1
  • 8
0
votes
0 answers

Omnibus anova for interaction using anova() on lm() is ignoring one factor

I am performing a onmibus anova to test for interaction on a dataset with one variable and three factors. data$fac1 data$fac2 data$fac3 levels(data$fac1) [1] "1" "2" "3" "4" "5" "6" "7" "8" [9] "9" "10" "11" "12" "13" "14" "15" "16" …
Rosario
  • 183
  • 1
  • 11
0
votes
1 answer

lm() and t.test(var.equal = TRUE) differ on one machine but not on another. Possible reasons?

I have noticed weird behaviour of lm() more specifically that the t.values do not work out. This behaviour is only observable on my machine, unregarding the loaded packages/objects in the global environment. Running the example from…
AaronP
  • 185
  • 10
0
votes
1 answer

lapply misses a variable name when used with lm and wanting to reduce iteration?

I have used melt to combine all my 32 columns into a single column, their values into a single column, and the independent variable into a single column. I then wanted to use lapply to generate a lm matching the rows of Years Species …
Lime
  • 738
  • 5
  • 17
0
votes
0 answers

How can I get lm() and nls() solvers in R to handle linear formulas with offsets self-consistently?

I have some time series data (x, y) which is consistent with a linear model. I would like to construct a regression formula in which one of the coefficients corresponds to the y-value at a specific moment in time (for example, Jan 1, 2013), rather…
stachyra
  • 4,423
  • 4
  • 20
  • 34
0
votes
1 answer

Why do I get two different R^2 in r and which one is correct?

I have the data below and want to do a exponential regression model using lm and the log of variable two. When I evaluate the model, I get two different r2 from the summary of the model and when i do a summary of the call of the model. Why do I get…
mace
  • 490
  • 1
  • 7
  • 24
0
votes
1 answer

Is there a way to extract $R^2$ of the coeftest() function?

I am having a question concerning the function coeftest(). I am trying to figure out where from I could get any results of the R-squared of this function. I was fitting a standard ,multiple linear regression as follows: Wetterstation.lm <-…
Leon
  • 37
  • 1
  • 8
0
votes
2 answers

simr: how to specify expected effect size in lm() or aov() models?

I am trying to use simR to assess the power of simple GLMs to detect a particular effect size, given a set of pilot data. For example: library(simr) m1 = lm(y ~ x, data=simdata) powerSim(m1) I have no problem doing this when testing power to detect…
Lyam
  • 123
  • 2
  • 14
0
votes
0 answers

Error in eval(predvars, data, env) : object not found However, the object does appear to exist

I am new to R and to actually asking a question in Stack Overflow. I looked at several similar questions, but they did not seem to apply to help my situation. I am trying to make a linear model with the lm() function, but I get an error returned…
shwalters
  • 23
  • 4
0
votes
0 answers

'relevel' function not working to reset the reference level in a linear model

I’m applying a simple linear model with a 3 levels treatment factor ("no", "one", "three") model<-lm(response variable~treatment, data) I obtain the following summary: Estimate Std. Error t value Pr(>|t|) (Intercept) …
L.Loc
  • 1
  • 2
0
votes
0 answers

Multi-linear regression in R error: 0 (non-NA) cases. How do I get this to work?

I'm trying to perform a multilinear regression analysis in R. I have a bunch of predictor variables that I had to centre (eg. variableA - mean(variableA)). Now when I plugged this into my lm(), it comes back with the following error: 0 (non-NA)…
0
votes
0 answers

R Cross Validation lm predict function

I have a problem with a cross validation I am doing right now. I have a dataset and split it into 4 pieces randomly, choose 3 of them for a regression model and use the 4th left one to model my target value. So far I always used a manual methode,…
Mr.Spock
  • 511
  • 2
  • 13
1 2 3
99
100