Specify an object to model a random effect in mixed model - r

I would like to run a mixed model in R specifycing the object for the structure of a random effect.
My model is this:
model1=lme(methane~fixedfactor1,
random=(~1|factory),
data=df,method="REML")
I have then an object named "factory_relationship" that I would like to use to model the structure of the random effect "factory".
If it can help, I did it in SAS by using the following:
proc mixed data=methane_data NOINFO;
class fixedfactor1;
model methane= fixedfactor1;
random factory/type=lin(1) LDATA=factory_relationship;
run;
However, I could not find any solutions in R.
Could you please help me?
Best
I tried to read the PDF guidelines for both "nlme" and "lme4" R packages, but I could not find any hint.

Related

R save xgb model command error: 'model must be xgb.Booster'

'bst' is the name of an xgboost model that I built in R. It gives me predicted values for the test dataset using this code. So it is definitely an xgboost model.
pred.xgb <- predict(bst , xdtest) # get prediction in test sample
cor(ytestdata, pred.xgb)
Now, I would like to save the model so another can use the model with their data set which has the same predictor variables and the same variable to be predicted.
Consistent with page 4 of xgboost.pdf, the documentation for the xgboost package, I use the xgb.save command:
xgb.save(bst, 'xgb.model')
which produces the error:
Error in xgb.save(bst, "xgb.model") : model must be xgb.Booster.
Any insight would be appreciated. I searched the stack overflow and could not locate relevant advice.
Mike
It's hard to know exactly what's going on without a fully reproducible example. But just because your model can make predictions on the test data, it doesn't mean it's an xgboost model. It can be any type of model with a predict method.
You can try class(bst) to see the class of your bst object. It should return "xgb.Booster," though I suspect it won't here (hence your error).
On another note, if you want to pass your model to another person using R, you can just save the R object rather than exporting to binary, via:
save(bst, model.RData)

Equation for Neural Network from R output

Hi I am a newbie in Depp learning fields.
I ran a neural network model (regression) with 2 hidden layers in R (neuralnet Package). then I used the the compute function to get the predicted probabilities.Now I want to regenerate predicted output using the equation used in the neural net. for example, following are weights received from the model object
Intercept.to.1layhid1 4.55725020215
Var1.to.1layhid1 -13.61221477737
VAr2.to.1layhid1 0.30686384857
var1.to.1layhid2 0.23527690062
var2.to.1layhid2 0..67345678
1layhid.1.to.target 1.95414397785
1layhid.2.to.target 3.68009136857
Can any one help me derive a equation with the above weights so that I can replicate the output
Thanks
In order to get the output for new data, you can always use predict function using the fitted model, which is the returned object from neuralnet function.
For instance, if your model is the following:
neuralFit = neuralnet(trainData)
Then you reproduce the output with the following:
predict(neuralFit,newdata)
Otherwise, you'll need to compute the result manually. But you need to understand your network architecture first.

Different between functions and regression models in R?

I'm really confused about regression models and functions in R. Here is my problem. I'm using the PLS package to make a model like Y~x. To do that I have to use 'plsr':
model=plsr(Y~X,ncomp=10,data=df1,center=TRUE, scale=TRUE, validation="LOO")
I couldn't find the source of the 'plsr' in the PLS source code but in the help document it says it refers to 'mvr{pls}' which I could find it. first is 'plsr' a function or model.. in the R terminology? is it built in R? and how does it refer to 'mvr' function in pls package?
Thanks

How can I specify 'unstructured' in lme function?

I'm trying to fit a mixed model in R.
Actually I have a Stata code and want to do the same thing using R.
The Stata code is
xtmixed laz c.x1##i.j4alloc_n c.x2##i.j4alloc_n ||childuid:age_m, cov(uns) var
I can't find how to specify 'unstructured' correlation structure in R.
In the R help file, there is no 'unstructured'
https://stat.ethz.ch/R-manual/R-devel/library/nlme/html/corClasses.html

R randomForest to PMML class index is wrong

I'm exporting an R randomForest model to PMML. The resulting PMML always has the class as the first element of the DataDictionary element, which is not always true.
Is there some way to fix this or at least increment the PMML with custom Extension elements? That way I could put the class index there.
I've looked in the pmml package documentation, as well as in the pmmlTransformations packages, but couldn't find anything there that could help me solve this issue.
By PMML class I assume you mean the model type (classification vs regression) in the PMML model attributes?
If so, it is not true that the model type is determined from the data type of the first element of the DataDictionary....these are completely independent. The model type is determined from the model type R thinks it is. The R random forest object determines the type it thinks it is (model$type) and that is the model type exported by the pmml function. If you want your model to be a certain type, just make sure you let R know that...for example, if you are using the iris data set, if your predicted variable is Sepal.Length, R will correctly assume it is a regression model. If you insist on treating it as a classification model, try using as.factor(Sepal.Length) instead.

Resources