In R, how can I set weights for specific variables , rather than observations in the lm() function?
The context is as follows. I am trying to create a personal ranking system for certain products, for example, for phones. I can build a linear model based on price as a dependent variable, and other functions such as screen size, memory, OS, etc. Like independent variables. Then I can use it to predict the real value of the phone (as opposed to the declared price), thereby finding the best price / quality factor. This is what I have already done.
Now I want to highlight some functions that are important only to me. For example, I might need a phone with a large memory, so I want to give it a higher weight so that the linear model is optimized for variable memory.
Function
lm() in R has a weights parameter, but these are scales for observations, not variables (correct me if this is incorrect). I also tried to play with the formula, but received only interpreter errors. Is there a way to enable scales for variables in lm() ?
Of course, the lm() function is not the only option. If you know how to do this with other similar solutions (e.g. glm() ), this is also very good.
UPD. After a few comments, I realized that the way I thought about the problem is wrong. The linear model obtained by calling lm() gives optimal coefficients for training examples, and there is no way (and no need) to change the weight of the variables, sorry for the confusion I made. What I'm actually looking for is a way to change the coefficients in an existing linear model to manually make some parameters more important than others. Continuing the previous example, let's say we have the following formula for the price:
price = 300 + 30 * memory + 56 * screen_size + 12 * os_android + 9 * os_win8
This formula describes the best possible linear model of the dependence of price and phone parameters. However, now I want to manually change the number 30 before the memory variable, for example 60, so it will look like this:
price = 300 + 60 * memory + 56 * screen_size + 12 * os_android + 9 * os_win8
Of course, this formula no longer reflects the optimal relationship between price and phone settings. Also, the dependent variable does not show the actual price, but only some value of good, given that memory is two times more important for me than for the average person (based on coefficients from the first formula). But this value of good (or, more precisely, the value of the goodness/price fraction) is exactly what I need - with this I can find the best (in my opinion) phone with the best price.
Hope this all makes sense. Now I have one (possibly very simple) question. How can I manually set the coefficients in an existing linear model obtained using lm() ? That is, I'm looking for something like:
coef(model)[2] <- 60
This code does not work, but you should get this idea. Note. Obviously, it is only possible to double the values ββin the memory column in the data frame, but I'm looking for a more elegant solution that affects the model, not the data.