Skip to main content

Questions tagged [matlab]

A programming language/environment. Use this tag for any on-topic question that (a) involves MATLAB either as a critical part of the question or expected answer, & (b) is not just about how to use MATLAB .

Filter by
Sorted by
Tagged with
19 votes
2 answers
25k views

Correlation coefficient between a (non-dichotomous) nominal variable and a numeric (interval) or an ordinal variable

I've already read all the pages in this site trying to find the answer to my problem but no one seems to be the right one form me... First I explain you the kind of data I'm working with... Let's ...
cristis's user avatar
  • 193
22 votes
4 answers
39k views

k-means implementation with custom distance matrix in input

Can anyone point me out a k-means implementation (it would be better if in matlab) that can take the distance matrix in input? The standard matlab implementation needs the observation matrix in input ...
Eugenio's user avatar
  • 341
17 votes
1 answer
2k views

Non-uniform distribution of p-values when simulating binomial tests under the null hypothesis

I heard that under the null hypothesis the p-value distribution should be uniform. However, simulations of binomial test in MATLAB return very different-from-uniform distributions with mean larger ...
TanZor's user avatar
  • 425
7 votes
1 answer
3k views

Cross-validation techniques for time series data

What is an appropriate cross-validation technique for time series data? I have a daily 4 years time series data and fitting a SVM model by MATLAB R2015b: ...
user2991243's user avatar
  • 4,271
27 votes
3 answers
28k views

How can I generate data with a prespecified correlation matrix?

I’m trying to generate correlated random sequence with mean = $0$, variance = $1$, correlation coefficient = $0.8$. In the code below, I use s1 & ...
anisa's user avatar
  • 271
15 votes
1 answer
22k views

Generating values from a multivariate Gaussian distribution

I am currently trying to simulate values of a $N$-dimensional random variable $X$ that has a multivariate normal distribution with mean vector $\mu = (\mu_1,...,\mu_N)^T$ and covariance matrix $S$. I ...
Berk U.'s user avatar
  • 5,085
10 votes
2 answers
13k views

Normalizing a 2D-histogram and getting the marginals

I have a 2D-histogram for two vectors, s1 and s2, generated using the hist3 function in Matlab: [hist2D, binC] = hist3([s1' s2']); I am normalizing it by making ...
Rachel's user avatar
  • 591
15 votes
2 answers
23k views

How to perform cross-validation for PCA to determine the number of principal components?

I'm trying to write my own function for principal component analysis, PCA (of course there's a lot already written but I'm just interested in implementing stuff by myself). The main problem I ...
Kirill's user avatar
  • 652
9 votes
1 answer
3k views

The effect of the number of samples in different cells on the results of ANOVA

I have written a 3-way ANOVA in C++. I have 3 factors, lets say A, B and C and my aim is to check the strength of all possible interactions and main effects. The result of my code is the same as in ...
Pegah's user avatar
  • 427
4 votes
1 answer
3k views

How to compute PCA scores from eigendecomposition of the covariance matrix?

Given a data matrix $\mathbf X$ of $12 \times 7$ size with samples in rows and variables in columns, I have calculated centered data $\mathbf X_c$ by subtracting column means, and then computed ...
dato datuashvili's user avatar
47 votes
4 answers
107k views

How to interpret mean of Silhouette plot?

Im trying to use silhouette plot to determine the number of cluster in my dataset. Given the dataset Train , i used the following matlab code ...
Learner's user avatar
  • 4,477
22 votes
4 answers
118k views

Generate random numbers following a distribution within an interval

I need to generate random numbers following Normal distribution within the interval $(a,b)$. (I am working in R.) I know the function rnorm(n,mean,sd) will ...
dvs's user avatar
  • 323
19 votes
2 answers
18k views

Best way to perform multiclass SVM

I know that the SVM is a binary classifier. I would like to extend it to multi-class SVM. Which is the best, and maybe the easiest, way to perform it? code: in MATLAB ...
lakshmen's user avatar
  • 1,133
14 votes
2 answers
8k views

How to compare two or more correlation matrices?

I have $P$ correlation matrices $(n \times n)$ computed with $P$ sets of $(m \times n)$ data (observed) using the MATLAB function corrcoef. How do I compare and ...
armundle's user avatar
  • 243
13 votes
4 answers
11k views

How can I draw a value randomly from a kernel density estimate?

I have some observations, and I want to mimick sampling based on these observations. Here I consider a non-parametric model, specifically, I use kernel smoothing to estimate a CDF from the limited ...
tunar's user avatar
  • 543
5 votes
3 answers
3k views

Strange outcome when performing nonlinear least squares fit to a power law

I have a data set (given below in my MATLAB code) y vs. x and my eventual goal is to fit it to a power law $y=ax^b$ to see what exponent $b$ I get. I did some non-linear least squares fitting and ...
Fixed Point's user avatar
3 votes
2 answers
1k views

