lm

Creating new Functions with Linear Regression in R :

拥有回忆 提交于 2020-08-26 15:17:37
问题 I'm having a trouble when creating a function that calls the lm() function: regresionLineal <- function (vardep, varindep1, varindep2, DATA) { lm(vardep ~ varindep1 + varindep2, data = DATA) } Then I call it using data from a data frame I created previously ( DATOS )... regresionLineal(Estatura, Largo, Ancho, DATOS) Error in eval(expr, envir, enclos) : object 'Estatura' not found Called from: eval(expr, envir, enclos) Any help will be welcome... 回答1: You should do: regresionLineal <- function

Get confidence intervals for regression coefficients of “mlm” object returned by `lm()`

限于喜欢 提交于 2020-08-25 04:25:26
问题 I'm running a multivariate regression with 2 outcome variables and 5 predictors. I would like to obtain the confidence intervals for all regression coefficients. Usually I use the function lm but it doesn't seem to work for a multivariate regression model (object mlm ). Here's a reproducible example. library(car) mod <- lm(cbind(income, prestige) ~ education + women, data=Prestige) confint(mod) # doesn't return anything. Any alternative way to do it? (I could just use the value of the

Run linear models by group over list of variables in R

送分小仙女□ 提交于 2020-08-20 07:38:39
问题 I have a data frame and I need to run 6 2-variable linear models for each group 'site'. Then, I need to convert the results to a data frame. The second variable in the linear model changes. I have that part down using lapply() , but I can't figure out how to run by groups. I've found answers on SO that answer parts of my question, but I can't figure out how to put it all together. Here's some data: structure(list(SiteName = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c(

Run linear models by group over list of variables in R

你。 提交于 2020-08-20 07:37:25
问题 I have a data frame and I need to run 6 2-variable linear models for each group 'site'. Then, I need to convert the results to a data frame. The second variable in the linear model changes. I have that part down using lapply() , but I can't figure out how to run by groups. I've found answers on SO that answer parts of my question, but I can't figure out how to put it all together. Here's some data: structure(list(SiteName = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c(

Omit output of a factor variable in stargazer?

霸气de小男生 提交于 2020-06-14 06:08:19
问题 If I'm running a fixed effects model in r using lm and the factor command, how can I suppress the factor variable coefficients in a stargazer model? i.e. my model is: m1<-lm(GDP~pop_growth + factor(city)) and I want to report findings with only an intercept and coefficient on pop_growth, not coefficients on every dummy variable for cities. EDIT: Issue was, as it turns out, with variable name encoding. omit="city" works. 来源: https://stackoverflow.com/questions/49368917/omit-output-of-a-factor

How to add linear lines to a plot with multiple data sets of a data frame?

空扰寡人 提交于 2020-05-02 05:32:23
问题 I have the following data frame: expected observed group 1: 0.5371429 0.0000 1 2: 1.3428571 1.3736 1 3: 2.6857143 2.4554 1 4: 5.3714286 3.6403 1 5: 0.5294118 0.0000 2 6: 1.3235294 1.1494 2 7: 2.6470588 1.1364 2 8: 5.2941176 4.9774 2 9: 0.5201207 0.0000 3 10: 1.3003018 1.4327 3 11: 2.6006036 2.5918 3 12: 5.2012072 8.0769 3 13: 0.5155039 1.4851 4 14: 1.2887597 1.0638 4 15: 2.5775194 3.1700 4 16: 5.1550388 6.2500 4 17: 0.4976959 0.0000 5 18: 1.2442396 1.2384 5 19: 2.4884793 3.1073 5 20: 4

Splitting data and running linear regression loop

旧巷老猫 提交于 2020-04-14 07:34:27
问题 I have seen a lot of similar questions, but there is one key to the loop that I am trying to write that I am missing. I have a a set of dataset with ~4,000 different keys, and for each key, there are ~1,000 observations. I have filtered out a key to isolate the observations for that key, run linear regression, checked model assumptions and all looks good. However, I want to loop over this dataset and run that linear regression for each of the keys. Then I will want to store the coefficients,