regression

How do I plot Linear Regression?

。_饼干妹妹 提交于 2019-12-02 11:47:22
问题 I wish to learn how to use Plotly with Python for data analysis. I have been using this website as reference. My current code looks like this: from plotly import tools import plotly as py import plotly.graph_objs as go py.offline.init_notebook_mode(connected=True) # Create linear regression object regr = linear_model.LinearRegression() # Train the model using the training sets regr.fit(X_train, y_train) p1 = go.Scatter(x=X_test, y=y_test, mode='markers', marker=dict(color='black') ) p2 = go

Get p-value for group mean difference without refitting linear model with a new reference level

隐身守侯 提交于 2019-12-02 11:14:23
问题 When we have a linear model with a factor variable X (with levels A , B , and C ) y ~ factor(X) + Var2 + Var3 The result shows the estimate XB and XC which is differences B - A and C - A . (suppose that the reference is A ). If we want to know the p-value of the difference between B and C : C - B , we should designate B or C as a reference group and re-run the model. Can we get the p-values of the effect B - A , C - A , and C - B at one time? 回答1: You are looking for linear hypothesis test by

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

允我心安 提交于 2019-12-02 10:47:25
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 to have a mean, other than 0, for this level. With intercept m1 <- lm(Y~X1+X2, data=DB) summary(m1)

`nls` fails to estimate parameters of my model

余生颓废 提交于 2019-12-02 10:25:18
问题 I am trying to estimate the constants for Heaps law. I have the following dataset novels_colection : Number of novels DistinctWords WordOccurrences 1 1 13575 117795 2 1 34224 947652 3 1 40353 1146953 4 1 55392 1661664 5 1 60656 1968274 Then I build the next function: # Function for Heaps law heaps <- function(K, n, B){ K*n^B } heaps(2,117795,.7) #Just to test it works So n = Word Occurrences , and K and B are values that should be constants in order to find my prediction of Distinct Words. I

Testing a regression network in caffe

柔情痞子 提交于 2019-12-02 10:25:15
I am trying to count objects in an image using Alexnet. I have currently images containing 1, 2, 3 or 4 objects per image. For initial checkup, I have 10 images per class. For example in training set I have: image label image1 1 image2 1 image3 1 ... image39 4 image40 4 I used imagenet create script to create a lmdb file for this dataset. Which successfully converted my set of images to lmdb. Alexnet, as an example is converted to a regression model for learning the number of objects in the image by introducing EucledeanLosslayer instead of Softmax Layer. As suggested by many. The rest of the

Running lagged regressions with lapply and two arguments

喜欢而已 提交于 2019-12-02 10:23:37
问题 I am running multiple univariate regressions, like in this reproducible example: require(dynlm) data(USeconomic) US<-USeconomic vars<-colnames(US)[-2] a<-lapply(colnames(US),function(x) dynlm(log(GNP)~get(x),data=US)) a contains a list of 3 univariate regressions. Assume now I´d like to run the same regressions with 3 lags: l<-c(0,1,4) where 0 is of course the case I already got. Is there a way to use the vector l directly, like # this did not work for me, I obtain multivariate regressions

Linear combination of regression coefficients in R [closed]

ⅰ亾dé卋堺 提交于 2019-12-02 09:33:49
I need to run a multiple regression in R, with the variables X1, X2 and X3, where there is a variable θ = β2 + β3. So instead of β2, for the coefficient of X2 I need to use (θ - β3). How could I do this? Note that Y = b1 * x1 + (t - b3) * x2 + b3 * x3 is equivalent to Y = b1 * x1 + t * x2 - b3 * x2 + b3 * x3 = b1 * x1 + t * x2 + b3 * (x3 - x2) So, you can continue from there easily. 来源: https://stackoverflow.com/questions/53561699/linear-combination-of-regression-coefficients-in-r

Automate script to run linear regression R

空扰寡人 提交于 2019-12-02 09:31:01
I am looking to run Linear Regression on the below data frame. test<-data.frame(abc=c(2.4,3.2,8.9,9.8,10.0,3.2,5.4), city1_0=c(5.3,2.6,3,5.4,7.8,4.4,5.5), city1_1=c(2.3,5.6,3,2.4,3.6,2.4,6.5), city1_2=c(4.2,1.4,2.6,2,6,3.6,2.4), city1_3=c(2.4,2.6,9.4,4.6,2.5,1.2,7.5), city1_4=c(8.2,4.2,7.6,3.4,1.7,5.2,9.7), city2_0=c(4.3,8.6,6,3.7,7.8,4.7,5.8), city2_1=c(5.3,2.6,3,5.4,7.8,4.4,5.5)) Dataframe "test" is sample of the data. But original data frame contains 100 columns. I want to create a script for predicting values using linear regression. In this case, I want to build many models with different

How do I run an exponential nls with seasonal dummies in R?

人盡茶涼 提交于 2019-12-02 09:17:44
问题 I'm having trouble with running an nls regression with seasonal dummies in R. I'm able to do it without the seasonal dummies, but not with. This is what I have so far: year=floor(time(lsts)) > month=round(time(lsts)-year,4) > month.f=factor(month) > dummies=model.matrix(~month.f) hotdogNLS<-nls(lsts~beta1/(1+exp(beta2+beta3*t)),start=list(beta1=2500,beta2=0.5,beta3=-0.5),trace=F) summary(hotdogNLS) Formula: lsts ~ beta1/(1 + exp(beta2 + beta3 * t)) Parameters: Estimate Std. Error t value Pr(>

Running several simple Regression in R

两盒软妹~` 提交于 2019-12-02 08:27:03
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 this in one step and pull all of the p values into a table or write them to a CSV. I was following this