I am trying to find whether a given vector is a linear combination of other vectors using R. Does anyone know how to find using R whether a given vector is a linear combination of other vectors?
Related
Is there any packages or commands allow multiple weighted matrices in a spatial lagged X (SLX) model?
I want to include two different weighted matrices with one dependent variable, but I cannot find any packages for it?
Theoretically, in spatial analysis, including multiple W matrices are not appropriate? If it is possible, how can I conduct analysis with W1 and W2? Do I have to do it by hand?(I meant, once create the lagged variable by multiplying W matrix and the key DV, and and run a OLS regression with the variables. Is it the right way applying multiple weighted matrices?
Thanks!
Dongjin
My question is on how to correctly interpret (and use) the 'weights' input variable in the nls function of R for non-linear weighted least squares regression.
The solution for solving the unknown parameters in weighted least squares theory is:
From this the variable P is the weight square matrix of size (NxN) where N is the number of data observations.
However, when I look at the nls documentation in R found here, it says the 'weights' to be input is a vector.
This has me puzzled since based on my understanding, the weights should be a square matrix. Some insights with those who have a better understanding is appreciated.
Weight variable in regression, is a measure of how important an observation is to your model due to different reasons (eg. may be in terms of reliability of measurement or inverse of variance estimate). Therefore, some observations may be more important/ weigh higher than others.
Weight vector , in matrix notation converts to a diagonal matrix for i in {1,2,3...n,} both represents the same thing (i.e. weight of ith observation). For nls package in R you need to supply weights in vector form.
Also, it should be noted that, weighted least squares is a special variant of generalized least squares in which we use weights to counter the heteroskedasticity. If the residuals are correlated for observations, perhaps a general model might be suitable.
PS: Cross validated would be the right place to get better detailed answer. Also, It seems to be memory efficient to store a vector rather than a matrix as the number of observations grows
This question already has an answer here:
R: lm() result differs when using `weights` argument and when using manually reweighted data
(1 answer)
Closed 6 years ago.
I would like to do a linear regression with a weighting factor for an analytical chemistry calibration curve. The x values are concentration and assumed to have no error. The y values are instrument response and the variation is assumed proportional to concentration. So, I would like to use a 1/x weighting factor for the linear regression. The data set is simply ten concentrations with a single measurement for each. Is there an easy way to do this in R? .
The answer can be found on a somewhat older question on Cross Validated. The lm() function (which represents the usual method of applying a linear regression), has an option to specify weights. As shown in the answer on the link, you can use a formula in the weights argument. In your case, the formula will likely take the form of 1/data$concentration.
As suggested by hrbrmstr, I'm adding mpiktas's actual answer from Cross Validated:
I think R help page of lm answers your question pretty well. The only
requirement for weights is that the vector supplied must be the same
length as the data. You can even supply only the name of the variable
in the data set, R will take care of the rest, NA management, etc. You
can also use formulas in the weight argument. Here is the example:
x <-c(rnorm(10),NA) df <-
data.frame(y=1+2*x+rnorm(11)/2,x=x,wght1=1:11)
##Fancy weights as numeric vector
summary(lm(y~x,data=df,weights=(df$wght1)^(3/4)))
#Fancy weights as formula on column of the data set
summary(lm(y~x,data=df,weights=I(wght1^(3/4))))
#Mundane weights as the column of the data set
summary(lm(y~x,data=df,weights=wght1)
Note that weights must be positive, otherwise R will produce an error.
I'm, trying to apply this solution to find the p-value in an arbitrary distribution defined from data experiments. I have estimated this distribution using the density function in R. Now, I would like to integrate this function to apply the solution proposed by #mpiktas. However, the integrate function requires a function as input, not two vectors x and y with the values that define the function, which is what density provides.
Any idea on how to deal with this numerical integration based on x-y values in R?
I want to do some testing of a program but I would like to have a really big matrix
Is there any tool that can generate an artificial correlation matrix?
Pick n random n-dimensional vectors of numbers from -1 to 1. Use the dot product of any 2 vectors is their correlation. Use that fact to make a random n x n correlation matrix.
Is this really a correlation matrix? Make each dimension into an independent standard normal distribution. The coefficients of each vector then describes a random variable. Those random variables have the specified correlations. So yes, this is actually going to be a correlation matrix.
There is a repository of sample matrix data for use in comparing algos available at the Matrix Market - free despite the name.