r-factor

Remove some factor-interaction terms from estimation

。_饼干妹妹 提交于 2021-02-10 07:13:20
问题 I'd like to remove certain factor interactions from an estimation. Here's an example with generated data from an imaginated labour market (I uploaded it here: http://pastebin.com/raw.php?i=EcMEVqUC) s <- source("http://pastebin.com/raw.php?i=EcMEVqUC")$value lm(income ~ age + cit * prof, data=s) In this example economy, foreigners are not allowed to work in the public sector, therefore citforeign:profofficial is NA . Therefore I would like to exclude the interaction term of citforeign

Remove some factor-interaction terms from estimation

旧街凉风 提交于 2021-02-10 07:10:12
问题 I'd like to remove certain factor interactions from an estimation. Here's an example with generated data from an imaginated labour market (I uploaded it here: http://pastebin.com/raw.php?i=EcMEVqUC) s <- source("http://pastebin.com/raw.php?i=EcMEVqUC")$value lm(income ~ age + cit * prof, data=s) In this example economy, foreigners are not allowed to work in the public sector, therefore citforeign:profofficial is NA . Therefore I would like to exclude the interaction term of citforeign

Remove some factor-interaction terms from estimation

做~自己de王妃 提交于 2021-02-10 07:09:31
问题 I'd like to remove certain factor interactions from an estimation. Here's an example with generated data from an imaginated labour market (I uploaded it here: http://pastebin.com/raw.php?i=EcMEVqUC) s <- source("http://pastebin.com/raw.php?i=EcMEVqUC")$value lm(income ~ age + cit * prof, data=s) In this example economy, foreigners are not allowed to work in the public sector, therefore citforeign:profofficial is NA . Therefore I would like to exclude the interaction term of citforeign

converting columns to factor over list of dataframes

你说的曾经没有我的故事 提交于 2021-02-05 11:15:33
问题 I'm trying to convert several columns in a list of dataframes into factors. I've tried this, but it doesn't seem to convert the columns into factors: factor_cols_REx <- c('GESLACHT','GEVKL','BEROEP') for (i in (1:9)) { dataset_RE10_2014[[i]] <- lapply(dataset_RE10_2014[[i]][factor_cols_REx],factor) dataset_RE10_2015[[i]] <- lapply(dataset_RE10_2015[[i]][factor_cols_REx],factor) } Any ideas on how to fix this? 回答1: Let me know if I understood correctly #DATA dat = list(A = mtcars, B = mtcars)

Linear model (lm) when dependent variable is a factor/categorical variable?

我与影子孤独终老i 提交于 2021-02-04 17:15:11
问题 I want to do linear regression with the lm function. My dependent variable is a factor called AccountStatus : 1:0 days in arrears, 2:30-60 days in arrears, 3:60-90 days in arrears and 4:90+ days in arrears. (4) As independent variable I have several numeric variables: Loan to value , debt to income and interest rate . Is it possible to do a linear regression with these variables? I looked on the internet and found something about dummy's, but those were all for the independent variable. This

in R, how to set and retain custom levels in factor with different labels?

邮差的信 提交于 2021-01-28 08:30:54
问题 in R, how to set and retain custom levels in factor with different labels ? That is, I want to set custom numbers in the levels of a factor, and these numerical values - integers to be retained and not converted to "1, 2, 3 etc.". I know that one solution is to set these weights as Labels, but then I will missing the "labels" of the factor. The "weighted" distance between factors is not retained. Is it possible in R, to achieve something like this, using a single variable ? For example: age_f

Creating a logical variable out of a factor variable in R

对着背影说爱祢 提交于 2020-07-08 11:49:45
问题 I need to create a logical variable (True-False) out of a categorical (factor) variable I decided to use the: dat$var[dat$var %in% c("option1")] <- TRUE dat$var[dat$var %in% c("option2")] <- FALSE But I get the following error message in both lines and my entire variable is NA: Warning message: In `[<-.factor`(`*tmp*`, dat$var %in% c("option1"), : invalid factor level, NA generated Any ideas on what I might be doing wrong? The factor level is right, I copy pasted to make sure there will not

Creating a logical variable out of a factor variable in R

谁说我不能喝 提交于 2020-07-08 11:48:50
问题 I need to create a logical variable (True-False) out of a categorical (factor) variable I decided to use the: dat$var[dat$var %in% c("option1")] <- TRUE dat$var[dat$var %in% c("option2")] <- FALSE But I get the following error message in both lines and my entire variable is NA: Warning message: In `[<-.factor`(`*tmp*`, dat$var %in% c("option1"), : invalid factor level, NA generated Any ideas on what I might be doing wrong? The factor level is right, I copy pasted to make sure there will not