lm

Extracting parameter coefficients from the summary function [duplicate]

风格不统一 提交于 2019-12-14 03:48:04
问题 This question already has answers here : Extract regression coefficient values (4 answers) Closed 6 years ago . I have fitted a linear regression model: Lin <- lm(y~x, data=df) When I use the summary function, I get some output. How do I extract the parameter coefficients from this output? 回答1: Here are a few ways of getting the parameter estimates: R> m = lm(y ~ x) R> m Call: lm(formula = y ~ x) Coefficients: (Intercept) x 0.5821 0.0878 Or ##See ?coef for details R> coef(m) R> coefficients(m

Using rollapply and lm over multiple columns of data

非 Y 不嫁゛ 提交于 2019-12-13 15:26:34
问题 I have a data frame similar to the following with a total of 500 columns: Probes <- data.frame(Days=seq(0.01, 4.91, 0.01), B1=5:495,B2=-100:390, B3=10:500,B4=-200:290) I would like to calculate a rolling window linear regression where my window size is 12 data points and each sequential regression is separated by 6 data points. For each regression, "Days" will always be the x component of the model, and the y's would be each of the other columns (B1, followed by B2, B3, etc). I would then

Predict X value from Y value with a fitted model [duplicate]

孤街醉人 提交于 2019-12-13 15:26:26
问题 This question already has an answer here : predict x values from simple fitting and annoting it in the plot (1 answer) Closed 2 years ago . I need to predict the corresponding x value of a new y value using a fitted model. The usual case of predicting the y value from a new x value is straightforward by using the predict function, but I cannot figure out how to do the reverse. For cases with multiple x solutions, I wish to obtain all solutions within the range of x values, i.e. 1-10 . And the

Finding the slope for multiple points in selected columns

情到浓时终转凉″ 提交于 2019-12-13 14:40:16
问题 Given the following data frame: structure(list(`-5` = c(0, 1, 0, 0, 9, 22), `-4` = c(1, 3, 0, 0, 1, 17), `-3` = c(1, 3, 0, 0, 0, 12), `-2` = c(1, 3, 0, 0, 2, 10), `-1` = c(0, 0, 0, 4, 3, 9), `0` = c(0, 1, 0, 2, 2, 21 ), `1` = c(0, 1, 1, 7, 1, 21), `2` = c(1, 0, 1, 2, 1, 10), `3` = c(0, 9, 0, 6, 1, 12), `4` = c(0, 2, 0, 5, 0, 18), `5` = c(0, 0, 0, 3, 0, 23)), .Names = c("-5", "-4", "-3", "-2", "-1", "0", "1", "2", "3", "4", "5"), row.names = c(NA, 6L), class = "data.frame") # -5 -4 -3 -2 -1 0

Rolling regression return multiple objects

筅森魡賤 提交于 2019-12-13 12:23:11
问题 I am trying to build a rolling regression function based on the example here, but in addition to returning the predicted values, I would like to return the some rolling model diagnostics (i.e. coefficients, t-values, and mabye R^2). I would like the results to be returned in discrete objects based on the type of results. The example provided in the link above sucessfully creates thr rolling predictions, but I need some assistance packaging and writing out the rolling model diagnostics: In the

Exporting and formatting regression analysis results in R to excel

佐手、 提交于 2019-12-13 05:20:57
问题 I am running regression analysis in R and unsure how to export my regression analysis results directly into Excel in standard regression table format (with significance level stars, standard errors, p-value , 95% confidence interval, R-sqr , F-test ). In stata, I would use the outreg2 command, which automatically generates a regression table, and I was wondering, if R has a similar code? For example: reg <- lm(imbd_score ~ budget + duration + year + cast_total_facebook_likes, data = imbd)

`Summary` multiple LM and GLM objects

一世执手 提交于 2019-12-13 03:52:16
问题 I have 50 lm and glm objects in R. I want to get the summary of all of them without having to type summary(lm...) 50 times. Is there a quick way to do it? The names of the dataset begin the same way: lin.mod.t# or lin.mod.s# where {# = 1,2,...,25}. I can list all the models using ls(pattern = "lin.mod") objects(pattern = "lin.mod") But I cannot run summary for the outcomes of using ls or objects . I used summary(eval(parse(text = ls(pattern = "lin.mod")))) , but this only runs the first one.

Fitting a quadratic curve for each data set that has different lengths

我的梦境 提交于 2019-12-13 03:45:33
问题 I would like to fit a quadratic to (Time,SkinTemp) for each id in the following data.frame df. Each id has a different number of Time,SkinTemp entries so I'm stuck with 'predict' df<-data.frame(Time=seq(65), SkinTemp=rnorm(65,37,0.5), id=rep(1:10,c(5,4,10,6,7,8,9,8,4,4))) So far I have: #Fit the model y=x^2+x+C fitted_models = df %>% group_by(id) %>% do(model = lm(SkinTemp ~ Time+I(Time^2), data = .)) So far so good. Here's where I'm stuck. How do I pass the original Time data into the

Writing loop/function to generate various linear regressions on same dataframe

試著忘記壹切 提交于 2019-12-13 03:16:04
问题 I am writing loops or functions in R, and I still haven't really understood how to do that. Currently, I need to write a loop/function (not sure which one would be better) to create several linear regression models within the same data frame. I have data like this: dataset <- read.table(text = "ID A_2 B_2 C_2 A_1 B_1 C_1 AGE M1 10 6 6 8 8 9 25 M2 50 69 54 67 22 44 16 M3 5 80 44 78 5 55 18 M4 60 70 52 89 3 56 28 M5 60 5 34 90 80 56 34 M6 55 55 67 60 100 77 54", header = TRUE, stringsAsFactors

Factors not being recognised in a lm using map()

谁说胖子不能爱 提交于 2019-12-13 03:07:25
问题 Aim: I want to use the map() function to do a linear model that involves categorical variables. Problem: I am getting the following error but I know the categorical variable included, borrower_genders has five levels. Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : contrasts can be applied only to factors with 2 or more levels What I've done: The following code works perfectly fine when removing borrower_genders , not with it, why? kiva_country%>% dplyr::group_by(country