lm

R: Automate Extraction of Linear Regression Equation from lm [duplicate]

匆匆过客 提交于 2019-12-12 00:25:20
问题 This question already has answers here : Extract Formula From lm with Coefficients (R) (3 answers) Closed 4 years ago . Does anyone know of an existing function to extract the full linear equation from a lm object? Suppose I have: lm1 = lm(y~x1+x2...xn, data=df) For this course in regression I'm taking, the professor repeatedly wants the resulting regression equation in the form: e(y) = b1 +b2x1 [...] bnx(n-1). Currently, I am doing something like this: (paste("y=", coef(lm1)[1], '+', coef

Factoring for linear models - Create lm with one factor

别来无恙 提交于 2019-12-11 22:56:41
问题 This question is a more specific and simplified version of this one. The dataset I'm using is too large for a single lm or speedlm calculation. I want to split up my data set in smaller pieces but in doing this, one(or more) of the columns only contains one factor. The code below is the mininum to reproduce my example. On the bottom of the question I will put my testing script for those interested. library(speedglm) iris$Species <- factor(iris$Species) i <- iris[1:20,] summary(i) speedlm

Fit model on a subset of columns in dataframe in R

天涯浪子 提交于 2019-12-11 20:31:53
问题 I'm trying to use lm() and matchit() on a subset of covariates. I have generated an arbitrary number of columns with prefix "covar", i.e. "covar.1", "covar.2", etc. I'd like to do something like lm(group ~ covars, data=df) where covars is a vector of strings c("covar.1", "covar.2", ...). I tried several things like cols <- colnames(df) covars <- cols[grep("covar", colnames(df))] m.out <- matchit(group ~ covars, data=df, method="nearest", distance="logit", caliper=.20) but got variable lengths

R: Waldtest: “Error in solve.default(vc[ovar, ovar]) : 'a' is 0-diml”

半世苍凉 提交于 2019-12-11 18:17:25
问题 If there is already an answer to my problem, i apologize for asking my question. So far, I couldn't find one. I'm currently doing a regression for financial data of bonds. Objective of my regression is to determine if two portfolios of bonds are showing significant different yields. I´m controlling for 4 variables (V1 to V4) to control for other sources of risk. The regression formula is the following: (one regression for "High-Portfolio", one regression for "Low-Portfolio") 𝑌ield(p)=∝(p)+ 𝛽1

Beta loop that allows for segmented time-series frequency

試著忘記壹切 提交于 2019-12-11 18:05:26
问题 I'm trying to run the LM function to collect the full output (summary) over a fairly large xts series (etfadj3) of different securities' returns. Currently, I can calculate a beta and capture all the regression outputs for the first column's return series against each column (security's) return series that follows - this is what I want. However, I would like to be able to modify this script so that I can vary the frequency of the regression to see a monthly/quarterly/yearly result. Is there a

Get number of data in each factor level (as well as interaction) from a fitted lm or glm [R]

社会主义新天地 提交于 2019-12-11 14:09:09
问题 I have a logistic regression model in R, where all of the predictor variables are categorical rather than continuous (in addition to the response variable, which is also obviously categorical/binary). When calling summary(model_name) , is there a way to include a column representing the number of observations within each factor level? 回答1: I have a logistic regression model in R, where all of the predictor variables are categorical rather than continuous. If all your covariates are factors

Run lm with multiple responses and weights

眉间皱痕 提交于 2019-12-11 07:39:02
问题 This question was migrated from Cross Validated because it can be answered on Stack Overflow. Migrated 6 years ago . I have to fit a linear model with the same model matrix to multiple responses. This can be easily done in R by specifying the response as matrix instead of a vector. Computation is very fast in this way. Now I would also like to add weights to the model that correspond to the accuracy of responses. Therefore, for each response vector I would need also different weight vector.

extracting linear model coefficients into a vector within a loop

痴心易碎 提交于 2019-12-11 07:17:57
问题 I am trying to create sample of 200 linear model coefficients using a loop in R. As an end result, I want a vector containing the coefficients. for (i in 1:200) { smpl_5 <- population[sample(1:1000, 5), ] model_5 <- summary(lm(y~x, data=smpl_5)) } I can extract the coefficients easy enough, but I am having trouble outputting them into a vector within the loop. Any Suggestions? 回答1: You can use replicate for this if you like. In your case, because the number of coefficients is identical for

why do residuals differ

柔情痞子 提交于 2019-12-11 07:16:36
问题 if we have dd <- structure(list(x = c(-0.27461139896373, -0.36715415967394, -0.396878987664827, -0.46247810661517, -0.348554552166752, -0.312871287128712, -0.305359246171965, -0.297850026219192, -0.38399462004035, -0.442901234567901, -0.436306074264866, -0.316390041493775), y = c(0.805840995132504, 1.9359410430839, 0.820987654320988, 1.4328231292517, 0.91156462585034, 1.75308641975309, 1.15646258503401, 1.42795138888889, 1.25575279421433, 3.13271604938272, 0.825788751714678, 0.583974649162517

How to match a data frame of variable names and another with data for a regression?

与世无争的帅哥 提交于 2019-12-11 07:05:10
问题 I have two data frames: x = data.frame(Var1= c("A", "B", "C", "D","E"),Var2=c("F","G","H","I","J"), Value= c(11, 12, 13, 14,18)) y = data.frame(A= c(11, 12, 13, 14,18), B= c(15, 16, 17, 14,18),C= c(17, 22, 23, 24,18), D= c(11, 12, 13, 34,18),E= c(11, 5, 13, 55,18), F= c(8, 12, 13, 14,18),G= c(7, 5, 13, 14,18), H= c(8, 12, 13, 14,18), I= c(9, 5, 13, 14,18), J= c(11, 12, 13, 14,18)) Var3 <- rep("time", each=length(x$Var1)) x=cbind(x,Var3) time=seq(1:length(y[,1])) y=cbind(y,time) > x Var1 Var2