lm

extracting standardized coefficients from lm in R

橙三吉。 提交于 2020-04-07 10:59:25
问题 My apologies for the dumb question...but I can't seem to find a simple solution I want to extract the standardized coefficients from a fitted linear model (in R) there must be a simple way or function that does that. can you tell me what is it? EDIT (following some of the comments below): I should have probably provided more contextual information about my question. I was teaching an introductory R workshop for a bunch of psychologists. For them, a linear model without the ability to get

Error in lm.fit(x,y,offset = offset, singular.ok,…) 0 non-NA cases with boxcox formula

余生长醉 提交于 2020-03-18 12:32:10
问题 I am trying to run a boxcox transformation with the following code: urban1 <- subset(ski,urban <= 4,na.rm=TRUE) ski$gender <- as.numeric((as.character(ski$gender)),na.rm=TRUE) urban1 <- as.numeric((as.character(urban1))) x <- (ski$gender*urban1) y <- ski$EPSI. bc <- boxcox(y ~ x) (trans <- bc$x[which.max(bc$y)]) model3 <- lm(y ~ x) model3new <- lm(y^trans ~ x) ski$EPSI. <- ski$EPSI. + 1 But I keep getting this error: Error in lm.fit(x,y,offset = offset, singular.ok = singular.ok, ...) : 0

R prediction package VS Stata margins

你。 提交于 2020-02-27 07:26:17
问题 I'm switching from Stata to R, and I find inconsistent results when I use prediction to compute marginal pred and the results from the Stata command margins fixing the values of a variable to x . Here is the example: library(dplyr) library(prediction) d <- data.frame(x1 = factor(c(1,1,1,2,2,2), levels = c(1, 2)), x2 = factor(c(1,2,3,1,2,3), levels = c(1, 2, 3)), x3 = factor(c(1,2,1,2,1,2), levels = c(1, 2)), y = c(3.1, 2.8, 2.5, 4.3, 4.0, 3.5)) m2 <- lm(y ~ x1 + x2 + x3, d) summary(m2) marg2a

Extract Formula from lm including Categorical Variables (R)

倖福魔咒の 提交于 2020-01-25 09:51:09
问题 I have an lm object and want to get the formula extracted with coefficients. This object includes categorical variables like month, as well as interactions with these categorical variables and numeric ones. Another user helped with some code that works for all but the categorical variables, however when I add a categorical variable (eg. d here) it breaks down and gives the error "Error in parse(text = x) : :1:785: unexpected numeric constant": a = c(1, 2, 5, 13, 40, 29, 82, 22, 34, 54, 12, 31

Extract Formula from lm including Categorical Variables (R)

♀尐吖头ヾ 提交于 2020-01-25 09:51:05
问题 I have an lm object and want to get the formula extracted with coefficients. This object includes categorical variables like month, as well as interactions with these categorical variables and numeric ones. Another user helped with some code that works for all but the categorical variables, however when I add a categorical variable (eg. d here) it breaks down and gives the error "Error in parse(text = x) : :1:785: unexpected numeric constant": a = c(1, 2, 5, 13, 40, 29, 82, 22, 34, 54, 12, 31

How to speed up the analysis of ANOVA in R [closed]

坚强是说给别人听的谎言 提交于 2020-01-25 06:53:25
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 days ago . I have 2000 rows and three variables. I want to run ANOVA for may data, but it takes lots of time to get the output. Here is the formula that I use: fit<-anova(lm(Value~factor(X)*Y,df1)) Could we do better to get the output? Due to a big data frame, I was unable to produce it, but the formula

Estimating multiple `lm` models and returning output in one table, with map()

半城伤御伤魂 提交于 2020-01-24 12:33:16
问题 I need to estimate a number of linear models on the same dataset, and put the regression results all into one table. For a reproducible example, here's a simplification using mtcars : formula_1 = "mpg ~ disp" formula_2 = "mpg ~ log(disp)" formula_3 = "mpg ~ disp + hp" Currently, my approach has been to: Create a list that contains all of the formulae. use purrr:map() to estimate all of the lm models. use stargazer:: to produce output tables. library(tidyverse) library(stargazer) formula_1 =

Estimating multiple `lm` models and returning output in one table, with map()

ぃ、小莉子 提交于 2020-01-24 12:32:55
问题 I need to estimate a number of linear models on the same dataset, and put the regression results all into one table. For a reproducible example, here's a simplification using mtcars : formula_1 = "mpg ~ disp" formula_2 = "mpg ~ log(disp)" formula_3 = "mpg ~ disp + hp" Currently, my approach has been to: Create a list that contains all of the formulae. use purrr:map() to estimate all of the lm models. use stargazer:: to produce output tables. library(tidyverse) library(stargazer) formula_1 =

Why do I get NA coefficients and how does `lm` drop reference level for interaction

别来无恙 提交于 2020-01-21 07:26:06
问题 I am trying to understand how R determines reference groups for interactions in a linear model. Consider the following: df <- structure(list(id = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L), .Label = c("1", "2", "3", "4", "5"), class = "factor"), year = structure(c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), .Label = c("1", "2"),

Is there a function or package which will simulate predictions for an object returned from lm()?

 ̄綄美尐妖づ 提交于 2020-01-21 03:12:04
问题 Is there a single function, similar to "runif", "rnorm" and the like which will produce simulated predictions for a linear model? I can code it on my own, but the code is ugly and I assume that this is something someone has done before. slope = 1.5 intercept = 0 x = as.numeric(1:10) e = rnorm(10, mean=0, sd = 1) y = slope * x + intercept + e fit = lm(y ~ x, data = df) newX = data.frame(x = as.numeric(11:15)) What I'm interested in is a function that looks like the line below: sims = rlm(1000,