linear-regression

R rlm model error: 'x' is singular: singular fits are not implemented in 'rlm'

冷暖自知 提交于 2019-12-23 15:47:13
问题 I have this two lists in R: y=c(420.5568, 693.6305, 420.5568, 946.9677, 499.1046, 946.9677) x=c(32, 29, 32, 27, 31, 27) I'm trying to fit this data to rlm model using this code: fit_new = (rlm(log(tail(y, 3)) ~ poly( tail(x,3), 2, raw=TRUE ))) The response is this error: Error in rlm.default(x, y, weights, method = method, wt.method = wt.method, : 'x' is singular: singular fits are not implemented in 'rlm' 回答1: Wrapping up my earlier comment: there's a problem is with the input data. Namely,

plotly regression line R

会有一股神秘感。 提交于 2019-12-23 12:41:55
问题 Problem with adding a regression line to a 'plotly' scatter plot. I've done the following code: require(plotly) data(airquality) ## Scatter plot ## c <- plot_ly(data = airquality, x = Wind, y = Ozone, type = "scatter", mode = "markers" ) c ## Adding regression line (HERE IS THE PROBLEM) ## g <- add_trace(c, x = Wind, y = fitted(lm(Ozone ~ Wind, airquality)), mode = "lines" ) g 回答1: I reckon it's caused by the missing values airq <- airquality %>% filter(!is.na(Ozone)) fit <- lm(Ozone ~ Wind,

How to use formula in R to exclude main effect but retain interaction

北城以北 提交于 2019-12-23 09:37:56
问题 I do not want main effect because it is collinear with a finer factor fixed effect, so it is annoying to have these NA . In this example: lm(y ~ x * z) I want the interaction of x (numeric) and z (factor), but not the main effect of z . 回答1: Introduction R documentation of ?formula says: The ‘*’ operator denotes factor crossing: ‘a * b’ interpreted as ‘a + b + a : b So it sounds like that dropping main effect is straightforward, by just doing one of the following: a + a:b ## main effect on `b

Categorical and ordinal feature data representation in regression analysis?

孤街醉人 提交于 2019-12-23 05:11:05
问题 I am trying to fully understand difference between categorical and ordinal data when doing regression analysis. For now, what is clear: Categorical feature and data example: Color: red, white, black Why categorical: red < white < black is logically incorrect Ordinal feature and data example: Condition: old, renovated, new Why ordinal: old < renovated < new is logically correct Categorical-to-numeric and ordinal-to-numeric encoding methods: One-Hot encoding for categorical data Arbitrary

Split data.frame by country, and create linear regression model on each subset [duplicate]

依然范特西╮ 提交于 2019-12-23 03:52:09
问题 This question already has answers here : Linear Regression and group by in R (10 answers) Closed 3 years ago . I have a data.frame of data from the World Bank which looks something like this; country date BirthRate US. 4 Aruba 2011 10.584 25354.8 5 Aruba 2010 10.804 24289.1 6 Aruba 2009 11.060 24639.9 7 Aruba 2008 11.346 27549.3 8 Aruba 2007 11.653 25921.3 9 Aruba 2006 11.977 24015.4 All in all there 70 something sub sets of countries in this data frame that I would like to run a linear

Split data.frame by country, and create linear regression model on each subset [duplicate]

女生的网名这么多〃 提交于 2019-12-23 03:52:02
问题 This question already has answers here : Linear Regression and group by in R (10 answers) Closed 3 years ago . I have a data.frame of data from the World Bank which looks something like this; country date BirthRate US. 4 Aruba 2011 10.584 25354.8 5 Aruba 2010 10.804 24289.1 6 Aruba 2009 11.060 24639.9 7 Aruba 2008 11.346 27549.3 8 Aruba 2007 11.653 25921.3 9 Aruba 2006 11.977 24015.4 All in all there 70 something sub sets of countries in this data frame that I would like to run a linear

need finite 'xlim' values using reactive function in Shiny

一世执手 提交于 2019-12-23 02:34:37
问题 I'm trying to build a Linear regression Shiny app with a custom file input. I have a problem with the reactive function in Server.R. The reactive function data returns a data frame called qvdata . When data() is called in renderPlot and I plot from the qvdata I get the following error: "Error in plot.window(...):need finite 'xlim' values". When I do not use the reactive function and do the calculations in renderPlot the error does not occur. Why is this? I want later to be able to call this

Loop multiple 'multiple linear regressions' in R

巧了我就是萌 提交于 2019-12-23 02:32:17
问题 I have a database where I want to do several multiple regressions. They all look like this: fit <- lm(Variable1 ~ Age + Speed + Gender + Mass, data=Data) The only variable changing is variable1. Now I want to loop or use something from the apply family to loop several variables at the place of variable1. These variables are columns in my datafile. Can someone help me to solve this problem? Many thanks! what I tried so far: When I extract one of the column names with the names() function I do

How to conduct linear hypothesis test on regression coefficients with a clustered covariance matrix?

狂风中的少年 提交于 2019-12-23 02:05:11
问题 I am interested in calculating estimates and standard errors for linear combinations of coefficients after a linear regression in R. For example, suppose I have the regression and test: data(mtcars) library(multcomp) lm1 <- lm(mpg ~ cyl + hp, data = mtcars) summary(glht(lm1, linfct = 'cyl + hp = 0')) This will estimate the value of the sum of the coefficients on cyl and hp , and provide the standard error based on the covariance matrix produced by lm . But, suppose I want to cluster my

How to set contrasts for my variable in regression analysis with R?

狂风中的少年 提交于 2019-12-22 19:51:12
问题 During coding, I need to change the dummy value assigned to a factor. However, the following code does not work. Any suggestion? test_mx= data.frame(a= c(T,T,T,F,F,F), b= c(1,1,1,0,0,0)) test_mx a b 1 TRUE 1 2 TRUE 1 3 TRUE 1 4 FALSE 0 5 FALSE 0 6 FALSE 0 model= glm(b ~ a, data= test_mx, family= "binomial") summary(model) model= glm(a ~ b, data= test_mx, family= "binomial") summary(model) Here I will get the coef for b is 47. Now if I swap the dummy value, it should be -47 then. However, this