Do we always assume cross entropy cost function for logistic regression solution unless stated otherwise?

I am using Matlab glmfit for logistic regression. Now I know that usually people use the cross entropy to evaluate the error in predictions against the true labels ( which different than the linear ...
MrX's user avatar
  • 133
11 votes
3 answers
7k views

Confidence interval for cross-validated classification accuracy

I'm working on a classification problem that computes a similarity metric between two input x-ray images. If the images are of the same person (label of 'right'), a higher metric will be calculated; ...
Sean's user avatar
  • 113
11 votes
2 answers
6k views

QQ Plot Reference Line not 45°

I was plotting (standardized) return data with qqplot() in MATLAB against the theoretical quantiles of a normal distribution. However, the line in the QQ-Plot does ...
mscnvrsy's user avatar
  • 545
8 votes
2 answers
5k views

Confused by MATLAB's implementation of ridge

I have two different implementations of ridge in MATLAB. One is simply $\mathbf x = (\mathbf{A}'\mathbf{A}+\mathbf{I}\lambda)^{-1}\mathbf{A}'\mathbf b$ (as seen ...
Susie G.'s user avatar
7 votes
1 answer
5k views

Singular values of the data matrix and eigenvalues of the covariance matrix

I am having some problem in computing SVD and PCA in Matlab. I do not know if I am doing theoretical mistakes or programming mistakes. Starting with a data matrix $X$, PCA computes the eigenvalues $\...
Donbeo's user avatar
  • 3,209
6 votes
2 answers
13k views

Converting arbitrary distribution to uniform one

I have 500,000 values for a variable derived from financial markets. This variable has a arbitrary distribution. I need a formula that will allow me to select a range around any value of this variable ...
Mike Furlender's user avatar
6 votes
5 answers
10k views

Singular covariance matrix in Mahalanobis distance in Matlab

I am using the Mahalanobis distance to classify an unknown 64-dimensional vector into one of 75 classes. There are n samples of 64-dimensional vectors for each class, arranged into an Nx64 matrix ...
AruniRC's user avatar
  • 469
5 votes
1 answer
4k views

Why is ridge regression giving different results in Matlab and Python?

Why is the output from Matlab and Python vary for ridge regression? I use the ridge command in Matlab and scikit-learn in Python ...
prashanth's user avatar
  • 4,127
4 votes
1 answer
427 views

Smoothness of a surface

I am currently working on a model which takes two parameters and produces a measurement statistic. Think of it as Z = f(X,Y). Z is a matrix of my statistics and I am creating a surface plot of it in ...
user avatar
4 votes
1 answer
10k views

Using canonical correlation analysis (CCA) to find matches

I have a training dataset of images: X (Visual) and Y (Infrared). Each set has $300$ training examples. I extract feature ...
roni's user avatar
  • 173
2 votes
1 answer
268 views

Akaike Information Criterion I cannot interpret the result

Maybe is a silly question, or maybe I'm doing something wrong. I've tried to implement AIC criterion to estimate the optimum number of parameters using Auto Regressive (AR) linear models using white ...
AbateFaria's user avatar
18 votes
4 answers
12k views

Bootstrapping residuals: Am I doing it right?

First of all: From what I understood, bootstrapping residuals works as follows: Fit model to data Calculate the residuals Resample the residuals and add them to 1. Fit model to new dataset from 3. ...
Fred S's user avatar
  • 395
10 votes
2 answers
2k views

Implementation of Dirichlet cdf?

I need to compute the Dirichlet CDF, but I can only find implementations of the PDF. Do you guys know of any library (preferably in R) implementing it?
Ricky Robinson's user avatar
9 votes
5 answers
16k views

Making square-root of covariance matrix positive-definite (Matlab)

Motivation: I'm writing a state estimator in MATLAB (the unscented Kalman filter), which calls for the update of the (upper-triangular) square-root of a covariance matrix $S$ at every iteration (that ...
Gilead's user avatar
  • 381
8 votes
4 answers
2k views

FA: Choosing Rotation matrix, based on "Simple Structure Criteria"

One of the most important issues in using factor analysis is its interpretation. Factor analysis often uses factor rotation to enhance its interpretation. After a satisfactory rotation, the rotated ...
Yorgos's user avatar
  • 6,564
8 votes
5 answers
8k views

Mean squared error of OLS smaller than Ridge?

I am comparing the mean squared error (MSE) from a standard OLS regression with the MSE from a ridge regression. I find the OLS-MSE to be smaller than the ridge-MSE. I doubt that this is correct. Can ...
Aristide Herve's user avatar
6 votes
3 answers
10k views

LibSVM cost weights for unbalanced data doesn't work

I have a dataset where the number of negative labeled values is 163 times the number of positive labeled values. That is, I have an unbalanced data set. I tried: ...
kamaci's user avatar
  • 731
6 votes
1 answer
14k views

Bonferroni correction on multiple Kruskal-Wallis tests

My data consists of 3 groups, and 6 variables. The data are not normal so I want to use non-parametric tests to uncover significance. The first thing I wanted to get your opinion on is, is it ...
Joe's user avatar
  • 63
5 votes
2 answers
2k views

How to extrapolate this simple trend line into the future for the purpose of forecasting in Matlab?

We have the following data points in variable data pertaining to a problem that we are solving: ...
learnerX's user avatar
  • 223
5 votes
1 answer
7k views

Interpreting Gaussian probabilities greater than 1 [duplicate]

Possible Duplicate: Probability distribution value exceeding 1 is OK? I'm a bit confused how I am getting probabilities greater than 1 when calculating p(x | mu, sigma) when x = mu. For example, ...
Martin's user avatar
  • 53
4 votes
1 answer
2k views

Does random effects allow me to do repeated measures?

I am analysing some behaviour data from several participants in Matlab. I used to do "repeated measures" in SPSS. But is this the same as adding "subject" as a factor, and choosing it as a random ...
Sanjay Manohar's user avatar
3 votes
1 answer
11k views

Use Gaussian RBF kernel for mapping of 2D data to 3D

I am working on SVMs and try to get all the concepts involved. For instance, the kernel mapping. I would like to construct some parts of the algorithm by myself, to understand what is happening. My ...
Roemer's user avatar
  • 215
3 votes
1 answer
4k views

Ryan-Joiner test for normality in MATLAB

I have been reading about comparing Anderson-Darling, Ryan-Joiner and Kolmogorov-Smirnov tests at the Minitab blog, Anderson-Darling, Ryan-Joiner, or Kolmogorov-Smirnov: Which Normality Test Is the ...
r2d2's user avatar
  • 163
3 votes
1 answer
7k views

PCA using princomp in MATLAB

I'm trying to do dimensionality reduction using matlab princomp, but i'm not sure i'm do it right. here is the my code just for test, but I'm not sure that I'm doing projection right: ...
mrgloom's user avatar
  • 2,217
3 votes
1 answer
840 views

Removing nuisance PCA components from the fMRI data

So in attempting to replicate analysis pipeline from Tambini & Davachi, PNAS 2013, Persistence of hippocampal multivoxel patterns into postencoding rest is related to memory I'm hoping to use PCA ...
chainhomelow's user avatar
3 votes
1 answer
670 views

Weighted median of a portfolio

I need to calculate weighted median return for a portfolio (using MATLAB). There is information available online: MATLAB Central/rates&weights and Excel/note 4+4+4+7+7/5 logic How would you ...
Maddy's user avatar
  • 768
3 votes
1 answer
3k views

How can I perform a chi-square test for independence on signal samples?

Let's say I have two signals $x$ and $y$, sampled $N$ times, i.e. $$ x = [ x_{1}, x_{2}, ..., x_{N} ] $$ $$ y = [ y_{1}, y_{2}, ..., y_{N} ] $$ I would like to check whether $x$ and $y$ are ...
Rachel's user avatar
  • 591
2 votes
2 answers
1k views

How to compare different distributions with reference truth value in Matlab?

I have values from 4 different methods stored in the 4 matrices. Each of the 4 matrices contains values from a different method as: ...
user avatar
2 votes
0 answers
3k views

Computing and plotting a correlogram

I have a sample data for a spatial grid of size 20x20. I need to plot the correlogram of this grid of data to see how much they are correlated. Currently I have 400 data points for the 20x20 grid ...
rajan sthapit's user avatar
2 votes
3 answers
3k views

Issues with feature selection in matlab

I am trying to use sequentialfs to do some feature selection in matlab. I have huge dimensional data of 22215 features. When I tried to use sequentialfs with svm as classifier so that it selects the ...
user34790's user avatar
  • 6,817
2 votes
1 answer
2k views

Representative point of a cluster with L1 distance

The representative point of a cluster or cluster center for the k-means algorithm is the component-wise mean of the points in its cluster. The mean is chosen because it helps to minimize the within ...
Prateek Kulkarni's user avatar
2 votes
1 answer
3k views

How can I calculate central moments of a joint pdf?

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-...
Rachel's user avatar
  • 591
1 vote
1 answer
2k views

Generate t distributed random variable in matlab

How can we generate t distributed random variables with given mean and covariance in matlab. trnd is a function in matlab but we can get random variable with different degrees of freedom but how to ...
undefined's user avatar
  • 463
1 vote
3 answers
5k views

How to use an optimization solver to get t-stats and p-values for the estimates?

I calculate a data log likelihood (evaluated at a set of parameters to be estimated), and my task is to find the set of parameters that maximize my log likelihood. My problem is: thought there are a ...
Ruby's user avatar
  • 67