regression

degrees of freedom, t-statistic, and f-values of combined multiply imputed data

微笑、不失礼 提交于 2019-12-12 02:24:35
问题 I am a novice R user. I installed Zelig version 4.1-3 and Amelia II version 1.7. I am puzzled on how I can obtain the degrees of freedom, t-statistic, and f-values of combined multiply imputed data using R packages and functions. First, I loaded Amelia and Zelig: require(Amelia) require(Zelig) Then, I loaded the sample data that came with Amelia: data(freetrade) I created 5 imputations for this dataset using the amelia function. a.out <- amelia(freetrade, m = 5, ts = "year", cs = "country")

OLS of statsmodels does not work with inversely proportional data?

青春壹個敷衍的年華 提交于 2019-12-12 02:04:46
问题 I'm trying to perform a Ordinary Least Squares Regression with some inversely proportional data, but seems like the fitting result is wrong? import statsmodels.formula.api as sm import numpy as np import matplotlib.pyplot as plt y = np.arange(100, 0, -1) x = np.arange(0, 100) result = sm.OLS(y, x).fit() fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(20, 4), sharey=True) ax.plot(x, result.fittedvalues, 'r-') ax.plot(x, y, 'x') fig.show() 回答1: You're not adding a constant as the

missing value where TRUE/FALSE needed in R [duplicate]

怎甘沉沦 提交于 2019-12-12 01:52:03
问题 This question already has answers here : Error in if/while (condition) {: missing Value where TRUE/FALSE needed (2 answers) Closed 4 years ago . When I run the following code without commenting gr.ascent(MMSE, 0.5, verbose=TRUE) I receive this error Error in b1 * x : 'b1' is missing but when I comment that line I receive the following error when testing MMSE with these arguments MMSE(2,1,farmland$farm,farmland$area) . Do you know where my problem is lying? Error in if (abs(t[i]) <= k) { :

Moving window forecasting with Python

走远了吗. 提交于 2019-12-12 01:27:09
问题 I am looking to create some code that will out-of-sample forecast the HAR-RV model. The model itself is formulated as the following, and the betas are estimated through HAC-OLS or Newey-West. Where weekly and monthly are 5 and 22 daily averages of the daily RV, but if you're interested read more about it here. So I have all the data and parameters ready in pandas dataframes. I now wish to forecast on moving windows so that I can obtain a time series that will show me how the entire period

How to random search in a specified grid in caret package?

空扰寡人 提交于 2019-12-12 01:26:20
问题 I wonder it is possible to use random search in a predefined grid. For example, my grid has alpha and lambda for glmnet method. alpha is between 0 and 1, and lambda is between -10 to 10. I want to use random search 5 times to randomly try points in this bound. I wrote the following code for grid search and it works fine, but I cannot modify it for random search in a bound. rand_ctrl <- trainControl(method = "repeatedcv", repeats = 5, search = "random") grid <- expand.grid(alpha=seq(0,1,0.1)

How to debug “contrasts can be applied only to factors with 2 or more levels” error?

隐身守侯 提交于 2019-12-12 00:34:15
问题 Here are all the variables I'm working with: str(ad.train) $ Date : Factor w/ 427 levels "2012-03-24","2012-03-29",..: 4 7 12 14 19 21 24 29 31 34 ... $ Team : Factor w/ 18 levels "Adelaide","Brisbane Lions",..: 1 1 1 1 1 1 1 1 1 1 ... $ Season : int 2012 2012 2012 2012 2012 2012 2012 2012 2012 2012 ... $ Round : Factor w/ 28 levels "EF","GF","PF",..: 5 16 21 22 23 24 25 26 27 6 ... $ Score : int 137 82 84 96 110 99 122 124 49 111 ... $ Margin : int 69 18 -56 46 19 5 50 69 -26 29 ... $

gmm estimation error

╄→гoц情女王★ 提交于 2019-12-11 23:20:59
问题 In estimating GMM with more than one independent variables, The codes are do_gmm <- function(X) { DE <- X[, "DE"] rmrf_local <- X[, "rmrf_local"] SMB_L <- X[,"SMB_L"] h <- cbind(as.numeric(DE,rmrf_local,SMB_L)) coef(gmm(DE ~ rmrf_local,~SMB_L, x = h)) } r <- rollapplyr(ALLX0, 24, do_gmm, by.column = FALSE, fill = NA) The code works but in the output, i have only the first variable as follows > r (Intercept) rmrf_local [1,] 0.21 -0.32 [2,] 0.32 -0.04 [3,] -0.43 -0.03 [4,] -0.42 -0.23 I NEED

How I plot the linear regression

牧云@^-^@ 提交于 2019-12-11 23:05:32
问题 I am trying to plot a graph with the calculated linear regression, but I get the error "ValueError: x and y must have same first dimension". This is a multivariate (2 variables) linear regression with 3 samples (x1,x2,x3). 1 - First, I am calculating the linear regression correctly? 2 - I know that the error comes from the plot lines. I just don't understand why I get this error. What is the right dimensions to put in the plot? import numpy as np import matplotlib.pyplot as plt x1 = np.array(

Specifying a Constant in Statsmodels Linear Regression?

回眸只為那壹抹淺笑 提交于 2019-12-11 22:34:21
问题 I want to use the statsmodels.regression.linear_model.OLS package to do a prediction, but with a specified constant. Currently, I can specify the presence of a constant with an argument: (from docs: http://statsmodels.sourceforge.net/devel/generated/statsmodels.regression.linear_model.OLS.html) class statsmodels.regression.linear_model.OLS(endog, exog=None, missing='none', hasconst=None), where hasconst is a boolean. What I want to do is specify explicitly a constant C, and then fit a linear

Difftime Error using Looping Regressions in R

依然范特西╮ 提交于 2019-12-11 20:24:04
问题 With the below code I am getting the error Error in Ops.difftime((f - mean(f)), 2) : '^' not defined for "difftime" objects . This error only occurs with the inclusion of r_sq[[counter-lookback]] <- summary(temp_lm)$r.squared; which is located towards the end of the loop. I cannot find any similar error solutions online. Thank you for your help. #Import necessary packages require(quantmod) require(ggplot2) #Measure time used in processing ptm <- proc.time() ######### #Write in the ticker