regression

plot regression line in R

被刻印的时光 ゝ 提交于 2019-12-20 06:09:15
问题 I want to plot a simple regression line in R. I've entered the data, but the regression line doesn't seem to be right. Can someone help? x <- c(10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120) y <- c(10, 18, 25, 29, 30, 28, 25, 22, 18, 15, 11, 8) df <- data.frame(x,y) plot(y,x) abline(lm(y ~ x)) 回答1: Oh, @GBR24 has nice formatted data. Then I'm going to elaborate a little bit based on my comment. fit <- lm(y ~ poly(x, 3)) ## polynomial of degree 3 plot(x, y) ## scatter plot (colour: black)

Adjust function for log(0)

老子叫甜甜 提交于 2019-12-20 05:45:39
问题 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

In r, get output values in power curve for 'a' and 'b' values

淺唱寂寞╮ 提交于 2019-12-20 04:36:54
问题 I apologise for this basic question but i am truly stuck for whatever reason. I am hoping to get the output values from a power curve of 'a' and 'b' from y = a*x^b. Assuming i have this data set: x y log10(x) log10(y) 7 240 0.84509804 2.380211242 45 610 1.653212514 2.785329835 14 340 1.146128036 2.531478917 30 500 1.477121255 2.698970004 24 450 1.380211242 2.653212514 57 690 1.755874856 2.838849091 And it produces this graph in excel: Using the excel example, how would i get the output values

Stata: combining coefficients/standard errors from several regressions in a single dataset (number of variables may differ)

走远了吗. 提交于 2019-12-20 04:32:59
问题 I have already asked a question about storing coefficients and standard errors of several regressions in a single dataset. Let me just reiterate the objective of my initial question: I would like to run several regressions and store their results in a DTA file that I could later use for analysis. My constraints are: I cannot install modules (I am writing code for other people and not sure what modules they have installed) Some of the regressors are factor variables. Each regression differ

Finding a point that best fits the intersection of n spheres

心已入冬 提交于 2019-12-20 04:27:09
问题 I have an array of points with distances. I wish to find a point that best satisfies the condition that for (point_i, distance_i) in pointArray: abs(point - point_i) = distance_i I think this could be solved with some kind of regression or least squares, but I'm having trouble with the problem formulation. If anyone could help out, it would be greatly appreciated 回答1: You need to define "best" to have an answerable question. What you probably want to do is define some sort of error function

R: build separate models for each category

女生的网名这么多〃 提交于 2019-12-20 03:49:05
问题 Short version : How to build separate models for each category (without splitting the data). (I am new to R) Long version: consider the following synthetic data housetype,ht1,ht2,age,price O,0,1,1,1000 O,0,1,2,2000 O,0,1,3,3000 N,1,0,1,10000 N,1,0,2,20000 N,1,0,3,30000 We can model the above using two separate models if(housetype=='o') price = 1000 * age else price = 10000 * age i.e. a separate model based on category type? This is what I have tried model=lm(price~housetype+age, data=datavar)

How to plot a regression plane with an interaction in rgl

折月煮酒 提交于 2019-12-20 03:26:06
问题 I want to plot the regression surface from a model with an interaction term using rgl 's interactive plotting system. It is easy to plot a regression plane for a model without an interaction term using: plot3d(x=x1, y=x2, z=y1, type="s", col="yellow", size=1) planes3d(a=coef(mod1)[2], b=coef(mod1)[3], c=-1, d=coef(mod1)[1], alpha=.5) However, when the plane twists, this seems to be more difficult. Following on this question: 3D equivalent of the curve function in r, I am trying: f2 <-

Constrained linear regression coefficients in R [duplicate]

大城市里の小女人 提交于 2019-12-20 02:43:19
问题 This question already has an answer here : R : constraining coefficients and error variance over multiple subsample regressions [closed] (1 answer) Closed 3 years ago . I'm estimating several ordinary least squares linear regressions in R. I want to constrain the estimated coefficients across the regressions such that they're the same. For example, I have the following: z1 ~ x + y z2 ~ x + y And I would like the estimated coefficient on y in the first regression to be equal to the estimated

How to plot a linear regression to a double logarithmic R plot?

江枫思渺然 提交于 2019-12-20 01:09:28
问题 I have the following data: someFactor = 500 x = c(1:250) y = x^-.25 * someFactor which I show in a double logarithmic plot: plot(x, y, log="xy") Now I "find out" the slope of the data using a linear model: model = lm(log(y) ~ log(x)) model which gives: Call: lm(formula = log(y) ~ log(x)) Coefficients: (Intercept) log(x) 6.215 -0.250 Now I'd like to plot the linear regression as a red line, but abline does not work: abline(model, col="red") What is the easiest way to add a regression line to

R plot.gam Error “Error in 1:object$nsdf : argument of length 0”

回眸只為那壹抹淺笑 提交于 2019-12-19 19:52:46
问题 I am trying to plot a gam object in R, which I made with the gam package. I receive the same error reported in Error in 1:object$nsdf : argument of length 0 when using plot.gam. However, the solution found there, updating to the latest versions (I think), is not working for me. I am running R 3.3.1, gam 1.12, and mgcv 1.8.12 (mgcv is where the plot.gam function is from). Unfortunately, I cannot share the data I am working with. However, the following code -- pulled directly from the p.294 of