instruction
stringlengths
9
38.7k
I want to run a binary logistic regression to model the presence or absence of conflict (dependent variable) from a set of independent variables over a 10 year period (1997-2006), with each year having 107 observations. My independents are: land degradation (categorical for 2 types of degradation); population increa...
Starting with arima models in R, I cannot make a forecast with my favourite model. For example, the commands predict(arima(data_ts,order=c(1,1,2),xreg=cbind(t),seasonal=list(order=c(0,1,1),period=12))) and forecast(arima(data_ts,order=c(1,1,2),xreg=cbind(t),seasonal=list(order=c(0,1,1),period=12))) don't work. Can ...
We have a sequence $\lbrace b \rbrace$ which is defined in a relation $b_i = b_{i-1} * 0.9 + t_i * 0.1$. If we have observations of the full sequence of $\lbrace b \rbrace$, it would be quite simple to calculate the values of $\lbrace t \rbrace$. However, the case is that we only have around $50\%$ to $80\%$ observatio...
I'm trying to fit a logistic model of the following form: $$ y \sim \frac{1}{1 + \exp(-\beta_X)} $$ where $$ \beta_X = a_0 + a_1x_1 + a_2x_2 + a_3x_3 + a_4x_4 + a_5x_5 $$ In my case, there is often good reason to first fit to a simpler model of $x_1$ and $x_2$; After that, fix $a_0, a_1$ and $a_2$, and then fit the r...
Background/how this came up: A student has numeric ratings on a variety of items in questionnaires and sports performance data and would like to model the performance on questionnaire scores. He wanted to do an analysis (don't ask me why) where some of the data are split into quantiles so he can compare high, medium, ...
One of the important OLS assumptions is a strict exogeneity assumption, i.e. $E(\epsilon_i | X) = 0, \forall i$. I'm interested in testing empirically this hypothesis, notably in the context of time series. It is known that exogeneity is rarely true in time series but assuming that the model is well specified, e.g. con...
I am very new in partial least squares (PLS) and I try to understand the output of the R function plsr() in the pls package. Let us simulate data and run the PLS: library(pls) n <- 50 x1 <- rnorm(n); xx1 <- scale(x1) x2 <- rnorm(n); xx2 <- scale(x2) y <- x1 + x2 + rnorm(n,0,0.1); yy <- scale(y) p <- plsr(yy ~ xx1+xx2,...
I have an estimated population size for which individual covariates are known for only a smaller sample of the population. So for example, my total population size is estimated to be 26.9 individuals/ha, SE = 4.4, lcl = 19.6, ucl = 36.9. I know that the population is 30% male, and 70% female (from a smaller sample of t...
I was studying on a PAMI article and I have seen an equation like this: $$ \begin{align*} P(B|X) &= \prod_c{P(B^c|X)} \\ &= \prod_c{P(B^c|A^c)} \end{align*} $$ where $A^c$ is a function of $X$. I know to fully understand the derivation details are needed, but what I am wondering is in under what circumstances w...
I have registry data for which I have data for individuals for each hospital attendance over a 10 year period. I wish to determine the effect of chronic antibiotic use upon acquisition of specific infections (outcome). However, often the choice of antibiotic may differ over time and so I want to be able to summarise ...
I am working with a time series (discrete) that has ideally 1 value per time stamp. In some cases, we are seeing multiples that have a wide range all recorded with the same time stamp. Up to now, we had been averaging the data but have found quite a few instances of very big ranges. Should we instead be considering t...
I'm using 2 kind of logistic regression - one is the simple type, for binary classification, and the other is ordinal logistic regression. For calculating the accuracy of the first, I used cross-validation, where I computed the AUC for each fold and than calculated the mean AUC. How can I do it for the ordinal logistic...
The question is similar to How to correlate two time series with gaps and different time bases? but with regular sample frequency and identical time base between two time series. Say I have two time series, one is the stock price for a given company, the other is the ratio of positive comments about the company on soci...
I have a dataset of some 100 samples, each with >10,000 features, some of which highly correlated. Here's what I am doing currently. Split the data set into three folds. For each fold, 2.1 Run elastic net for 100 values of lambda. (this returns a nfeatures x 100 matrix) 2.2 Take a union of all non-zero weights. (r...
Just a general question. Are there any good non-linear SVM (kernelized) implementations that include a regularization component (e.g. $L_1$, SCAD etc)? I've been looking around but man there are a lot of different bits and pieces of code in various languages everywhere. I've seen some stuff on R, but it looks like most...
I have a dataset with 43,422 observations and a left-censored (at 0) dependent variable. Of the $n$ observations, 42,536 are left-censored and 886 are not. I plan on analyzing this with a Tobit model and discovered there are three different implementations in R (AER, VGAM, and censReg). Without thinking through a mo...
Can someone help me with this one? A fair coin is tossed 5 times, what is the probability of a sequence of 3 heads? I can see that there are 2*2*2*2*2 possible outcomes, but how many of these include 3 heads in a sequence and why?
Here is an explanation of how NPS is calculated: http://en.wikipedia.org/wiki/Net_promoter_score I'm interested in testing two net promoter scores to determine if they are statistically different. I read a great answer to calculating margin of error for NPS (see link below), but I'm really interested in testing to see ...
Suppose I have a set of $k$ matrices. $$ \mathbb D = A_1,A_2,...,A_k $$ Each column of $A$ is categorical vector. $$ A = v_1,v_2,...,v_n $$ I want to find the mapping $$ f: A \rightarrow Q $$ Where $Q$ is a $(n,n)$ matrix such that $$ \frac{1}{k} \sum_k \text{MSE}\left(Q_{k,real}(ij) - Q_{k,predict}(i...
I am estimating the effect of $x$ on $y$; $y$ and $x$ are available both by city and by year. During the first period, $T_1$, both $x$ and $y$ generally increase. During the second period, $T_2$, both generally decrease. I have about 30 cities over 40 years. How can I use regression to attribute the average effect...
I'm not sure what this is called but I remember seeing a colleague of mine doing a multivariate regression much like $$Y \sim X_1 + X_2 + X_3$$ and then he said he would "orthogonalize" so he regressed each of the IVs against the other ones, and took the residuals..as in: $$Z_1 = \text{residuals}(X_1 \sim X_2 + X_3)$$ ...
I have data that is, at its most basic level, activity counts per minute of fruit flies. Flies are considered to be asleep when they have no activity for at least 5 minutes. The data essentially looks somewhat like a sinusoidal curve when plotted as activity vs. time or sleep vs. time. I have researched various normali...
I'm trying to convert a bunch of Stata commands to their R equivalents, and I'm struggling with how R does handle confidence intervals for inferential statistics of single variables. In Stata, I can use ci variable to calculate normal confidence intervals, ci variable, b to calculate binomial intervals, and ci variable...
In baseball statistics, there is a statistic called "luck" which is the difference between a team's win-loss record and their Pythagorean win-loss record. This statistic is supposed to measure how lucky or unlucky a team was to win however many games they did in a season. Suppose one has a big data set which, for each...
SPSS uses the Levene test to evaluate homogeneity of variances in the independent group t-test procedure. Why is the Levene test better than a simple F ratio of the ratio of the variances of the two groups?
When doing a paired t-test, is it appropriate to use the paired t value to calculate $\eta^2$? I ask because it is not appropriate to calculate Cohen's d based on the paired t value. Thanks.
I am working on a problem that its difficult part is to invert a covariance matrix (in R). I could not use usual approches like SVD and Chol. Then, I decided to use a Discrete Fourier Transform (DFT) approach. But I couldn't understand how to apply the method, especially in R. So, your comments and possible examples in...
I'm using PCA to reduce dimensionality before I feed the data into a classifier. My bootstrap/cross-validation has shown a significant reduction in test error as a result of applying PCA and keeping the PCs whose standard deviation is a fraction (say, 0.05) of the standard deviation of the first PC. My features are act...
Volume 45 of the Journal of Statistical Software contains articles about packages that deal with imputation of missing data, one of which is the mi package. In the PDF article regarding that package there is an example about a study of HIV-positive people. Below I copy the R commands and the output. library(mi) data(CH...
Whenever I read about repeated measures or within-subjects design in different books and on webpages, the example that always is brought up is some kind of longitudinal or repeated measures design (e.g. people are measured on the same scale several times during the day). For my experiment, I have showed people a number...
Can anybody give me a good reference on Almon model for time-series analysis. Also, what's the basic difference between Koyck model & Almon model.
I have a bunch (around 1000) of estimates and they are all supposed to be estimates of long-run elasticity. A little more than half of these is estimated using method A and the rest using a method B. Somewhere I read something like "I think method B estimates something very different than method A, because the estimate...
The model is from sports. I'm trying to predict the win percentage of each team in the next season based on information available before that season. I have about 240 observations of the numbers of wins in various seasons for various teams, along with the corresponding values of possible predictors. I want to build a ...
I would like to fit a spatial generalized linear mixed model, for example, to model spatial count responses by using the Laplace approximation in available statistical software. I am particularly interested in implementations in R.
Suppose I'm trying to predict $Y$ (a real number) and I have $n$ experts with guesses $Y_1,...Y_n$. Each prediction is a reasonable guess as to the value of Y in itself (hence the name "expert"), but we should be able to come up with a better prediction for $Y$ by combining the experts' guesses. We could take our guess...
I am concerned about how unequipped most people are (both within and without academia) to properly employ standard model building methods such as linear regression and to interpret the results of these models. Both from my own observations and the literature, it is clear that most people are being poorly served by the ...
It's hard for me to accept that Donald Rubin would ever come up with a true lemon of a technique. Yet, that's my perception of the BESD [1, 2, 3]. The original paper by Rosenthal and Rubin (1982) claimed that there was value in showing "how to recast any product-moment correlation into such a [2x2] display, whether the...
I am trying to use Gibbs Sampling to simulate a random sample from a joint distribution $f(\beta ,{{Z}_{1}},...,{{Z}_{75}},{{\lambda }_{1}},...,{{\lambda }_{75}})$, where the fully conditioned distribution function are: $$\beta |{{Z}_{1}},...,{{Z}_{75}},{{\lambda }_{1}},...,{{\lambda }_{75}}\sim N\left( \frac{\sum\limi...
I'm ultimately looking to apply cross-validation to a much more complicated scenario, but for now consider the simple task of leave-one-out-cross-validating logistic regression. When you compare the left-out value against its respective model's predicted value, I presume you must convert the predicted value to the prob...
I am running the following unit root test (Dickey-Fuller) on a time series using the ur.df() function in the urca package. The command is: summary(ur.df(d.Aus, type = "drift", 6)) The output is: ############################################### # Augmented Dickey-Fuller Test Unit Root Test # ##########################...
I've been reading about stacked regression, as described, for example, here. It seems it's important that when you regress against the first predictors, you require that the regression coefficients are non-negative. How does one do that in R?
How can I create Sankey diagrams?
I am conducting an experiment which has the following: DV: Slice consumption (continuous or could be categorical) IV: Healthy message, unhealthy message, no message (control) (3 groups in which people are randomly assigned - categorical) This is a manipulated message about the healthiness of the slice. The following...
Is it possible to perform principal component analysis on variables that have different number of rows of data? For instance, if there were just three variables - Var1, Var2, Var3 - where Var1 has 100 rows of data, Var2 has 50 rows, and Var3 has 20 rows. Can PCA be performed on such a data set? If PCA is possible, do ...
I'm reasonably certain the absolute value of the distance covariance satisfies $d(x, y) \ge 0$ (non-negativity, or separation axiom) $d(x, y) = 0$ if and only if $x = y$ (identity of indiscernibles, or coincidence axiom) $d(x, y) = d(y, x)$ (symmetry) But I'm not sure about: 4) $d(x, z) \le d(x, y) + ...
I have a bootstrap sample of a parameter and I want to calculate the confidence intervals that 'boot.ci' from the R package 'boot' produces: "norm","basic","perc","bca"and "stud; but I do not have an object of class 'boot', I just have the bootstrap sample. Do you know another package that I could use for this purpo...
I'm trying to perform a knn regression on a sales time series using the kknn package. I can't see how you can restrict the neighbours to past sales only though. e.g. Product, Price, Sale Date A, £100, 2012-01-04 A, £100, 2012-01-05 A, £200, 2012-01-06 If I want to predict for the second row, it sh...
Can anyone provide or point me to a freely available implemention of Elastic Net in C or C++?
I'm using PASWStatistics18 and K-Means clustering data that I'd previously clustered using an earlier version of SPSS... My problem is that I'm getting different cluster results depending on how the data file is sorted. I can't remember this being an issue in the earlier versions of SPSS, but I can't repeat the same r...
I understand that HMM models model language with Parts of Speech (POS) as hidden states and words as observations. These HMM models are usually learned from large text corpora, and many of these corpora are publicly available. Where can I find such models with their parameters, i.e., the list of POS or other hidden sta...
When I compute the five-number summary on my sample, I obtain quantiles that differ from the quantiles I got from the empirical cdf, since they are not normally distributed data. Can you help me in the interpretation of this difference? For instance, with a randomly-generated Poisson dataset x x=rpois(50, 2) summary(x...
Does there exists a Box-Cox method for linear Gaussian models with random effects ?
I need a one-sentence explanation of the use of the AIC in model-building. So far I have "Simply put, the AIC is a relative measure of the amount of observed variation accounted for by different models and allows correction for the complexity of the model." Any advice much appreciated. R
Searching the internet for PCA tutorial gives thousands of results (even videos). Many of the tutorials are very good. But I am not able to find any practical example where PCA is explained using some data-sets which I can use for demonstration. I need a tutorial which provides some small data set which is easy to plot...
I will ask my question beginning by an example (I am novice in stats) I have a set of probabilities from a given observation A={0.3,0.2,0.001, 0.02, ...} I want to partition A on subsets or clusters so as each one will contain the closest probabilities. And after, i will be interested in calculating the distances betwe...
I have a data frame with two categorical variables (representing different methods) that "classify" objects into three categories: cat1, cat2, cat3. The objects are classified somewhat differently by the two variables and I would like to perform a test described as "Measuring Agreement Between Observers" in Agresti's C...
I have a number of samples $X_1,\ldots,X_n $ from Gaussian distributions centered at $\mu_1,\ldots,\mu_n $ respectively. I need to construct a confidence interval for the biggest difference between means $\max_{1\leq i<j\leq n}|\mu_i-\mu_j|.$ How can this be done? Probably that interval should be wider than the ordinar...
I have a distribution of observed measurements and I want to compare it to sampled distributions, using R. I have a program that samples distributions, according to a certain low of probability / constraint. Suppose I have: $m$ observed measurements two sets of $n$ samples of $m$ measurements I'd like to compute: ...
I am using plm() to estimate fixed-effects models of the form y ~ x + time + time:fixed_trait where fixed_trait is a variable that varies across individuals but is constant within individuals. The point of interacting time with fixed_trait is to permit the effect of fixed_trait to vary across time. (I am working here...
Suppose I have two samples, and I'd like to compare them to see if they come from the same underlying distribution. Normally, I would probably do this using a KS test. However, suppose also that I have some 'weight' for each observation in each of the two samples indicating how 'sure' I am that the sampled value is 'ac...
Suppose we have three different treatments A, B, and C and we are modeling response(0,1). I want to know how to do sample size determination for each group(A,B,C) given say normal priors on each group. I need to show how we can (and how much we can reduce) the sample size and get similar testing of differences in main...
I'm interested into the Portmanteau tests for fitting ARIMA models and ended up to Ljung-Box test and their implementations for R-statistics. I've read already some relative question on the subject and came to the conclusion that the safest way to reject the null hypothesis is when p<0.05. However I was browsing this s...
I have 10 measures of snakes that are strongly correlated (body length, tail length and 8 measures of head size). My dataset consists of different snake sizes (but excluded non-adults) so smaller (younger) snakes have smaller heads and shorter tails (because they depend on body length). Usually there are two approaches...
If you use 10-fold cross validation to derive the error in, say, a C4.5 algorithm, then you are essentially building 10 separate trees on 90% of the data to test on 10% - 10 times. Which one of the 10 trees is representative? Won't they all be different? For example - how does WEKA give me a C4.5 tree and a cross-valid...
I've ran across a type of classification problem that I don't think fits into the traditional multi-class framework. Just wanted to run it across you guys to see if you had any ideas. So Lets say we have 3 drugs - drug A, B, C - and we serve it to 100 patients The for each patient we have three types of information: P...
In many studies of heritability, researchers study identical twins raised apart and raised together, and see how much a trait correlates between the two types of twins. Sometimes they use fraternal twins, there are a few variations on the scheme. But while we can measure how similar two people are in terms of their gen...
I have several test results of server response delay. According to our theory analysis, the delay distribution (The probability distribution function of response delay) should have heavy-tail behavior. But how could I prove that the test result does follow heavy-tail distribution?
I have been asked to do some real time data analysis. The data values represent parameters of phone calls for a telco (like number of calls, call length, etc.) If the numbers suddenly drop or spike, I'm supposed to raise an alarm. Normal noise is expected, but we want to know if things change suddenly, like if no on...
I have a chi squared of 0.1185 with 1 degree of freedom. How can i determine the P-value?
A regression in which all the IVs are replaced by their residuals after regressing them with the rest of the IVs. I have seen (for example in Elements of Statistical Learning) how doing this in a multivariate regression yields the multivariate coefficients from univariate regressions. But other than this, why would one...
Are there any multiple linear regression methods or packages that are resilient to occasional missing values? I have no prior view on imputing the missing values based on the nature of the data, and I would like to avoid discarding rows that have NAs. Although I am not performing a panel regression, my data is arranged...
I have a lot of data sets corresponding to particular events, each event is a collection of some $N$ real values between 0 and 1. Some of these events don't interest me, and I want to filter them out. To this end I want to associate with each event a value that would let me order events from the most useful to least us...
I own a software business that follows a common pattern: Interested people can download the software and try it free for 30 days, and if they like it, they can buy it at any time during those 30 days (or after). I'd like to calculate my "conversion rate," which I will define as the percentage of downloads that lead to ...
What is the formula for calculating p-value of Tukey HSD http://onlinestatbook.com/calculators/tukeycdf.html
There is a paper that uses something like the 2-sigma limit to check if a quantity is more-or-less constant. More specifically in this paper on Text Detection (Sec. 3.2 3rd para last line) this limit is used to check for constant stroke width i.e. something like if mean > 2*sigma. This relation is not explicitly stated...
I know that for each feature-class pair, the value of the chi-square statistic is computed and compared against a threshold. I am a little confused though. If there are $m$ features and $k$ classes, how does one build the contingency table? How does one decide which features to keep and which ones to remove? Any clari...
I was speaking to a statistician recently who suggested that using dummy variables rather than one variable with several levels reduced the constraints on models, particular reducing the assumption of linearity. I didn't understand the explanation and was wondering if someone could make it clear?
I've been reading on how to calculate confidence levels from A/B tests, as I'm running some ads on Facebook and want to better understand the results. The clearest explanations I've found seem to offer two alternatives: Chi-Square and Binomial Random Variables. I'm hoping someone can explain which is more appropriate....
I have a dataset containing multiple proportions that add up to 1. I am interested in the change of these proportions along a gradient (see below for example data). gradient <- 1:99 A1 <- gradient * 0.005 A2 <- gradient * 0.004 A3 <- 1 - (A1 + A2) df <- data.frame(gradient = gradient, A1 = A1, ...
I would like to generate thousands of distributions with respect to: VaR@5%=-7% and Median=0%. A first idea: Choose a family, say the Gaussian one. Estimate its parameters. This is straightforward for the Gaussian but let's write the general algorithm (see mpiktas' answer on Estimating a distribution based on three pe...
I am performing a returns analysis. The idea is to regress a time-series of returns on the returns of various asset classes. The beta coefficients must be constrained such that sum of the coefficients is 1 and no coefficient is less than 0 or greater than 1. These beta coefficients can then be interpreted as explaining...
Suppose I want to know whether a baseball team's winning percentage the previous season or the Pythagorean expectation of that team from the previous season is a better predictor of next season's win percentage. (I take percentages because the number of games played per season has changed in the past, so it seems easie...
A colleague of mine has asked me for help on this problem, but I am confused with it as well, the main question he asked me was that the chi-square result he was getting was very high. He conducted a survey, and among other questions, one of them is a question which has 8 sub-questions about certain processes in compan...
The necessary context is, I want to model the world as states, and a state is a frequency distribution of people's opinions. So I wonder if I can use a random variable, say $T$, to model the state the world is in and hence the frequency distribution. Thanks.
Suppose a variable $T$ (temperature) is coded as follows: $T = 1$ if temperature < 10, $T = 2$ if 10 < temperature < 40, and $T=3$ if temperature > 40. Is it better to treat $T$ as a categorical variable?
Suppose you are using $\alpha = 0.01$ as the significance level. IF you are not getting significant results, is it better to increase the significance level to $\alpha = 0.05$?
I am trying to propose Gibbs sampling with the density below, $$p(y_1,y_2,y_3)\propto \exp [-({{y}_{1}}+{{y}_{2}}+{{y}_{3}}+{{\theta}_{12}{y_1}{y_2}}+{{\theta }_{13}{y_3}{y_1}}+{{\theta }_{23}{y_2}{y_3}})]$$ where, $({{y}_{1}},{{y}_{2}},{{y}_{3}})\in R_{+}^{3}$ and ${{\theta }_{ij}}=i+j$ How do I find the full conditio...
If I am selecting 232 people from a pool of 363 people without replacement what is the probability of 2 of a list of 12 specific people being in that selection? This is a random draw for an ultra race where there were 363 entrants for 232 spots. There is an argument about whether the selection was biased against a cert...
For $a_1,a_2$ and $b_1,b_2$, $\in\Re^+$, if $a_1<b_1$ , then for any perturbation by a random variable $\epsilon\in \Re^+$, $$r_1=\frac{a_1+\epsilon}{b_1+\epsilon}>\frac{a_1}{b_1} $$ and if $a_2>b_2$, $$r_2=\frac{a_2+\epsilon}{b_2+\epsilon}<\frac{a_2}{b_2} $$ If $\epsilon$ is generated from a density as, $\epsilon_1={...
Let's say I have two signals $x_1$ and $x_2$, each having $N$ samples, i.e.: $$ x_1 = \{ x_{11}, x_{12}, ..., x_{1N} \} $$ $$ x_2 = \{ x_{21}, x_{22}, ..., x_{2N} \} $$ The signals are both zero-mean. (Each signal's mean has already been subtracted from all of that signal's elements.) Since the signals are both zero-m...
I have an $n\times p$ matrix, where $p$ is the number of genes and $n$ is the number of patients. Anyone whose worked with such data knows that $p$ is always larger than $n$. Using feature selection I have gotten $p$ down to a more reasonable number, however $p$ is still greater than $n$. I would like to compute the si...
Using Cohen's $d$, I am getting small and medium effect sizes for results that are statistically non-significant ($p>.05$). Does this make sense?
I want to do multiple linear regression and then to predict new values with little extrapolation. I have my response variable in the range from -2 to +7, and three predictors (the ranges about +10 - +200). The distribution is nearly normal. But the relationship between the response and the predictors is not linear, I s...
Suppose you have variables $X_{1}, \dots, X_{100}$ (can be discrete or continuous). If you want to test all possible interactions, should you include them all in 1 model? We are doing linear regression here.
Suppose that I am interested in selecting from one of the following model spaces: $$\begin{align*} y &= \beta_0 + \beta_1 x_i + \epsilon_i \, \, \text{or} \\ \log (y_i) &= \gamma_0 + \gamma_1 x_i + \eta_i. \end{align*}$$ I intend to use cross validation for making my selection. If I calculate the prediction errors on ...
Using R, I have fitted a linear model for a single response variable from a mix of continuous and discrete predictors. This is uber-basic, but I'm having trouble grasping how a coefficient for a discrete factor works. Concept: Obviously, the coefficient of the continuous variable 'x' is applied in the form y = coefx(v...
Suppose products A, B and C are sold on markets 1, 2 and 3. I have access to three years worth of monthly historical data. I'd like to detect/foresee possible shifts in sales mix for the three products over the three markets (e.g. I'd like to know if market 1 is buying more of product A than it used to, or if product B...
I am building a Logistic regression model for a churn problem. When I scored the out of sample data set, I find very low probability levels as the output probability. Conventionally, I would look for .5 as the cut off but this scored population doesnt have many customers above .5 ( say just 1%). Seeing the business cau...
Suppose we have a categorical variable $X_1$ with $100$ levels. Should we not test interaction between $X$ and some other variable $X_2$? Because if, for example, $X_1(3)*X_2$ is not significant then the interaction between $X_1$ and $X_2$ is not significant?
I am doing some multiple regression using R's lm() method. I wonder whether there is an easy way to limit the impact of some predictors. I think lm() results give too much weight to certain predictors and I would like to somehow cap coefficients of certain predictors. Is it doable?