linear-regression

Time series prediction using R

不羁岁月 提交于 2019-12-20 14:12:28
问题 I have the following R code library(forecast) value <- c(1.2, 1.7, 1.6, 1.2, 1.6, 1.3, 1.5, 1.9, 5.4, 4.2, 5.5, 6, 5.6, 6.2, 6.8, 7.1, 7.1, 5.8, 0, 5.2, 4.6, 3.6, 3, 3.8, 3.1, 3.4, 2, 3.1, 3.2, 1.6, 0.6, 3.3, 4.9, 6.5, 5.3, 3.5, 5.3, 7.2, 7.4, 7.3, 7.2, 4, 6.1, 4.3, 4, 2.4, 0.4, 2.4) sensor<-ts(value,frequency=24) fit <- auto.arima(sensor) LH.pred<-predict(fit,n.ahead=24) plot(sensor,ylim=c(0,10),xlim=c(0,5),type="o", lwd="1") lines(LH.pred$pred,col="red",type="o",lwd="1") grid() The

How to get the confidence intervals for LOWESS fit using R?

╄→гoц情女王★ 提交于 2019-12-20 10:30:58
问题 I didn't find any satisfactory answer to the confidence intervals (CIs) for LOWESS regression line of the 'stats' package of R: plot(cars, main = "lowess(cars)") lines(lowess(cars), col = 2) But I'm unsure how to draw a 95% CI around it?? However, I know I could get the estimated variance from V = s^2*sum(w^2) where, s2= estimated error variance, and w=weights applied to the X. Therefore, the 95% CIs should be Y plus/minus 2*sqrt(V(Y)) I know there's a way of getting the CIs from loess fit,

How can I force cv.glmnet not to drop one specific variable?

蓝咒 提交于 2019-12-20 09:53:57
问题 I am running a regression with 67 observasions and 32 variables. I am doing variable selection using cv.glmnet function from the glmnet package. There is one variable I want to force into the model. (It is dropped during normal procedure.) How can I specify this condition in cv.glmnet? Thank you! My code looks like the following: glmntfit <- cv.glmnet(mydata[,-1], mydata[,1]) coef(glmntfit, s=glmntfit$lambda.1se) And the variable I want is mydata[,2]. 回答1: This can be achieved by providing a

Why do I get only one parameter from a statsmodels OLS fit

為{幸葍}努か 提交于 2019-12-20 08:28:25
问题 Here is what I am doing: $ python Python 2.7.6 (v2.7.6:3a1db0d2747e, Nov 10 2013, 00:42:54) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin >>> import statsmodels.api as sm >>> statsmodels.__version__ '0.5.0' >>> import numpy >>> y = numpy.array([1,2,3,4,5,6,7,8,9]) >>> X = numpy.array([1,1,2,2,3,3,4,4,5]) >>> res_ols = sm.OLS(y, X).fit() >>> res_ols.params array([ 1.82352941]) I had expected an array with two elements?!? The intercept and the slope coefficient? 回答1: Try this: X = sm

How can I force dropping intercept or equivalent in this linear model?

若如初见. 提交于 2019-12-20 06:21:58
问题 Consider the following table : DB <- data.frame( Y =rnorm(6), X1=c(T, T, F, T, F, F), X2=c(T, F, T, F, T, T) ) Y X1 X2 1 1.8376852 TRUE TRUE 2 -2.1173739 TRUE FALSE 3 1.3054450 FALSE TRUE 4 -0.3476706 TRUE FALSE 5 1.3219099 FALSE TRUE 6 0.6781750 FALSE TRUE I'd like to explain my quantitative variable Y by two binary variables (TRUE or FALSE) without intercept. The argument of this choice is that, in my study, we can't observe X1=FALSE and X2=FALSE at the same time, so it doesn't make sense

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)

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)

Free library for regression in c#

血红的双手。 提交于 2019-12-20 03:35:06
问题 Do you know of a free library in .net that I can use to fit a multivariate regression. I want to get the coefficients, and all the statistics (p-values, Std Errors, Goodness of Fitness, etc). I've tried Meta.Numerics, which works great, but it does not have some of the statistics. 回答1: Could R. be a solution? There are several ways you can incorporate R in C# http://rdotnet.codeplex.com/ R.NET enables .NET Framework to collaborate with R statistical computing. R.NET requires .NET Framework 4

Predict y value for a given x in R

南笙酒味 提交于 2019-12-20 03:07:31
问题 I have a linear model: mod=lm(weight~age, data=f2) I would like to input an age value and have returned the corresponding weight from this model. This is probably simple, but I have not found a simple way to do this. 回答1: If your purposes are related to just one prediction you can just grab your coefficient with coef(mod) Or you can just build a simple equation like this. coef(mod)[1] + "Your_Value"*coef(mod)[2] 回答2: Its usually more robust to use the predict method of lm : f2<-data.frame(age

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