How to run a hodges-lehmann test in R or SPSS - r

How can I compute the Hodges-Lehmann (aligned ranks) test in R or SPSS? Is there are ready-made functions to call? I understood the formula,but if the Hodges-Lehmann test has already been implemented, there would be no need to create a new function .
I tried hodgeslehmann() in the senstrat package, but it's not what I need. It only computes Hodges-Lehmann Aligned Ranks, but couldn't give the statistical value.

An R version in a package called DescTools is documented here and also here.
Note especially that it will supply confidence intervals but only if you make use of the conf.level argument.
And there is SPSS Syntax code here, but you may prefer something that has had better open-source scrutiny.

Related

1 sample t-test from summarized data in R

I can perform a 1 sample t-test in R with the t.test command. This requires actual sets of data. I can't use summary statistics (sample size, sample mean, standard deviation). I can work around this utilizing the BSDA package. But are there any other ways to accomplish this 1-sample-T in R without the BSDA pacakage?
Many ways. I'll list a few:
directly calculate the p-value by computing the statistic and calling pt with that and the df as arguments, as commenters suggest above (it can be done with a single short line in R - ekstroem shows the two-tailed test case; for the one tailed case you wouldn't double it)
alternatively, if it's something you need a lot, you could convert that into a nice robust function, even adding in tests against non-zero mu and confidence intervals if you like. Presumably if you go this route you'' want to take advantage of the functionality built around the htest class
(code and even a reasonably complete function can be found in the answers to this stats.SE question.)
If samples are not huge (smaller than a few million, say), you can simulate data with the exact same mean and standard deviation and call the ordinary t.test function. If m and s and n are the mean, sd and sample size, t.test(scale(rnorm(n))*s+m) should do (it doesn't matter what distribution you use, so runif would suffice). Note the importance of calling scale there. This makes it easy to change your alternative or get a CI without writing more code, but it wouldn't be suitable if you had millions of observations and needed to do it more than a couple of times.
call a function in a different package that will calculate it -- there's at least one or two other such packages (you don't make it clear whether using BSDA was a problem or whether you wanted to avoid packages altogether)

Equivalent to R's sample(x,y,prob=) in Julia

Julia-users: is there an equivalent to R's sample(x,y,prob=) to sample from a given set of values with weighted probabilities? The rand() function is equivalent to sample(x,y), but as far as I'm aware there's no option to add probability weights... Any help appreciated!
OK - done a bit more digging and wsample from the Distributions package seems to be the answer:
using Distributions
wsample(population, weights, n)
Next time I'll look harder before posting!
wsample exists also in the StatsBase.jl package (which I am not sure is a more recent addition compared to when the question was first answered)
If you go by StatsBase.jl you can also just use "sample":
using StatsBase
sample(population, Weights(weights), n)
In both packages you can also set a random number generator and whether to take with replacement for both functions too.

Is ezPerm (of ez Package) an alternative for aovp (of lmPerm package)?

I was wondering if the ezPerm function (of ez Package) is an appropiate alternative for the aovp (of the orphaned and unsopported lmPerm package)?
The aovp function has been thepreferred option because it works exactly like aov. The ezPerm is faily easy to use but I am not sure if it is equivalent. And then there is the coin package that supposedly is able to do permutation tests, but I have failed finding a good explanation.
ezANOVA is parametric approach while ezperm is considered non-parametric approach so it does not require assumptions to be satisfied.
I have not used avop, but now I am considering it as an alternative to ezPerm. I tried using ezPerm, but it takes a lot of time for big data (only good for small data), and WARNING: interactions may not be trusted using this function, this packages is still a work in progress.
Regarding aov and ezAnova, I read that the problem with ezANOVA is that it doesn’t use formulae to define the model (Taken from = Just Enough R- Anova ‘Cookbook’). I feel like ezANOVA is a better option for repeated measures, otherwise they are almost the same.

What is the equivalent to Stata's portmanteau (Q) test for white noise in R?

Stata includes a a command (wntestq) that it calls the "portmanteau Q test for white noise." There seem to a variety of related tests in different packages in R. That said, most of these seem designed specifically for data in various time series formats and none that I could find that operate on a single variable.
"Portmanteau" refers to a family of statistical tests. In time series analysis, portmanteau tests are used for testing for autocorrelation of residuals in a model. The most commonly used test is the Ljung-Box test. Although it's buried in a citation in the manual, it seems that is the test that the Stata command wntestq has implemented.
R implements the same test in a function called Box.test() which is in the stats package that comes included with R. As you can see in the documentation for that function, Box.test() actually implements two tests: the Ljung-Box text that Stata uses and the Box-Pierce test. According to some sources, Box-Pierce was found to include a seemingly trivial simplification which can lead to nasty effects.[1][2] For that reasons, and because the defaults are different in R and Stata, it is worth noting that the Box-Pierce version is default in R.
The test will consider a certain number of autocorrelation coefficients (i.e., up to lag h) and there is no obvious default to select (see this question on the statistics StackExchange for a much more detailed discussion). Another important difference that will lead to different results is that the default h or number of lags will be different in Stata and R. By default, R will set h to 1* while Stata will set h to [n/2]-2 or 40, whichever is smaller.
Although there are many reasons you might not want the default, the following R function will reproduce the default behavior of the Stata command:
q.test <- function (x) {
Box.test(x, type="Ljung-Box", lag=min(length(x)/2-2, 40))
}

Matlab alternative function for ClustOfVar from R

I am working on clustering of variables in matlab. Two functions come in ClustOfVar package in R, called hcluster() and cutreevar().
I am good in Matlab and would like to use alternatives of hcluster() and cutreevar() in it.
Does Matlab has any inbuilt function which computes exactly same as hcluster() and cutreevar() does in R?
Need help.
Thanks
for heirarchical clustering you'll probably want to look at clusterdata. Note that you'll need the statistical toolbox for this function.

Resources