regression

How to export coefficients of the regression analysis fto a spreadsheet or csv file?

我与影子孤独终老i 提交于 2019-12-02 20:41:35
I am new to RStudio and I guess my question is pretty easy to solve but a lot of searching did not help me. I am running a regression and summary(regression1) shows me all the coefficients and so on. Now I am using coef(regression1) so it only gives me the coefficients which I want to export to a file. write.csv(coef, file="regression1.csv) and the "Error in as.data.frame.default(x[[i]], optional = TRUE) : cannot coerce class ""function"" to a data.frame" occurs. Would be great If you could help me. I am searching the web for a few hours now and was not successful. Do I have to change coef

Plot the results of a multivariate logistic regression model in R

孤人 提交于 2019-12-02 17:47:26
I would like to plot the results of a multivariate logistic regression analysis (GLM) for a specific independent variables adjusted (i.e. independent of the confounders included in the model) relationship with the outcome (binary). I have seen posts that recommend the following method using the predict command followed by curve , here's an example; x <- data.frame(binary.outcome, cont.exposure) model <- glm(binary.outcome ~ cont.exposure, family=binomial, data=x) plot(cont.exposure, binary.outcome, xlab="Temperature",ylab="Probability of Response") curve(predict(model, data.frame(cont.exposure

Running several simple Regression in R

[亡魂溺海] 提交于 2019-12-02 17:19:52
问题 So I have a data set that has 188 rows and 65 columns relating to World development indicators and Birth statistics. I am trying to do a purposeful selection method to create a regression model. The first step of this is to look at all of the individual simple linear models. my goal is to run regression models in R for for each of my variables against my response. I know I can run lm(x$v30 ~ x$v1) which would give the regression for one of the variables. however, i am hoping to be able to do

Import column names from step wise regression in R

与世无争的帅哥 提交于 2019-12-02 16:55:47
问题 I want to import the variables selected from the step-wise regression process as column names so that I have the "Output" has the variables from the step-wise regression as shown below. But, my code below does NOT do that. I cannot understand what I am doing wrong here. Can somebody help me please? iris$area <- iris$Petal.Length * iris$Petal.Width iris <- data.table(iris) mydata <- iris[Species %in% "virginica", list(Sepal.Length,Sepal.Width,Petal.Length,Petal.Width,area)] fit <- lm(area~.,

Can we set / fix the coefficients in a regression equation in Python

可紊 提交于 2019-12-02 15:28:35
问题 I've been trying to find a way of specifying pre-defined coefficients in a OLS/GLS regression in Python. I can do this in R using offset , but there doesn't seem to be anything similar in Python. R equivalent: model=lm(y~x+offset(0.2*z)) So in this example x and z are our independent variables, and x is predicted by the model but we have specified the impact of z is 0.2 回答1: Using statsmodels you can perform regression analysis in Python with a style similar to R. There you will find offset

Predict.lm() in R - how to get nonconstant prediction bands around fitted values

只谈情不闲聊 提交于 2019-12-02 14:45:15
So I am currently trying to draw the confidence interval for a linear model. I found out I should use predict.lm() for this, but I have a few problems really understanding the function and I do not like using functions without knowing what's happening. I found several how-to's on this subject, but only with the corresponding R-code, no real explanation. This is the function itself: ## S3 method for class 'lm' predict(object, newdata, se.fit = FALSE, scale = NULL, df = Inf, interval = c("none", "confidence", "prediction"), level = 0.95, type = c("response", "terms"), terms = NULL, na.action =

R - Getting Column of Dataframe from String [duplicate]

我只是一个虾纸丫 提交于 2019-12-02 13:27:02
This question already has an answer here: Dynamically select data frame columns using $ and a vector of column names 8 answers I am trying to create a function that allows the conversion of selected columns of a data frame to categorical data type (factor) before running a regression analysis. Question is how do I slice a particular column from a data frame using a string (character). Example: strColumnNames <- "Admit,Rank" strDelimiter <- "," strSplittedColumnNames <- strsplit(strColumnNames, strDelimiter) for( strColName in strSplittedColumnNames[[1]] ){ dfData$as.name(strColName) <- factor

Adjust function for log(0)

我们两清 提交于 2019-12-02 12:43:29
I wrote a function for a poisson regression. The data set discoveris have some count data where 5 entries are y = 0. I want compute the deviance residuals, acroding to the formula in my function : devianceResiduals <- sign(y - fittedValuesFullModell) * sqrt(2 * y * log(y / fittedValuesFullModell) - 2 * (y - fittedValuesFullModell)) My problem ist that i get NaN because log(y = 0) = -inf. So tried to write a loop that use 2 different forumals to compute the deviance residuals. If y = 0 the formula simplifies to - 2 * (y - fittedValuesFullModell)) because of log rules. If y > 0 i want use my

Incorrect abline line for a regression model with intercept in R

China☆狼群 提交于 2019-12-02 12:11:19
问题 (reproducible example given) In the following, I get an abline line with y-intercept is about 30, but the regression says y-intercept should be 37.2851 Where am I wrong? mtcars$mpg # 21.0 21.0 22.8 ... 21.4 (32 obs) mtcars$wt # 2.620 2.875 2.320 ... 2.780 (32 obs) regression1 <- lm(mtcars$mpg ~ mtcars$wt) coef(regression1) # mpg ~ 37.2851 - 5.3445wt plot(mtcars$mpg ~ mtcars$wt, pch=19, col='gray50') # pch: shape of points abline(h=mean(mtcars$mpg), lwd=2, col ='darkorange') # The y-coordinate

Import column names from step wise regression in R

故事扮演 提交于 2019-12-02 12:03:05
I want to import the variables selected from the step-wise regression process as column names so that I have the "Output" has the variables from the step-wise regression as shown below. But, my code below does NOT do that. I cannot understand what I am doing wrong here. Can somebody help me please? iris$area <- iris$Petal.Length * iris$Petal.Width iris <- data.table(iris) mydata <- iris[Species %in% "virginica", list(Sepal.Length,Sepal.Width,Petal.Length,Petal.Width,area)] fit <- lm(area~., data=mydata) satis.step <- step(fit, direction="both") datanew <- iris[Species %in% "virginica", list