R Single sample K-S Test - r

This site gives a great example on how to execute a two-sample K-S test in R
Upon reading the documentation, I'm completely lost about how I can execute a single sample K-S test. I understand that y can be "a numeric vector of data values, or a character string naming a cumulative distribution function or an actual cumulative distribution function such as pnorm. Alternatively, y can be an ecdf function (or an object of class stepfun) for specifying a discrete distribution."
I tried passing in one variable, got this error message: "argument "y" is missing, with no default"
Thinking about how pnorm can be used I recall this link. Not sure which one would be applicable in the case where I want to execute a single sample K-S test.

Related

can't fit GLM with family binomial and log link to estimate RR

I am trying to estimate relative risk using log-binomial model using the glm function. Although it works well with univariable analysis, it gives me an error message when I add multiple variables
This is the error message I get
Error: no valid set of coefficients has been found: please supply starting values.
I did some search but couldn't find a way to solve this issue
Thanks
This error can happen for one of two reasons. First, if any of the deviances are infinite, and second, if invalid starting values have been supplied. Assuming that you haven't supplied starting values, then I suggest doing so, by using the start = option in glm.
Having said that, the only times I have seen this problem is when either the dataset is pathological, or the model is wrong (for example using an inappropriate link function). Since you don't supply a reproducible example, there isn't much more we can say.

mma code error: Must use a vector in `[`, not an object of class matrix

I am using every variation of code I can think of to run a multiple mediation using the mma package in R and I keep getting the same error.
I've used a ton of different variations, but this is the main bit of code I'm trying to run just to identify the mediators vs. covariates.
data.bin<-data.org(x,y,pred=2,mediator=c(1,7:11),alpha=.05,alpha2=.05)
Error: Must use a vector in [, not an object of class matrix.
Call rlang::last_error() to see a backtrace
pred is the data frame of predictor(s). It is separate from x, the data frame of covariates and mediators.
An older version uses pred to indicate the column number of predictor (exposure) in x. This has been changed.

Problems fitting arbitray distributions using the fitdistplus package

I am trying to fit my data using the fitdist() function from the fitdistrplus package in R. I succeeded using a normal and a lognormal distribution via key words 'norm' and 'lnorm' which I found via searching online.
I was not able to get other distributions working; the help of fitdist() says:
distr: A character string "name" naming a distribution for which the corresponding density function dname, the corresponding distribution function pname and the corresponding quantile function qname must be defined, or directly the density function.
I checked and when entering ?norm or ?norm into the R command line, neither function norm() nor lnorm() is found. This confuses me totally.
When I try for example fitdist(data, 'poisson'), I get the following error message:
Error in fitdist(data$time, "poisson") :
The dpoisson function must be defined
I am somewhat a noob in R, can anybody give a hint?
norm() in R is a different function to compute norms of a matrix, so not directly related to the normal distribution.
?Normal brings up the documentation related to the normal distribution, and you'll see the 4 functions dnorm, pnorm, qnorm and rnorm belonging to this family.
If you look at ?Lognormal you'll see the same convention with the typical 4 functions.
More generally, you can look-up ?Distributions, which links all of them. There you can see that the keyword for the poisson distribution should actually be pois.

Error: 'X' must be a numeric or complex matrix [in a binary spatial autoregressive model]

I am estimating a binary spatial autoregressive model via a Gibbs sampler in R. When I do this using a neighborhood matrix, everything goes perfectly fine, but when I switch to a distance matrix, the program stops almost immediately, and outputs the infamous:
"Error in ginv(A) : 'X' must be a numeric or complex matrix"
What strikes me as odd is that when I try to compute the generalized inverse myself, everything goes smoothly, and all the matrixes seem to be numeric. Below you will find the data and code for the replicable example.
Data Link
Code (the error occurs after executing the final line, which is also a toy model to be estimated through the bsar function):
Code Link
Any ideas?

How do I find the cut point value used by the lda( ) function in MASS package for R?

I am working with the MASS package in R, specifically the lda() function. I would like to know how to get R to return the threshold value of LD1 (i.e. the cut point or cutoff) that the lda function uses to determine which group or class each sample should be assigned to.
I know that R does not just use the midpoint average between the two group means for LD1. I need to know the cut point value so that I can run multiple iterations of lda and reallocate the misclassified samples prior to each new iteration.
It is going to depend on the data unless you force it otherwise. ?lda produces:
prior
the prior probabilities of class membership. If unspecified, the class proportions for
the training set are used. If present, the probabilities should be specified in the
order of the factor levels.
If you want to see the code or generate a prediction look either at predict.lda or read further in ?predict.lda and in the MASS book. predict.lda also offers a handle on specifying the cutpoint:
prior
The prior probabilities of the classes, by default the proportions in the training set
or what was set in the call to lda.

Resources