linear-regression

Error when building regression model using lm ( Error in `contrasts<-`(`*tmp*`… contrasts can be applied only to factors with 2 or more levels) [duplicate]

走远了吗. 提交于 2019-12-12 05:44:58
问题 This question already has answers here : How to debug “contrasts can be applied only to factors with 2 or more levels” error? (2 answers) Closed last year . I get this error depending on which variables I include and the sequence in which I specify them in the formula: Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : contrasts can be applied only to factors with 2 or more levels I've done a little research on this and it looks like it would be caused by the variable in

R: how to do rolling regressions for multiple return data at once? with the dependent variable in one data frame and the regressor in the other?

ぃ、小莉子 提交于 2019-12-12 05:37:25
问题 Hi guys i would like to ask is there any way to do rolling window regressions for multiple return at once, with the dependent variable in one data frame and the regressor in the other?. i am trying to combine the rollapply and the sapply funtion to do this. So far i cant seem to make it work. For finance backgrounds: What i am trying to do is to compute the regressor for Fama-Macbeth regressions. With a rolling window that is rolled forward by 1 month to update the regressor. Different from

Extending Stargazer to multiwaycov

放肆的年华 提交于 2019-12-12 05:19:59
问题 I'm using stargazer to create regression outputs for my bachelor thesis. Due to the structure of my data I have to use clustered models (code below). I'm using the vcovclust command from the multiwaycov package, which works perfectly. However, stargazer does not support it. Do you know another way to create outputs as nice as stargazer does? Or do you know an other package/command to cluster the models, which is suppported by stargazer? model1.1.2 <- lm(leaflet ~ partisan + as.factor(gender)

R - How can I use the apply functions instead of iterating?

本秂侑毒 提交于 2019-12-12 05:10:05
问题 Regress each dependent variable ( dep_var ) against independent variable ( ind_var ) I am trying to perform linear regressions for multiple dependent variables against a independent variable one at a time. When there is a missing observation ( NA ) , the entire row is not used for that particular regression. I have done it by looping/iterating through each column of dependent variable. fit = list() for( i in 1 : 2 ) { fit[[i]] = lm( mydf$Ind_Var[ which( !is.na( mydf[ , (2+i) ] ) ) ] ~ na.omit

lme4::lmer reports “fixed-effect model matrix is rank deficient”, do I need a fix and how to?

旧城冷巷雨未停 提交于 2019-12-12 04:48:56
问题 I am trying to run a mixed-effects model that predicts F2_difference with the rest of the columns as predictors, but I get an error message that says fixed-effect model matrix is rank deficient so dropping 7 columns / coefficients. From this link, Fixed-effects model is rank deficient, I think I should use findLinearCombos in the R package caret . However, when I try findLinearCombos(data.df) , it gives me the error message Error in qr.default(object) : NA/NaN/Inf in foreign function call

Tensorflow: Simple Linear Regression using CSV data

梦想的初衷 提交于 2019-12-12 04:01:56
问题 I am an extreme beginner at tensorflow, and i was tasked to do a simple linear regression using my csv data which contains 2 columns, Height & State of Charge(SoC), where both values are float. In CSV file, Height is the first col while SoC is the second col. Using Height i'm suppose to predict SoC I'm completely lost as to what i have to add in the "Fit all training data" portion of the code. I've looked at other linear regression models and their codes are mind boggling, such as this one:

How to create a loop for a linear model in R

为君一笑 提交于 2019-12-12 03:44:42
问题 I am here to ask your help. I have to run a series of OLS regression on multiple depended variable using the same set for the independent ones. I.e. I have a dataframe of size (1510x5), in particular each one represent the return of a portfolio, and I would like to regress it agains the same set of dependent variable (1510x4), which in my case are the factors from the Carhart model. Since, beside the value for the coefficients, I am interested in both their P-value and on the R2 of the

R : constraining coefficients and error variance over multiple subsample regressions [closed]

家住魔仙堡 提交于 2019-12-12 03:33:36
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . I'm working with R on a sample of 145 observations. I have created five subsamples each with 29 observations, while the response variable q has been sorted. As a result, subset1 contains the 29 lines of the data frame with the lowest output, subset2 contains the following 29 lines, etc. I am regressing the

R's sandwich package producing strange results for robust standard errors in linear model

只谈情不闲聊 提交于 2019-12-12 03:08:14
问题 I am trying to find heteroskedasticity-robust standard errors in R, and most solutions I find are to use the coeftest and sandwich packages. However, when I use those packages, they seem to produce queer results (they're way too significant). Both my professor and I agree that the results don't look right. Could someone please tell me where my mistake is? Am I using the right package? Does the package have a bug in it? What should I use instead? Or can you reproduce the same results in STATA?

Trouble with predict function in R [duplicate]

青春壹個敷衍的年華 提交于 2019-12-12 02:13:04
问题 This question already has answers here : Predict() - Maybe I'm not understanding it (4 answers) Closed 2 years ago . I loaded the inbuilt R data 'women' which has a tabular data of average American women's height and corresponding weight. this table has 15 rows. Using this data I am trying to predict the weight for specific values of height. I made a linear model first and gave new values to predict. But R still comes up with the 15 figures from the original data. I am a beginner in