linear-regression

How can I plot my R Squared value on my scatterplot using R?

喜你入骨 提交于 2019-11-30 06:36:49
问题 This seems a simple question, so I hope its a simple answer. I am plotting my points and fitting a linear model, which I can do OK. I then want to plot some summary statistics, for example the R Squared value, on the plot also. I can only seem to get the R Squared value at the command line. Any advice; do I need to be looking at ggplot or anything else? Thanks in advance. #Does the plot plot(df$VAR1, df$VAR2) #Adds the line abline(lm(df$VAR2~df$VAR1), col="red") #Shows stats on command line

What is the difference between linear regression and logistic regression?

时间秒杀一切 提交于 2019-11-30 06:09:27
问题 When we have to predict the value of a categorical (or discrete) outcome we use logistic regression. I believe we use linear regression to also predict the value of an outcome given the input values. Then, what is the difference between the two methodologies? 回答1: Linear regression output as probabilities It's tempting to use the linear regression output as probabilities but it's a mistake because the output can be negative, and greater than 1 whereas probability can not. As regression might

Fitting linear model / ANOVA by group [duplicate]

安稳与你 提交于 2019-11-30 06:04:14
问题 This question already has answers here : Linear Regression and group by in R (10 answers) Closed 3 years ago . I'm trying to run anova() in R and running into some difficulty. This is what I've done up to now to help shed some light on my question. Here is the str() of my data to this point. str(mhw) 'data.frame': 500 obs. of 5 variables: $ r : int 1 2 3 4 5 6 7 8 9 10 ... $ c : int 1 1 1 1 1 1 1 1 1 1 ... $ grain: num 3.63 4.07 4.51 3.9 3.63 3.16 3.18 3.42 3.97 3.4 ... $ straw: num 6.37 6.24

Multiple regression analysis in R using QR decomposition

試著忘記壹切 提交于 2019-11-30 05:50:29
I am trying to write a function for solving multiple regression using QR decomposition. Input: y vector and X matrix; output: b, e, R^2. So far I`ve got this and am terribly stuck; I think I have made everything way too complicated: QR.regression <- function(y, X) { X <- as.matrix(X) y <- as.vector(y) p <- as.integer(ncol(X)) if (is.na(p)) stop("ncol(X) is invalid") n <- as.integer(nrow(X)) if (is.na(n)) stop("nrow(X) is invalid") nr <- length(y) nc <- NCOL(X) # Householder for (j in seq_len(nc)) { id <- seq.int(j, nr) sigma <- sum(X[id, j]^2) s <- sqrt(sigma) diag_ej <- X[j, j] gamma <- 1.0 /

D3.js linear regression

帅比萌擦擦* 提交于 2019-11-30 05:42:41
I searched for some help on building linear regression and found some examples here: nonlinear regression function and also some js libraries that should cover this, but unfortunately I wasn't able to make them work properly: simple-statistics.js and this one: regression.js With regression.js I was able to get the m and b values for the line, so I could use y = m*x + b to plot the line that followed the linear regression of my graph, but couldn't apply those values to the line generator, the code I tried is the following: d3.csv("typeStatsTom.csv", function (error, dataset) { //Here I plot

Pandas DataFrame - 'cannot astype a datetimelike from [datetime64[ns]] to [float64]' when using ols/linear regression

*爱你&永不变心* 提交于 2019-11-30 05:17:41
问题 I have a DataFrame as follows: Ticker Date Close 0 ADBE 2016-02-16 78.88 1 ADBE 2016-02-17 81.85 2 ADBE 2016-02-18 80.53 3 ADBE 2016-02-19 80.87 4 ADBE 2016-02-22 83.80 5 ADBE 2016-02-23 83.07 ...and so on. The Date column is the issue. I'm trying to get the linear regression of the Date column with the Close column: ols1 = pd.ols(y=ADBE['Close'], x=ADBE['Date'], intercept=True) I get the following error: TypeError: cannot astype a datetimelike from [datetime64[ns]] to [float64] I've tried

Linear regression with constraints on the coefficients

北城余情 提交于 2019-11-30 04:43:58
问题 I am trying to perform linear regression, for a model like this: Y = aX1 + bX2 + c So, Y ~ X1 + X2 Suppose I have the following response vector: set.seed(1) Y <- runif(100, -1.0, 1.0) And the following matrix of predictors: X1 <- runif(100, 0.4, 1.0) X2 <- sample(rep(0:1,each=50)) X <- cbind(X1, X2) I want to use the following constraints on the coefficients: a + c >= 0 c >= 0 So no constraint on b. I know that the glmc package can be used to apply constraints, but I was not able to determine

3D Linear Regression

倖福魔咒の 提交于 2019-11-30 04:15:31
I want to write a program that, given a list of points in 3D-space, represented as an array of x,y,z coordinates in floating point, outputs a best-fit line in this space. The line can/should be in the form of a unit vector and a point on the line. The problem is that I don't know how this is to be done. The closest thing I found was this link, though quite honestly I did not understand how he went from equation to equation and by the time we got to matrices I was pretty lost. Is there a generalization of simple 2D linear regression that I can use/can someone explain (mathematically) if/how the

6th degree curve fitting with numpy/scipy

∥☆過路亽.° 提交于 2019-11-30 04:00:40
I have a very specific requirement for interpolating nonlinear data using a 6th degree polynomial. I've seen numpy/scipy routines (scipy.interpolate.InterpolatedUnivariateSpline) that allow interpolation only up to degree 5. Even if there's no direct function to do this, is there a way to replicate Excel's LINEST linear regression algorithm in Python? LINEST allows 6th degree curve-fitting but I do NOT want to use Excel for anything as this calculation is part of a much larger Python script. Any help would be appreciated! Use numpys polyfit routine. http://docs.scipy.org/doc/numpy-1.3.x

Regression (logistic) in R: Finding x value (predictor) for a particular y value (outcome)

僤鯓⒐⒋嵵緔 提交于 2019-11-30 03:32:37
问题 I've fitted a logistic regression model that predicts the a binary outcome vs from mpg ( mtcars dataset). The plot is shown below. How can I determine the mpg value for any particular vs value? For example, I'm interested in finding out what the mpg value is when the probability of vs is 0.50. Appreciate any help anyone can provide! model <- glm(vs ~ mpg, data = mtcars, family = binomial) ggplot(mtcars, aes(mpg, vs)) + geom_point() + stat_smooth(method = "glm", method.args = list(family =